JDatePicker v4.3

com.standbysoft.component.date
Class AbstractDateSelectionModel

java.lang.Object
  extended bycom.standbysoft.component.date.AbstractDateSelectionModel
All Implemented Interfaces:
DateSelectionModel
Direct Known Subclasses:
DefaultDateSelectionModel

public abstract class AbstractDateSelectionModel
extends java.lang.Object
implements DateSelectionModel

The abstract definition for a date selection model that provides implementation for most operations; date selection model implementations should at least start from this class.

Apart from being an implementation of the date selection model interface, it provides two methods to conveniently specify the minimum and maximum allowed dates.

You might also want to see the policy this model uses to determine which dates can be selected and which cannot.


Nested Class Summary
 
Nested classes inherited from class com.standbysoft.component.date.DateSelectionModel
DateSelectionModel.SelectionMode
 
Constructor Summary
AbstractDateSelectionModel()
          Creates a date selection model with no selected dates.
 
Method Summary
 void addDateSelectionInterval(java.util.Date date1, java.util.Date date2)
          Change the selection to be the set union of the current date selection and the dates between date1 and date2 inclusive.
 void addDateSelectionListener(DateSelectionListener listener)
          Registers a new date selection listener to the model.
protected  void fireDateSelectionChanged(DateSelectionEvent evt)
           
protected  void fireDisabledDatesChanged(DateSelectionEvent evt)
           
protected  void fireDisabledDateSelectionAttempted(DateSelectionEvent evt)
           
protected  void fireEmptySelectionAllowedChanged(DateSelectionEvent evt)
           
protected  void fireSelectionModeChanged(DateSelectionEvent evt)
           
 java.util.Date getAnchorSelectionDate()
          Returns the anchor selection date.
 java.util.Date getLeadSelectionDate()
          Returns the lead selection date.
 java.util.EventListener[] getListeners(java.lang.Class listenerType)
           
 java.util.Date getMaximumAllowed()
          Returns the maximum allowed date.
 java.util.Date getMinimumAllowed()
          Returns the minimum allowed date.
 java.util.Date[] getSelectedDates()
          Returns the selected dates.
 DateSelectionModel.SelectionMode getSelectionMode()
          Returns the selection mode used by this model.
 java.util.TimeZone getTimeZone()
          Returns the time zone used to calculate date interval dates.
 boolean isDateSelectable(java.util.Date date)
          Determines whether the specified date can be selected or not from this model.
 boolean isDateSelected(java.util.Date date)
          Determines whether a specified date has been selected.
abstract  boolean isDisabled(java.util.Date date)
          Determines whether the specified date can or cannot be selected.
 boolean isEmptySelectionAllowed()
          Determines whether empty selection is allowed.
 void removeAllDates()
          Removes all selected dates from this model.
 void removeDateSelectionInterval(java.util.Date date1, java.util.Date date2)
          Change the selection to be the set difference of the current selection and the dates between date1 and date2 inclusive.
 void removeDateSelectionListener(DateSelectionListener listener)
          Removes a specified date selection listener from this model.
 void setAnchorSelectionDate(java.util.Date date)
          Sets the anchor selection date.
 void setDateSelectionIterval(java.util.Date date1, java.util.Date date2)
          Changes the date selection interval to be between date1 and date2 inclusive.
 void setEmptySelectionAllowed(boolean allowed)
          Specifies whether the model supports empty date selections that is no date can be selected at one time.
 void setLeadSelectionDate(java.util.Date date)
          Sets the lead selection date.
 void setMaximumAllowed(java.util.Date date)
          Specifies a new maximum allowed date and announces interested parties that the set of date that can be selected has changed.
 void setMinimumAllowed(java.util.Date date)
          Specifies a new minimum allowed date and announces interested parties that the set of date that can be selected has changed.
 void setSelectedDates(java.util.Date[] dates)
          Specifies what dates are selected by this model.
 void setSelectionMode(DateSelectionModel.SelectionMode mode)
          Specifies a new selection mode to be used by this model.
 void setTimeZone(java.util.TimeZone timezone)
          Specifies the time zone used to properly calculate the dates of a date interval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDateSelectionModel

