Package org.jdesktop.swingx.calendar
Class AbstractDateSelectionModel
java.lang.Object
org.jdesktop.swingx.calendar.AbstractDateSelectionModel
- All Implemented Interfaces:
DateSelectionModel
- Direct Known Subclasses:
DaySelectionModel,DefaultDateSelectionModel,SingleDaySelectionModel
Abstract base implementation of DateSelectionModel.
Implements notification, Calendar related properties and lower/upper bounds.
- Author:
- Jeanette Winzenburg
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jdesktop.swingx.calendar.DateSelectionModel
DateSelectionModel.SelectionMode -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanTODO docprotected Calendarjava.util.Calendarempty datesprotected EventListenerMapthe Listeners collectionprotected Localethe locale used by the calendar.protected Datelower bound for the modelprotected Dateupper bound for the model -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a DateSelectionModel with default locale.AbstractDateSelectionModel(Locale locale) Instantiates a DateSelectionModel with the given locale. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the specified listener to this model.protected voidadjustDatesToTimeZone(TimeZone oldTimeZone) Adjusts all stored dates to a new time zone.protected DateReturns the end of the day of the given date in this model's calendar.protected voidfireValueChanged(DateSelectionEvent.EventType eventType) Notifies all listeners that have registered interest for notification on value change.Returns a clone of the calendar used by this model.get all registered listener to this model.intGets what the first day of the week is; e.g.,Calendar.SUNDAYin the U.S.,Calendar.MONDAYin France.Returns the Locale of this model's calendar.Return the lower bound date that is allowed to be selected for this model.intGets the minimal number of days in the first week of the year.Returns the TimeZone of this model.Return the upper bound date that is allowed to be selected for this model.booleanReturns the property to decide whether the selection is intermediate or final.protected booleanReturns a boolean indicating whether the given dates are on the same day in the coordinates of the model's calendar.voidRemove the specified listener to this model.voidsetAdjusting(boolean adjusting) Set the property to mark upcoming selections as intermediate/ final.voidsetFirstDayOfWeek(int firstDayOfWeek) Sets what the first day of the week is.voidSets the Locale of this model's calendar.voidsetLowerBound(Date lowerBound) Set the lower bound date that is allowed to be selected for this model.voidsetMinimalDaysInFirstWeek(int minimalDays) Sets the minimal number of days in the first week of the year.voidsetTimeZone(TimeZone timeZone) Sets the TimeZone of this model.voidsetUpperBound(Date upperBound) Set the upper bound date that is allowed to be selected for this model.protected DatestartOfDay(Date date) Returns the start of the day of the given date in this model's calendar.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jdesktop.swingx.calendar.DateSelectionModel
addSelectionInterval, clearSelection, getFirstSelectionDate, getLastSelectionDate, getNormalizedDate, getSelection, getSelectionMode, getUnselectableDates, isSelected, isSelectionEmpty, isUnselectableDate, removeSelectionInterval, setSelectionInterval, setSelectionMode, setUnselectableDates
-
Field Details
-
EMPTY_DATES
empty dates -
listenerMap
the Listeners collection -
adjusting
protected boolean adjustingTODO doc -
calendar
java.util.Calendar -
upperBound
upper bound for the model -
lowerBound
lower bound for the model -
locale
the locale used by the calendar.NOTE: need to keep separately as a Calendar has no getter.
-
-
Constructor Details
-
AbstractDateSelectionModel
public AbstractDateSelectionModel()Instantiates a DateSelectionModel with default locale. -
AbstractDateSelectionModel
Instantiates a DateSelectionModel with the given locale. If the locale is null, the Locale's default is used. PENDING JW: fall back to JComponent.getDefaultLocale instead? We use this with components anyway?- Parameters:
locale- the Locale to use with this model, defaults to Locale.default() if null.
-
-
Method Details
-
getCalendar
Returns a clone of the calendar used by this model. It's date is unspecified.- Specified by:
getCalendarin interfaceDateSelectionModel- Returns:
- a clone of the calendar used by this model.
-
getFirstDayOfWeek
public int getFirstDayOfWeek()Gets what the first day of the week is; e.g.,Calendar.SUNDAYin the U.S.,Calendar.MONDAYin France. This is needed when the model selection mode isWEEK_INTERVAL_SELECTION. PENDING JW: move week-interval selection from JXMonthView into the model.- Specified by:
getFirstDayOfWeekin interfaceDateSelectionModel- Returns:
- int The first day of the week.
- See Also:
-
setFirstDayOfWeek
public void setFirstDayOfWeek(int firstDayOfWeek) Sets what the first day of the week is. E.g.,Calendar.SUNDAYin US,Calendar.MONDAYin France. Fires a DateSelectionEvent of type CALENDAR_CHANGED, if the value is different from the old.The default value depends on the Calendar's default. PENDING JW: actually, it's a bound property. Use a propertyChangeListener?
- Specified by:
setFirstDayOfWeekin interfaceDateSelectionModel- Parameters:
firstDayOfWeek- The first day of the week.- See Also:
-
getMinimalDaysInFirstWeek
public int getMinimalDaysInFirstWeek()Gets the minimal number of days in the first week of the year.- Specified by:
getMinimalDaysInFirstWeekin interfaceDateSelectionModel- Returns:
- int the minimal number of days in the first week of the year.
-
setMinimalDaysInFirstWeek
public void setMinimalDaysInFirstWeek(int minimalDays) Sets the minimal number of days in the first week of the year. Fires a DateSelectionEvent of type CALENDAR_CHANGED, if the value is different from the old. The default value depends on the Calendar's default. PENDING JW: actually, it's a bound property. Use a propertyChangeListener?- Specified by:
setMinimalDaysInFirstWeekin interfaceDateSelectionModel- Parameters:
minimalDays- the minimal number of days in the first week of the year.- See Also:
-
getTimeZone
Returns the TimeZone of this model.- Specified by:
getTimeZonein interfaceDateSelectionModel- Returns:
- the TimeZone of this model.
- See Also:
-
setTimeZone
Sets the TimeZone of this model. Fires a DateSelectionEvent of type CALENDAR_CHANGED if the new value is different from the old. The default value depends on the Calendar's default. PENDING JW: actually, it's a bound property. Use a propertyChangeListener?- Specified by:
setTimeZonein interfaceDateSelectionModel- Parameters:
timeZone- the TimeZone to use in this model, must not be null.- See Also:
-
adjustDatesToTimeZone
Adjusts all stored dates to a new time zone. This method is called after the change had been made.This implementation resets all dates to null, clears everything. Subclasses may override to really map to the new time zone.
- Parameters:
oldTimeZone- the old time zone
-
getLocale
Returns the Locale of this model's calendar.- Specified by:
getLocalein interfaceDateSelectionModel- Returns:
- the Locale of this model's calendar.
-
setLocale
Sets the Locale of this model's calendar. Fires a DateSelectionEvent of type CALENDAR_CHANGED if the new value is different from the old.The default value is Locale.default().
PENDING JW: fall back to JComponent.getDefaultLocale instead? We use this with components anyway?
PENDING JW: actually, it's a bound property. Use a propertyChangeListener?
- Specified by:
setLocalein interfaceDateSelectionModel- Parameters:
locale- the Locale to use. If null, the default Locale is used.
-
startOfDay
Returns the start of the day of the given date in this model's calendar. NOTE: the calendar is changed by this operation.- Parameters:
date- the Date to get the start for.- Returns:
- the Date representing the start of the day of the input date.
-
endOfDay
Returns the end of the day of the given date in this model's calendar. NOTE: the calendar is changed by this operation.- Parameters:
date- the Date to get the start for.- Returns:
- the Date representing the end of the day of the input date.
-
isSameDay
Returns a boolean indicating whether the given dates are on the same day in the coordinates of the model's calendar.- Parameters:
selected- one of the dates to check, must not be null.compare- the other of the dates to check, must not be null.- Returns:
- true if both dates represent the same day in this model's calendar.
-
getUpperBound
Return the upper bound date that is allowed to be selected for this model.- Specified by:
getUpperBoundin interfaceDateSelectionModel- Returns:
- upper bound date or null if not set
-
setUpperBound
Set the upper bound date that is allowed to be selected for this model.- Specified by:
setUpperBoundin interfaceDateSelectionModel- Parameters:
upperBound- upper bound
-
getLowerBound
Return the lower bound date that is allowed to be selected for this model.- Specified by:
getLowerBoundin interfaceDateSelectionModel- Returns:
- lower bound date or null if not set
-
setLowerBound
Set the lower bound date that is allowed to be selected for this model.- Specified by:
setLowerBoundin interfaceDateSelectionModel- Parameters:
lowerBound- lower bound date or null if not set
-
isAdjusting
public boolean isAdjusting()Returns the property to decide whether the selection is intermediate or final.- Specified by:
isAdjustingin interfaceDateSelectionModel- Returns:
- the adjusting property.
-
setAdjusting
public void setAdjusting(boolean adjusting) Set the property to mark upcoming selections as intermediate/ final. This will fire a event of type adjusting_start/stop. The default value is false. Note: Client code marking as intermediate must take care of finalizing again.- Specified by:
setAdjustingin interfaceDateSelectionModel- Parameters:
adjusting- a flag to turn the adjusting property on/off.
-
addDateSelectionListener
Add the specified listener to this model.- Specified by:
addDateSelectionListenerin interfaceDateSelectionModel- Parameters:
l- listener to add to this model
-
removeDateSelectionListener
Remove the specified listener to this model.- Specified by:
removeDateSelectionListenerin interfaceDateSelectionModel- Parameters:
l- listener to remove from this model
-
getDateSelectionListeners
get all registered listener to this model.- Returns:
- a List of listeners
-
fireValueChanged
Notifies all listeners that have registered interest for notification on value change.- Parameters:
eventType- DateSelectionEvent type
-