|
JDatePicker v4.3.25 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface DateSelectionModel
The date selection model defines basic operations needed by date components
like JDatePicker to make valid
date selections; it abstracts everything there is about date selection.
This model tries to be flexible enough to offer powerful date selection operations and this makes its interface rather big. Next, an overview of the problems it tries to solve is presented:
Before delving more into the API, here is a possible scenario that presents the methods it is most likely you will use.
selection typenull datesevent listenerdatesWhenever working with dates, users might need to select more that just one date. Perhaps they need to select a whole range of dates. To suit these needs, the date selection model can be configured for a specific type of selection.
Single allows the selection of only one date at a time
Single interval allows the selection of only one range of dates
Multiple interval allows the selection of multiple date ranges
Use setSelectionMode(DateSelectionModel.SelectionMode)
and getSelectionMode() methods in order to specify and
determine the selection mode that is used. Note that if the model is set on single
selection type, for instance, there is no chance you could select more than one date.
Date selection means not only selecting one or more dates, but also selecting no date at all. By empty selection we mean no selected date. Empty selection is also known as null date selection.
So, if you need to allow empty selection (null dates), just use
setEmptySelectionAllowed(boolean) and set it to true. To
find out whether empty selection is allowed use isEmptySelectionAllowed().
To clear all the selected dates use removeAllDates() method.
Often the business logic imposes restrictions on the dates that can be selected by users. Possible solutions are to validate the selected dates against the list of selectable dates or to make it impossible in the first place for those dates to be selected. The date selection model helps you implement the second approach in a flexible manner.
Date selection restrictions may refer to one of:
By date restriction, we mean allowing only semantically valid dates to be
selected. A possible client of this model can determine if a date can be selected
or not by calling the isDateSelectable(Date) method.
Of course, various implementations of this interface may use whatever logic to determine which dates are selectable and which are not.
The model can also specify an interval of valid dates contained between
getMinimumAllowed() and getMaximumAllowed().
As its name says, this model is about date selection. This means that you can easily specify and determine which dates are selected. The basic operations are:
date is selected or not,dates are selected,selected,Remove all selected dates.To control the selected dates, one can also use addDateSelectionInterval(Date, Date)
and removeDateSelectionInterval(Date, Date).
getAnchorSelectionDate(), setAnchorSelectionDate(Date),
getLeadSelectionDate() and setLeadSelectionDate(Date) are intended
to be used internally.
Sometimes you might just want to check what happens with the selection model. Perhaps to see when the selected dates change.
For all these situations you must create a class that implements DateSelectionListener
and then register it using addDateSelectionListener(DateSelectionListener)
to receive notifications. Use removeDateSelectionListener(DateSelectionListener)
to stop a listener receiving notifications.
| Nested Class Summary | |
|---|---|
static class |
DateSelectionModel.SelectionMode
The type of selection for the selection model that allows to choose from single, interval or multiple interval selection. |
| 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. |
java.util.Date |
getAnchorSelectionDate()
Returns the anchor selection date. |
java.util.Date |
getLeadSelectionDate()
Returns the lead selection date. |
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 a specified date can be selected from this model or not. |
boolean |
isDateSelected(java.util.Date date)
Determines whether a specified date has been 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 |
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. |
| Method Detail |
|---|
void setTimeZone(java.util.TimeZone timezone)
timezone - new time zonejava.util.TimeZone getTimeZone()
setTimeZone(TimeZone)void setSelectionMode(DateSelectionModel.SelectionMode mode)
mode - selection mode to be used by this modelsetEmptySelectionAllowed(boolean)DateSelectionModel.SelectionMode getSelectionMode()
void setEmptySelectionAllowed(boolean allowed)
throws DateSelectionException
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.
allowed - true if empty selection is allowed or false otherwise
DateSelectionException - exception thrown when the model is set to not allow empty selections
but it does not contain any selected date.boolean isEmptySelectionAllowed()
true if empty selection is allowed or false otherwise.setEmptySelectionAllowed(boolean)boolean isDateSelectable(java.util.Date date)
date - the date to be tested; if null is the same as asking
whether empty date selection is allowed
true if the date can be selected; false otherwise.isEmptySelectionAllowed()java.util.Date getMinimumAllowed()
null then there is no restriction.
null.isDateSelectable(Date)java.util.Date getMaximumAllowed()
null then there is no restriction.
null.isDateSelectable(Date)boolean isDateSelected(java.util.Date date)
date - date to be tested; if null then it tests if the
selection is empty (when empty date selection is allowed)
true if the date has been selected; false otherwise.isEmptySelectionAllowed(),
getSelectedDates()void setSelectedDates(java.util.Date[] dates)
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.setEmptySelectionAllowed(boolean),
setSelectionMode(DateSelectionModel.SelectionMode)java.util.Date[] getSelectedDates()
setEmptySelectionAllowed(boolean)java.util.Date getAnchorSelectionDate()
null when the selection is empty.setAnchorSelectionDate(Date)void setAnchorSelectionDate(java.util.Date date)
null.
date - anchor date to be set; ignored when nulljava.util.Date getLeadSelectionDate()
null when the selection is empty.setAnchorSelectionDate(Date),
date selection overviewvoid setLeadSelectionDate(java.util.Date date)
null.
date - lead date to be set; ignored when null
void setDateSelectionIterval(java.util.Date date1,
java.util.Date date2)
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.
date1 - one end of the date intervaldate2 - other end of the date interval
void addDateSelectionInterval(java.util.Date date1,
java.util.Date date2)
DateSelectionListener.
Note that date1 doesn't have to be less than or equal to date2.
Nothing happens when one of the dates is null.
date1 - one end of the date intervaldate2 - other end of the date interval
void removeDateSelectionInterval(java.util.Date date1,
java.util.Date date2)
DateSelectionListener.
Note that date1 doesn't have to be less than or equal to date2.
Nothing happens when one of the dates is null.
date1 - one end of the date intervaldate2 - other end of the date intervalvoid removeAllDates()
void addDateSelectionListener(DateSelectionListener listener)
listener - listener to be registeredvoid removeDateSelectionListener(DateSelectionListener listener)
listener - listener to be removed
|
JDatePicker v4.3.25 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Visit www.jdatepicker.com for further information or send us your suggestions.
Copyright © 2003-2010 Elmro Ltd. All Rights Reserved.