public AbstractDateSelectionModel()
Creates a date selection model with no selected dates. By default, it allows empty selection and for multiple interval selection.

Method Detail

setTimeZone

public void setTimeZone(java.util.TimeZone timezone)
Description copied from interface: DateSelectionModel
Specifies the time zone used to properly calculate the dates of a date interval. This property is used internally by the date components to synchronize their time zone with this model so that it can calculate proper dates when interval selections are made.

Specified by:
setTimeZone in interface DateSelectionModel
Parameters:
timezone - new time zone

getTimeZone

public java.util.TimeZone getTimeZone()
Description copied from interface: DateSelectionModel
Returns the time zone used to calculate date interval dates.

Specified by:
getTimeZone in interface DateSelectionModel
Returns:
time zone used to calculate date interval dates
See Also:
DateSelectionModel.setTimeZone(TimeZone)

isDateSelectable

public boolean isDateSelectable(java.util.Date date)
Determines whether the specified date can be selected or not from this model. For this method, a date can be selected if and only if it is between the minimum date and maximum date and it is not disabled explicitly (isDisabled(Date)). Null dates are considered to be selectable if and only if empty selection is allowed.

Specified by:
isDateSelectable in interface DateSelectionModel
Parameters:
date - date to be tested if it can be selected
Returns:
true if the specified date can be selected; false otherwise.
See Also:
isDisabled(Date), getMaximumAllowed(), getMinimumAllowed(), isEmptySelectionAllowed()

isDisabled

public abstract boolean isDisabled(java.util.Date date)
Determines whether the specified date can or cannot be selected. The logic of this method is different from that of isDateSelectable(Date) because it explicitly says which days cannot be selected. When creating a new selection model, just override this method to say which days cannot be selected.

Parameters:
date - specified date that is tested if it can be selected.
Returns:
true if the specified date cannot be selected; false otherwise.

isDateSelected

public boolean isDateSelected(java.util.Date date)
Description copied from interface: DateSelectionModel
Determines whether a specified date has been selected.

Specified by:
isDateSelected in interface DateSelectionModel
Parameters:
date - date to be tested; if null then it tests if the selection is empty (when empty date selection is allowed)
Returns:
true if the date has been selected; false otherwise.
See Also:
date selection overview, DateSelectionModel.isEmptySelectionAllowed(), DateSelectionModel.getSelectedDates()

setMinimumAllowed

public void setMinimumAllowed(java.util.Date date)
Specifies a new minimum allowed date and announces interested parties that the set of date that can be selected has changed.

Parameters:
date - new minimum allowed date

setMaximumAllowed

public void setMaximumAllowed(java.util.Date date)
Specifies a new maximum allowed date and announces interested parties that the set of date that can be selected has changed.

Parameters:
date - new maximum allowed date

getMinimumAllowed

public java.util.Date getMinimumAllowed()
Description copied from interface: DateSelectionModel
Returns the minimum allowed date. Dates below the minimum allowed date should not be selected. If the minimum allowed date is null then there is no restriction.

Specified by:
getMinimumAllowed in interface DateSelectionModel
Returns:
the minimum allowed date or null.
See Also:
restricted dates overview, DateSelectionModel.isDateSelectable(Date)

getMaximumAllowed

public java.util.Date getMaximumAllowed()
Description copied from interface: DateSelectionModel
Returns the maximum allowed date. Dates above the maximum allowed date should not be selected. If the maximum allowed date is null then there is no restriction.

Specified by:
getMaximumAllowed in interface DateSelectionModel
Returns:
the maximum allowed date or null.
See Also:
restricted dates overview, DateSelectionModel.isDateSelectable(Date)

setSelectionMode

