|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.AbstractSpinnerModel | +--javax.swing.SpinnerDateModel
Safe: A SpinnerModel
for sequences of Date
s.
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(int, int)
,
Serialized FormField Summary | |
private int |
calendarField
|
private Comparable |
end
|
private Comparable |
start
|
private Calendar |
value
|
Fields inherited from class javax.swing.AbstractSpinnerModel |
listenerList |
Constructor Summary | |
SpinnerDateModel()
Enabled: Constructs a SpinnerDateModel whose initial
value is the current date, calendarField
is equal to Calendar.DAY_OF_MONTH , and for which
there are no start /end limits. |
|
SpinnerDateModel(Date value,
Comparable start,
Comparable end,
int calendarField)
Enabled: Creates a SpinnerDateModel that represents a sequence of dates
between start and end . |
Method Summary | |
private boolean |
calendarFieldOK(int calendarField)
|
int |
getCalendarField()
Enabled: Returns the Calendar field that is added to or subtracted from
by the nextValue and previousValue methods. |
Date |
getDate()
Enabled: Returns the current element in this sequence of Date s. |
Comparable |
getEnd()
Enabled: Returns the last Date in the sequence. |
Object |
getNextValue()
Enabled: Returns the next Date in the sequence, or null if
the next date is after end . |
Object |
getPreviousValue()
Enabled: Returns the previous Date in the sequence, or null
if the previous date is before start . |
Comparable |
getStart()
Enabled: Returns the first Date in the sequence. |
Object |
getValue()
Enabled: Returns the current element in this sequence of Date s. |
void |
setCalendarField(int calendarField)
Enabled: Changes the size of the date value change computed by the nextValue and previousValue methods. |
void |
setEnd(Comparable end)
Enabled: Changes the upper limit for Date s in this sequence. |
void |
setStart(Comparable start)
Enabled: Changes the lower limit for Dates in this sequence. |
void |
setValue(Object value)
Enabled: Sets the current Date for this sequence. |
Methods inherited from class javax.swing.AbstractSpinnerModel |
addChangeListener, fireStateChanged, getChangeListeners, getListeners, removeChangeListener |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private Comparable start
private Comparable end
private Calendar value
private int calendarField
Constructor Detail |
public SpinnerDateModel(Date value, Comparable start, Comparable end, int calendarField)
SpinnerDateModel
that represents a sequence of dates
between start
and end
. The
nextValue
and previousValue
methods
compute elements of the sequence by advancing or reversing
the current date value
by the
calendarField
time unit. For a precise description
of what it means to increment or decrement a Calendar
field
, see the add
method in
java.util.Calendar
.
The start
and end
parameters can be
null
to indicate that the range doesn't have an
upper or lower bound. If value
or
calendarField
is null
, or if both
start
and end
are specified and
mininum > maximum
then an
IllegalArgumentException
is thrown.
Similarly if (minimum <= value <= maximum)
is false,
an IllegalArgumentException is thrown.
value
- the current (non null
) value of the modelstart
- 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
IllegalArgumentException
- if value
or
calendarField
are null
,
if calendarField
isn't valid,
or if the following expression is
false: (start <= value <= end)
.Calendar.add(int, int)
,
setValue(java.lang.Object)
,
setStart(java.lang.Comparable)
,
setEnd(java.lang.Comparable)
,
setCalendarField(int)
public SpinnerDateModel()
SpinnerDateModel
whose initial
value
is the current date, calendarField
is equal to Calendar.DAY_OF_MONTH
, and for which
there are no start
/end
limits.
Method Detail |
private boolean calendarFieldOK(int calendarField)
public void setStart(Comparable start)
start
is null
,
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 the nextValue
, previousValue
,
or setValue
methods.
Typically this property is a Date
however it's possible to use
a Comparable
with a compareTo
method for Dates.
For example start
might 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 a
ClassCastException
if the Object
passed to compareTo(Object)
is not a Date
.
This method fires a ChangeEvent
if the
start
has changed.
start
- defines the first date in the sequencegetStart()
,
setEnd(java.lang.Comparable)
,
AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
public Comparable getStart()
Date
in the sequence.
start
propertysetStart(java.lang.Comparable)
public void setEnd(Comparable end)
Date
s in this sequence.
If start
is null
, 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 the nextValue
, previousValue
,
or setValue
methods.
Typically this property is a Date
however it's possible to use
Comparable
with a compareTo
method for
Date
s. See setStart
for an example.
This method fires a ChangeEvent
if the end
has changed.
getEnd()
,
setStart(java.lang.Comparable)
,
AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
public Comparable getEnd()
Date
in the sequence.
end
propertysetEnd(java.lang.Comparable)
public void setCalendarField(int calendarField)
nextValue
and previousValue
methods.
The calendarField
parameter must be one of the
Calendar
field constants like Calendar.MONTH
or Calendar.MINUTE
.
The nextValue
and previousValue
methods
simply move the specified Calendar
field forward or backward
by one unit with the Calendar.add
method.
getCalendarField()
,
getNextValue()
,
getPreviousValue()
,
Calendar.add(int, int)
,
AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
public int getCalendarField()
Calendar
field that is added to or subtracted from
by the nextValue
and previousValue
methods.
calendarField
propertysetCalendarField(int)
public Object getNextValue()
Date
in the sequence, or null
if
the next date is after end
.
getNextValue
in interface SpinnerModel
Date
in the sequence, or null
if
the next date is after end
.SpinnerModel.getNextValue()
,
getPreviousValue()
,
setCalendarField(int)
public Object getPreviousValue()
Date
in the sequence, or null
if the previous date is before start
.
getPreviousValue
in interface SpinnerModel
Date
in the sequence, or
null
if the previous date
is before start
SpinnerModel.getPreviousValue()
,
getNextValue()
,
setCalendarField(int)
public Date getDate()
Date
s.
This method is equivalent to (Date)getValue
.
value
propertysetValue(java.lang.Object)
public Object getValue()
Date
s.
getValue
in interface SpinnerModel
value
propertysetValue(java.lang.Object)
,
getDate()
public void setValue(Object value)
Date
for this sequence.
If value
is null
,
an IllegalArgumentException
is 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 the nextValue
, previousValue
,
or setValue
methods.
This method fires a ChangeEvent
if the
value
has changed.
setValue
in interface SpinnerModel
value
- the current (non null
)
Date
for this sequence
IllegalArgumentException
- if value is null
or not a Date
getDate()
,
getValue()
,
AbstractSpinnerModel.addChangeListener(javax.swing.event.ChangeListener)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |