javax.swing
Class SpinnerDateModel

java.lang.Object
  extended by javax.swing.AbstractSpinnerModel
      extended by javax.swing.SpinnerDateModel
All Implemented Interfaces:
Serializable, SpinnerModel

public class SpinnerDateModel
extends AbstractSpinnerModel
implements Serializable

A date model used by the JSpinner component. This implements a spinner model for dates, rotating a calendar field such as month, year, day, week, hour, minute.

Since:
1.4
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractSpinnerModel
listenerList
 
Constructor Summary
SpinnerDateModel()
          Constructs a SpinnerDateModel using the current date, no start or end limit, and Calendar.DAY_OF_MONTH as the calendar field.
SpinnerDateModel(Date value, Comparable start, Comparable end, int calendarField)
          Constructs a SpinnerDateModel with the specified value, lower and upper bounds, and which spins the specified calendar field.
 
Method Summary
 int getCalendarField()
          Returns the Calendar field used to calculate the previous and next dates in the sequence.
 Date getDate()
          Returns the current date/time.
 Comparable getEnd()
          Returns the upper limit on the date/time value, or null if there is no maximum date/time.
 Object getNextValue()
          Returns the next date in the sequence, or null if the next date is past the upper limit (if one is specified).
 Object getPreviousValue()
          Returns the previous date in the sequence, or null if the previous date is prior to the lower limit (if one is specified).
 Comparable getStart()
          Returns the lower limit on the date/time value, or null if there is no minimum date/time.
 Object getValue()
          Returns the current date in the sequence (this method returns the same as getDate()).
 void setCalendarField(int calendarField)
          Sets the date field to change when calculating the next and previous values.
 void setEnd(Comparable end)
          Sets the upper limit for the date/time value and, if the new limit is different to the old limit, sends a ChangeEvent to all registered listeners.
 void setStart(Comparable start)
          Sets the lower limit for the date/time value and, if the new limit is different to the old limit, sends a ChangeEvent to all registered listeners.
 void setValue(Object value)
          Sets the current date and, if the new value is different to the old value, sends a ChangeEvent to all registered listeners.
 
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
 

Constructor Detail

SpinnerDateModel

public SpinnerDateModel()
Constructs a SpinnerDateModel using the current date, no start or end limit, and Calendar.DAY_OF_MONTH as the calendar field.


SpinnerDateModel

public SpinnerDateModel(Date value,
                        Comparable start,
                        Comparable end,
                        int calendarField)
Constructs a SpinnerDateModel with the specified value, lower and upper bounds, and which spins the specified calendar field.

The start and end limits must have a compareTo method that supports instances of Date, but do not themselves need to be instances of Date (although typically they are).

Parameters:
value - the initial value/date (null not permitted).
start - a constraint that specifies the earliest permitted date value, or null for no lower limit.
end - a constraint that specifies the latest permitted date value, or null for no upper limit.
calendarField - the Calendar field to spin, (Calendar.ZONE_OFFSET and Calendar.DST_OFFSET are invalid)
Method Detail

getCalendarField

public int getCalendarField()
Returns the Calendar field used to calculate the previous and next dates in the sequence.

Returns:
The date field code.

getDate

public Date getDate()
Returns the current date/time.

Returns:
The current date/time (never null).
See Also:
getValue()

getStart

public Comparable getStart()
Returns the lower limit on the date/time value, or null if there is no minimum date/time.

Returns:
The lower limit.
See Also:
setStart(Comparable)

getEnd

public Comparable getEnd()
Returns the upper limit on the date/time value, or null if there is no maximum date/time.

Returns:
The upper limit.
See Also:
setEnd(Comparable)

getValue

public Object getValue()
Returns the current date in the sequence (this method returns the same as getDate()).

Specified by:
getValue in interface SpinnerModel
Returns:
The current date (never null).

getNextValue

public Object getNextValue()
Returns the next date in the sequence, or null if the next date is past the upper limit (if one is specified). The current date is not changed.

Specified by:
getNextValue in interface SpinnerModel
Returns:
The next date, or null if the current value is the latest date represented by the model.
See Also:
getEnd()

getPreviousValue

public Object getPreviousValue()
Returns the previous date in the sequence, or null if the previous date is prior to the lower limit (if one is specified). The current date is not changed.

Specified by:
getPreviousValue in interface SpinnerModel
Returns:
The previous date, or null if the current value is the earliest date represented by the model.
See Also:
getStart()

setCalendarField

public void setCalendarField(int calendarField)
Sets the date field to change when calculating the next and previous values. It must be a valid Calendar field, excluding Calendar.ZONE_OFFSET and Calendar.DST_OFFSET.

Parameters:
calendarField - the calendar field to set.
Throws:
IllegalArgumentException - if calendarField is not a valid code.

setStart

public void setStart(Comparable start)
Sets the lower limit for the date/time value and, if the new limit is different to the old limit, sends a ChangeEvent to all registered listeners. A null value is interpreted as "no lower limit". No check is made to ensure that the current date/time is on or after the new lower limit - the caller is responsible for ensuring that this relationship holds. In addition, the caller should ensure that start is Serializable.

Parameters:
start - the new lower limit for the date/time value (null permitted).

setEnd

public void setEnd(Comparable end)
Sets the upper limit for the date/time value and, if the new limit is different to the old limit, sends a ChangeEvent to all registered listeners. A null value is interpreted as "no upper limit". No check is made to ensure that the current date/time is on or before the new upper limit - the caller is responsible for ensuring that this relationship holds. In addition, the caller should ensure that end is Serializable.

Parameters:
end - the new upper limit for the date/time value (null permitted).

setValue

public void setValue(Object value)
Sets the current date and, if the new value is different to the old value, sends a ChangeEvent to all registered listeners.

Specified by:
setValue in interface SpinnerModel
Parameters:
value - the new date (null not permitted, must be an instance of Date).
Throws:
IllegalArgumentException - if value is not an instance of Date.