public void setSelectionMode(DateSelectionModel.SelectionMode mode)
Description copied from interface: DateSelectionModel
Specifies a new selection mode to be used by this model. The selection mode tells whether a single date, a date interval or multiple date intervals can be selected.

Specified by:
setSelectionMode in interface DateSelectionModel
Parameters:
mode - selection mode to be used by this model
See Also:
selection type overview, DateSelectionModel.setEmptySelectionAllowed(boolean)

getSelectionMode

public DateSelectionModel.SelectionMode getSelectionMode()
Description copied from interface: DateSelectionModel
Returns the selection mode used by this model.

Specified by:
getSelectionMode in interface DateSelectionModel
Returns:
the selection mode used by this model.
See Also:
selection type overview

setSelectedDates

public void setSelectedDates(java.util.Date[] dates)
Description copied from interface: DateSelectionModel
Specifies what dates are selected by this model. This method selects all the dates only when a multiple selection mode is used. Otherwise, only the first date is selected.

Specified by:
setSelectedDates in interface DateSelectionModel
Parameters:
dates - dates that will be selected. They can be zero, one or more. If empty selection is off and the selected dates array is empty, then no date is selected; the selected dates remain unchanged. On a null array of dates, nothing happens.
See Also:
DateSelectionModel.setEmptySelectionAllowed(boolean), DateSelectionModel.setSelectionMode(DateSelectionModel.SelectionMode)

getSelectedDates

public java.util.Date[] getSelectedDates()
Description copied from interface: DateSelectionModel
Returns the selected dates. Depending on the selection mode, zero, one or more dates are returned. There can be returned zero dates when empty date selection is allowed.

Specified by:
getSelectedDates in interface DateSelectionModel
Returns:
the selected dates; the array can be empty when empty selection is allowed
See Also:
date selection overview, DateSelectionModel.setEmptySelectionAllowed(boolean)

setLeadSelectionDate

public void setLeadSelectionDate(java.util.Date date)
Description copied from interface: DateSelectionModel
Sets the lead selection date. The lead selection date is the second selected date in the selected range. If only one date is selected then it corresponds to that date. When no date is selected, this date is null.

Specified by:
setLeadSelectionDate in interface DateSelectionModel
Parameters:
date - lead date to be set; ignored when null
See Also:
date selection overview

getLeadSelectionDate

public java.util.Date getLeadSelectionDate()
Description copied from interface: DateSelectionModel
Returns the lead selection date.

Specified by:
getLeadSelectionDate in interface DateSelectionModel
Returns:
the lead selection date or null when the selection is empty.
See Also:
DateSelectionModel.setAnchorSelectionDate(Date), date selection overview

setAnchorSelectionDate

public void setAnchorSelectionDate(java.util.Date date)
Description copied from interface: DateSelectionModel
Sets the anchor selection date. The anchor selection date is the first selected date in the selected range. If only one date is selected then it corresponds to that date. When no date is selected, this date is null.

Specified by:
setAnchorSelectionDate in interface DateSelectionModel
Parameters:
date - anchor date to be set; ignored when null
See Also:
date selection overview

getAnchorSelectionDate

public java.util.Date getAnchorSelectionDate()
Description copied from interface: DateSelectionModel
Returns the anchor selection date.

Specified by:
getAnchorSelectionDate in interface DateSelectionModel
Returns:
the anchor selection date or null when the selection is empty.
See Also:
date selection overview, DateSelectionModel.setAnchorSelectionDate(Date)

setEmptySelectionAllowed

public void setEmptySelectionAllowed(boolean allowed)
                              throws DateSelectionException
Description copied from interface: DateSelectionModel
Specifies whether the model supports empty date selections that is no date can be selected at one time. This feature is also known as null date selection. When changing from true to false there must be at least one date selected because otherwise the model would be in an inconsistent state. If that does not happen, the operation fails throwing an exception.

