- java.lang.Object
- 
- javax.swing.AbstractSpinnerModel
- 
- javax.swing.SpinnerDateModel
 
 
- 
- All Implemented Interfaces:
- Serializable,- SpinnerModel
 
 public class SpinnerDateModel extends AbstractSpinnerModel implements Serializable ASpinnerModelfor sequences ofDates. The upper and lower bounds of the sequence are defined by properties calledstartandendand the size of the increase or decrease computed by thenextValueandpreviousValuemethods is defined by a property calledcalendarField. Thestartandendproperties can benullto indicate that the sequence has no lower or upper limit.The value of the calendarFieldproperty must be one of thejava.util.Calendarconstants that specify a field within aCalendar. ThegetNextValueandgetPreviousValuemethods change the date forward or backwards by this amount. For example, ifcalendarFieldisCalendar.DAY_OF_WEEK, thennextValueproduces aDatethat's 24 hours after the currentvalue, andpreviousValueproduces aDatethat's 24 hours earlier.The legal values for calendarFieldare:- Calendar.ERA
- Calendar.YEAR
- Calendar.MONTH
- Calendar.WEEK_OF_YEAR
- Calendar.WEEK_OF_MONTH
- Calendar.DAY_OF_MONTH
- Calendar.DAY_OF_YEAR
- Calendar.DAY_OF_WEEK
- Calendar.DAY_OF_WEEK_IN_MONTH
- Calendar.AM_PM
- Calendar.HOUR
- Calendar.HOUR_OF_DAY
- Calendar.MINUTE
- Calendar.SECOND
- Calendar.MILLISECOND
 This model inherits a ChangeListener. TheChangeListenersare notified whenever the modelsvalue,calendarField,start, orendproperties changes.- Since:
- 1.4
- See Also:
- JSpinner,- SpinnerModel,- AbstractSpinnerModel,- SpinnerListModel,- SpinnerNumberModel,- Calendar.add(int, int), Serialized Form
 
- 
- 
Field Summary- 
Fields declared in class javax.swing.AbstractSpinnerModellistenerList
 
- 
 - 
Constructor SummaryConstructors Constructor Description SpinnerDateModel()Constructs aSpinnerDateModelwhose initialvalueis the current date,calendarFieldis equal toCalendar.DAY_OF_MONTH, and for which there are nostart/endlimits.SpinnerDateModel(Date value, Comparable<Date> start, Comparable<Date> end, int calendarField)Creates aSpinnerDateModelthat represents a sequence of dates betweenstartandend.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCalendarField()Returns theCalendarfield that is added to or subtracted from by thenextValueandpreviousValuemethods.DategetDate()Returns the current element in this sequence ofDates.Comparable<Date>getEnd()Returns the lastDatein the sequence.ObjectgetNextValue()Returns the nextDatein the sequence, ornullif the next date is afterend.ObjectgetPreviousValue()Returns the previousDatein the sequence, ornullif the previous date is beforestart.Comparable<Date>getStart()Returns the firstDatein the sequence.ObjectgetValue()Returns the current element in this sequence ofDates.voidsetCalendarField(int calendarField)Changes the size of the date value change computed by thenextValueandpreviousValuemethods.voidsetEnd(Comparable<Date> end)Changes the upper limit forDates in this sequence.voidsetStart(Comparable<Date> start)Changes the lower limit for Dates in this sequence.voidsetValue(Object value)Sets the currentDatefor this sequence.- 
Methods declared in class javax.swing.AbstractSpinnerModeladdChangeListener, fireStateChanged, getChangeListeners, getListeners, removeChangeListener
 
- 
 
- 
- 
- 
Constructor Detail- 
SpinnerDateModelpublic SpinnerDateModel(Date value, Comparable<Date> start, Comparable<Date> end, int calendarField) Creates aSpinnerDateModelthat represents a sequence of dates betweenstartandend. ThenextValueandpreviousValuemethods compute elements of the sequence by advancing or reversing the current datevalueby thecalendarFieldtime unit. For a precise description of what it means to increment or decrement aCalendarfield, see theaddmethod injava.util.Calendar.The startandendparameters can benullto indicate that the range doesn't have an upper or lower bound. IfvalueorcalendarFieldisnull, or if bothstartandendare specified andminimum > maximumthen anIllegalArgumentExceptionis thrown. Similarly if(minimum <= value <= maximum)is false, an IllegalArgumentException is thrown.- Parameters:
- value- the current (non- null) value of the model
- start- the first date in the sequence or- null
- end- the last date in the sequence or- null
- calendarField- one of- Calendar.ERA
- Calendar.YEAR
- Calendar.MONTH
- Calendar.WEEK_OF_YEAR
- Calendar.WEEK_OF_MONTH
- Calendar.DAY_OF_MONTH
- Calendar.DAY_OF_YEAR
- Calendar.DAY_OF_WEEK
- Calendar.DAY_OF_WEEK_IN_MONTH
- Calendar.AM_PM
- Calendar.HOUR
- Calendar.HOUR_OF_DAY
- Calendar.MINUTE
- Calendar.SECOND
- Calendar.MILLISECOND
 
- Throws:
- IllegalArgumentException- if- valueor- calendarFieldare- null, if- calendarFieldisn't valid, or if the following expression is false:- (start <= value <= end).
- See Also:
- Calendar.add(int, int),- setValue(java.lang.Object),- setStart(java.lang.Comparable<java.util.Date>),- setEnd(java.lang.Comparable<java.util.Date>),- setCalendarField(int)
 
 - 
SpinnerDateModelpublic SpinnerDateModel() Constructs aSpinnerDateModelwhose initialvalueis the current date,calendarFieldis equal toCalendar.DAY_OF_MONTH, and for which there are nostart/endlimits.
 
