SpinnerModel for sequences of Dates.
The upper and lower bounds of the sequence are defined by properties called
start and end and the size
of the increase or decrease computed by the nextValue
and previousValue methods is defined by a property
called calendarField. The start
and end properties can be null to
indicate that the sequence has no lower or upper limit.
The value of the calendarField property must be one of the
java.util.Calendar constants that specify a field
within a Calendar. The getNextValue
and getPreviousValue
methods change the date forward or backwards by this amount.
For example, if calendarField is Calendar.DAY_OF_WEEK,
then nextValue produces a Date that's 24
hours after the current value, and previousValue
produces a Date that's 24 hours earlier.
The legal values for calendarField are:
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. The
ChangeListeners are notified whenever the models
value, calendarField,
start, or end properties changes.
JSpinner, SpinnerModel, AbstractSpinnerModel, SpinnerListModel, SpinnerNumberModel, Calendar#add
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private Comparable | |
| private Comparable | |
| private Calendar |
| Access | Constructor and Description |
|---|---|
| public | SpinnerDateModel(Date
the current (non value, Comparable<Date> null) value of the modelthe first date in the sequence or start, Comparable<Date> nullthe last date in the sequence or end, int nullone of
calendarField)
Creates a |
| public | SpinnerDateModel()
Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| public int | Returns: the value of thecalendarField propertyReturns the |
| public Date | |
| public Comparable | |
| public Object | Returns: the nextDate in the sequence, or null if
the next date is after end.Implements javax. Returns the next |
| public Object | Returns: the previousDate in the sequence, or
null if the previous date
is before startImplements javax. Returns the previous |
| public Comparable | |
| public Object | Returns: thevalue propertyImplements javax. Returns the current element in this sequence of |
| public void | setCalendarField(int
one of
calendarField)
This method fires a Changes the size of the date value change computed
by the |
| public void | setEnd(Comparable<Date>
defines the last date in the sequence end)Changes the upper limit for |
| public void | setStart(Comparable<Date>
defines the first date in the sequence start)Changes the lower limit for Dates in this sequence. |
| public void | setValue(Object
the current (non value)null)
Date for this sequenceImplements javax. Sets the current |
| calendarField | back to summary |
|---|---|
| private int calendarField | |
| end | back to summary |
|---|---|
| private Comparable<Date> end | |
| start | back to summary |
|---|---|
| private Comparable<Date> start | |
| value | back to summary |
|---|---|
| private Calendar value | |
| SpinnerDateModel | back to summary |
|---|---|
| public SpinnerDateModel(Date value, Comparable<Date> start, Comparable<Date> end, int calendarField) Creates a
The
| |
| SpinnerDateModel | back to summary |
|---|---|
| public SpinnerDateModel() Constructs a | |
| calendarFieldOK | back to summary |
|---|---|
| private boolean calendarFieldOK(int calendarField) | |
| getCalendarField | back to summary |
|---|---|
| public int getCalendarField() Returns the
| |
| getDate | back to summary |
|---|---|
| public Date getDate() Returns the current element in this sequence of | |
| getEnd | back to summary |
|---|---|
| public Comparable Returns the last
| |
| getNextValue | back to summary |
|---|---|
| public Object getNextValue() Implements javax. Returns the next
| |
| getPreviousValue | back to summary |
|---|---|
| public Object getPreviousValue() Implements javax. Returns the previous
| |
| getStart | back to summary |
|---|---|
| public Comparable Returns the first
| |
| getValue | back to summary |
|---|---|
| public Object getValue() Implements javax. Returns the current element in this sequence of | |
| setCalendarField | back to summary |
|---|---|
| public void setCalendarField(int calendarField) Changes the size of the date value change computed
by the
| |
| setEnd | back to summary |
|---|---|
| public void setEnd(Comparable<Date> end) Changes the upper limit for
Typically this property is a
This method fires a
| |
| setStart | back to summary |
|---|---|
| public void setStart(Comparable<Date> start) Changes the lower limit for Dates in this sequence.
If
Typically this property is a
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 a ClassCastException
if the Object passed to compareTo(Object)
is not a Date.
This method fires a
| |
| setValue | back to summary |
|---|---|
| public void setValue(Object value) Implements javax. Sets the current
This method fires a
| |