Specified by:
setEmptySelectionAllowed in interface DateSelectionModel
Parameters:
allowed - true if empty selection is allowed or false otherwise
Throws:
DateSelectionException - exception thrown when the model is set to not allow empty selections but it does not contain any selected date.
See Also:
empty selection (null dates) overview

isEmptySelectionAllowed

public boolean isEmptySelectionAllowed()
Description copied from interface: DateSelectionModel
Determines whether empty selection is allowed.

Specified by:
isEmptySelectionAllowed in interface DateSelectionModel
Returns:
true if empty selection is allowed or false otherwise.
See Also:
empty selection (null dates) overview, DateSelectionModel.setEmptySelectionAllowed(boolean)

setDateSelectionIterval

public void setDateSelectionIterval(java.util.Date date1,
                                    java.util.Date date2)
Description copied from interface: DateSelectionModel
Changes the date selection interval to be between date1 and date2 inclusive. Note that date1 doesn't have to be less than or equal to date2. Nothing happens when one of the dates is null.

Specified by:
setDateSelectionIterval in interface DateSelectionModel
Parameters:
date1 - one end of the date interval
date2 - other end of the date interval
See Also:
date selection overview

addDateSelectionInterval

public void addDateSelectionInterval(java.util.Date date1,
                                     java.util.Date date2)
Description copied from interface: DateSelectionModel
Change the selection to be the set union of the current date selection and the dates between date1 and date2 inclusive. If this represents a change to the current date selection, then notify each DateSelectionListener. Note that date1 doesn't have to be less than or equal to date2. Nothing happens when one of the dates is null.

Specified by:
addDateSelectionInterval in interface DateSelectionModel
Parameters:
date1 - one end of the date interval
date2 - other end of the date interval
See Also:
date selection overview

removeDateSelectionInterval

public void removeDateSelectionInterval(java.util.Date date1,
                                        java.util.Date date2)
Description copied from interface: DateSelectionModel
Change the selection to be the set difference of the current selection and the dates between date1 and date2 inclusive. If this represents a change to the current date selection, then notify each DateSelectionListener. Note that date1 doesn't have to be less than or equal to date2. Nothing happens when one of the dates is null.

Specified by:
removeDateSelectionInterval in interface DateSelectionModel
Parameters:
date1 - one end of the date interval
date2 - other end of the date interval
See Also:
date selection overview

removeAllDates

public void removeAllDates()
Description copied from interface: DateSelectionModel
Removes all selected dates from this model. When empty selection is not allowed, the anchor date is kept as selected.

Specified by:
removeAllDates in interface DateSelectionModel
See Also:
date selection overview

addDateSelectionListener

public void addDateSelectionListener(DateSelectionListener listener)
Description copied from interface: DateSelectionModel
Registers a new date selection listener to the model.

Specified by:
addDateSelectionListener in interface DateSelectionModel
Parameters:
listener - listener to be registered
See Also:
events listening overview

removeDateSelectionListener

public void removeDateSelectionListener(DateSelectionListener listener)
Description copied from interface: DateSelectionModel
Removes a specified date selection listener from this model.

Specified by:
removeDateSelectionListener in interface DateSelectionModel
Parameters:
listener - listener to be removed
See Also:
events listening overview

getListeners

public java.util.EventListener[] getListeners(java.lang.Class listenerType)

fireDateSelectionChanged

protected void fireDateSelectionChanged(DateSelectionEvent evt)

fireSelectionModeChanged

protected void fireSelectionModeChanged(DateSelectionEvent evt)

fireDisabledDatesChanged

protected void fireDisabledDatesChanged(DateSelectionEvent evt)

fireEmptySelectionAllowedChanged

protected void fireEmptySelectionAllowedChanged(DateSelectionEvent evt)

fireDisabledDateSelectionAttempted

protected void fireDisabledDateSelectionAttempted(DateSelectionEvent evt)

JDatePicker v4.3

Visit www.jdatepicker.com for further information or send us your suggestions.

Copyright © 2003-2007 Stand By Soft Ltd. All Rights Reserved.