- 
 - 
Method Detail- 
setStartpublic void setStart(Comparable<Date> start) Changes the lower limit for Dates in this sequence. Ifstartisnull, then there is no lower limit. No bounds checking is done here: the new start value may invalidate the(start <= value <= end)invariant enforced by the constructors. This is to simplify updating the model. Naturally one should ensure that the invariant is true before calling thenextValue,previousValue, orsetValuemethods.Typically this property is a Datehowever it's possible to use aComparablewith acompareTomethod for Dates. For examplestartmight be an instance of a class like this:MyStartDate implements Comparable { long t = 12345; public int compareTo(Date d) { return (t < d.getTime() ? -1 : (t == d.getTime() ? 0 : 1)); } public int compareTo(Object o) { return compareTo((Date)o); } }Note that the above example will throw aClassCastExceptionif theObjectpassed tocompareTo(Object)is not aDate.This method fires a ChangeEventif thestarthas changed.- Parameters:
- start- defines the first date in the sequence
- See Also:
- getStart(),- setEnd(java.lang.Comparable<java.util.Date>),- AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
 
 - 
getStartpublic Comparable<Date> getStart() Returns the firstDatein the sequence.- Returns:
- the value of the startproperty
- See Also:
- setStart(java.lang.Comparable<java.util.Date>)
 
 - 
setEndpublic void setEnd(Comparable<Date> end) Changes the upper limit forDates in this sequence. Ifstartisnull, then there is no upper limit. No bounds checking is done here: the new start value may invalidate the(start <= value <= end)invariant enforced by the constructors. This is to simplify updating the model. Naturally, one should ensure that the invariant is true before calling thenextValue,previousValue, orsetValuemethods.Typically this property is a Datehowever it's possible to useComparablewith acompareTomethod forDates. SeesetStartfor an example.This method fires a ChangeEventif theendhas changed.- Parameters:
- end- defines the last date in the sequence
- See Also:
- getEnd(),- setStart(java.lang.Comparable<java.util.Date>),- AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
 
 - 
getEndpublic Comparable<Date> getEnd() Returns the lastDatein the sequence.- Returns:
- the value of the endproperty
- See Also:
- setEnd(java.lang.Comparable<java.util.Date>)
 
 - 
setCalendarFieldpublic void setCalendarField(int calendarField) Changes the size of the date value change computed by thenextValueandpreviousValuemethods. ThecalendarFieldparameter must be one of theCalendarfield constants likeCalendar.MONTHorCalendar.MINUTE. ThenextValueandpreviousValuemethods simply move the specifiedCalendarfield forward or backward by one unit with theCalendar.addmethod. You should use this method with care as some UIs may set the calendarField before committing the edit to spin the field under the cursor. If you only want one field to spin you can subclass and ignore the setCalendarField calls.- Parameters:
- calendarField- one of- Calendar.ERA
- Calendar.YEAR
- Calendar.MONTH
- Calendar.WEEK_OF_YEAR
- Calendar.WEEK_OF_MONTH
- Calendar.DAY_OF_MONTH
- Calendar.DAY_OF_YEAR
- Calendar.DAY_OF_WEEK
- Calendar.DAY_OF_WEEK_IN_MONTH
- Calendar.AM_PM
- Calendar.HOUR
- Calendar.HOUR_OF_DAY
- Calendar.MINUTE
- Calendar.SECOND
- Calendar.MILLISECOND
 - This method fires a - ChangeEventif the- calendarFieldhas changed.
- See Also:
- getCalendarField(),- getNextValue(),- getPreviousValue(),- Calendar.add(int, int),- AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
 
 - 
getCalendarFieldpublic int getCalendarField() Returns theCalendarfield that is added to or subtracted from by thenextValueandpreviousValuemethods.- Returns:
- the value of the calendarFieldproperty
- See Also:
- setCalendarField(int)
 
 - 
getNextValuepublic Object getNextValue() Returns the nextDatein the sequence, ornullif the next date is afterend.- Specified by:
- getNextValuein interface- SpinnerModel
- Returns:
- the next Datein the sequence, ornullif the next date is afterend.
- See Also:
- SpinnerModel.getNextValue(),- getPreviousValue(),- setCalendarField(int)
 
 - 
getPreviousValuepublic Object getPreviousValue() Returns the previousDatein the sequence, ornullif the previous date is beforestart.- Specified by:
- getPreviousValuein interface- SpinnerModel
- Returns:
- the previous Datein the sequence, ornullif the previous date is beforestart
- See Also:
- SpinnerModel.getPreviousValue(),- getNextValue(),- setCalendarField(int)
 
 - 
getDatepublic Date getDate() Returns the current element in this sequence ofDates. This method is equivalent to(Date)getValue.- Returns:
- the valueproperty
- See Also:
- setValue(java.lang.Object)
 
 - 
getValuepublic Object getValue() Returns the current element in this sequence ofDates.- Specified by:
- getValuein interface- SpinnerModel
- Returns:
- the valueproperty
- See Also:
- setValue(java.lang.Object),- getDate()
 
 - 
setValuepublic void setValue(Object value) Sets the currentDatefor this sequence. Ifvalueisnull, anIllegalArgumentExceptionis thrown. No bounds checking is done here: the new value may invalidate the(start <= value < end)invariant enforced by the constructors. Naturally, one should ensure that the(start <= value <= maximum)invariant is true before calling thenextValue,previousValue, orsetValuemethods.This method fires a ChangeEventif thevaluehas changed.- Specified by:
- setValuein interface- SpinnerModel
- Parameters:
- value- the current (non- null)- Datefor this sequence
- Throws:
- IllegalArgumentException- if value is- nullor not a- Date
- See Also:
- getDate(),- getValue(),- AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
 
 
- 
 
-