Package org.jdesktop.swingx.calendar
Class DaySelectionModel
- java.lang.Object
-
- org.jdesktop.swingx.calendar.AbstractDateSelectionModel
-
- org.jdesktop.swingx.calendar.DaySelectionModel
-
- All Implemented Interfaces:
DateSelectionModel
public class DaySelectionModel extends AbstractDateSelectionModel
DaySelectionModel is a (temporary?) implementation of DateSelectionModel which normalizes all dates to the start of the day, that is zeroes all time fields. Responsibility extracted from JXMonthView (which must respect rules of model instead of trying to be clever itself).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jdesktop.swingx.calendar.DateSelectionModel
DateSelectionModel.SelectionMode
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.SortedSet<java.util.Date>
selectedDates
private DateSelectionModel.SelectionMode
selectionMode
private java.util.SortedSet<java.util.Date>
unselectableDates
-
Fields inherited from class org.jdesktop.swingx.calendar.AbstractDateSelectionModel
adjusting, calendar, EMPTY_DATES, listenerMap, locale, lowerBound, upperBound
-
-
Constructor Summary
Constructors Constructor Description DaySelectionModel()
DaySelectionModel(java.util.Locale locale)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
addSelectionImpl(java.util.Date startDate, java.util.Date endDate)
void
addSelectionInterval(java.util.Date startDate, java.util.Date endDate)
Adds the specified selection interval to the selection model.void
clearSelection()
Clears any selection from the selection model.private void
clearSelectionImpl()
java.util.Date
getFirstSelectionDate()
Returns the earliest date in the selection or null if the selection is empty.java.util.Date
getLastSelectionDate()
Returns the latest date in the selection or null if the selection is empty.java.util.Date
getNormalizedDate(java.util.Date date)
Returns a normalized Date as used by the implementation, if any.java.util.SortedSet<java.util.Date>
getSelection()
Returns the current selection.DateSelectionModel.SelectionMode
getSelectionMode()
Get the selection mode.java.util.SortedSet<java.util.Date>
getUnselectableDates()
Returns aSortedSet
ofDates that are unselectable.
private boolean
isIntervalSelected(java.util.Date startDate, java.util.Date endDate)
Checks and returns if the single date interval bounded by startDate and endDate is selected.boolean
isSelected(java.util.Date date)
Returns true if the date specified is selected, false otherwise.boolean
isSelectionEmpty()
Returns true if the selection is empty, false otherwise.boolean
isUnselectableDate(java.util.Date date)
Returns true is the specified date is unselectable.void
removeSelectionInterval(java.util.Date startDate, java.util.Date endDate)
Removes the specifed selection interval from the selection model.void
setSelectionInterval(java.util.Date startDate, java.util.Date endDate)
Sest the specified selection interval to the selection model.void
setSelectionMode(DateSelectionModel.SelectionMode selectionMode)
Set the selection mode.void
setUnselectableDates(java.util.SortedSet<java.util.Date> unselectables)
Sets a collection of dates which are not selectable.-
Methods inherited from class org.jdesktop.swingx.calendar.AbstractDateSelectionModel
addDateSelectionListener, adjustDatesToTimeZone, endOfDay, fireValueChanged, getCalendar, getDateSelectionListeners, getFirstDayOfWeek, getLocale, getLowerBound, getMinimalDaysInFirstWeek, getTimeZone, getUpperBound, isAdjusting, isSameDay, removeDateSelectionListener, setAdjusting, setFirstDayOfWeek, setLocale, setLowerBound, setMinimalDaysInFirstWeek, setTimeZone, setUpperBound, startOfDay
-
-
-
-
Field Detail
-
selectionMode
private DateSelectionModel.SelectionMode selectionMode
-
selectedDates
private java.util.SortedSet<java.util.Date> selectedDates
-
unselectableDates
private java.util.SortedSet<java.util.Date> unselectableDates
-
-
Method Detail
-
getSelectionMode
public DateSelectionModel.SelectionMode getSelectionMode()
Description copied from interface:DateSelectionModel
Get the selection mode.- Returns:
- return the current selection mode
-
setSelectionMode
public void setSelectionMode(DateSelectionModel.SelectionMode selectionMode)
Description copied from interface:DateSelectionModel
Set the selection mode.- Parameters:
selectionMode
- new selection mode
-
addSelectionInterval
public void addSelectionInterval(java.util.Date startDate, java.util.Date endDate)
Adds the specified selection interval to the selection model.- Parameters:
startDate
- interval start date, must not be nullendDate
- interval end date >= start date, must not be null
-
setSelectionInterval
public void setSelectionInterval(java.util.Date startDate, java.util.Date endDate)
Sest the specified selection interval to the selection model.- Parameters:
startDate
- interval start date, must not be nullendDate
- interval end date >= start date, must not be null
-
isIntervalSelected
private boolean isIntervalSelected(java.util.Date startDate, java.util.Date endDate)
Checks and returns if the single date interval bounded by startDate and endDate is selected. This is useful only for SingleInterval mode.- Parameters:
startDate
- the start of the intervalendDate
- the end of the interval, must be >= startDate- Returns:
- true the interval is selected, false otherwise.
-
removeSelectionInterval
public void removeSelectionInterval(java.util.Date startDate, java.util.Date endDate)
Removes the specifed selection interval from the selection model. If the selection is changed by this method, it fires a DateSelectionEvent of type DATES_REMOVED.- Parameters:
startDate
- interval start date, must not be nullendDate
- interval end date >= start date, must not be null
-
clearSelection
public void clearSelection()
Clears any selection from the selection model. Fires an Event of type SELECTION_CLEARED if there had been a selection, does nothing otherwise.
-
clearSelectionImpl
private void clearSelectionImpl()
-
getSelection
public java.util.SortedSet<java.util.Date> getSelection()
Returns the current selection.- Returns:
- sorted set of selected dates, guaranteed to be never null.
-
getFirstSelectionDate
public java.util.Date getFirstSelectionDate()
Returns the earliest date in the selection or null if the selection is empty.- Returns:
- the earliest date in the selection, or null if isSelectionEmpty.
- See Also:
DateSelectionModel.getLastSelectionDate()
,DateSelectionModel.getSelection()
,DateSelectionModel.isSelectionEmpty()
-
getLastSelectionDate
public java.util.Date getLastSelectionDate()
Returns the latest date in the selection or null if the selection is empty.- Returns:
- the lastest date in the selection, or null if isSelectionEmpty.
- See Also:
DateSelectionModel.getFirstSelectionDate()
,DateSelectionModel.getSelection()
,DateSelectionModel.isSelectionEmpty()
-
isSelected
public boolean isSelected(java.util.Date date)
Returns true if the date specified is selected, false otherwise.Note: it is up to implementations to define the exact notion of selected. It does not imply the exact date as given is contained the set returned from getSelection().
- Parameters:
date
- date to check for selection, must not be null- Returns:
- true if the date is selected, false otherwise
-
isSelectionEmpty
public boolean isSelectionEmpty()
Returns true if the selection is empty, false otherwise.- Returns:
- true if the selection is empty, false otherwise
-
getUnselectableDates
public java.util.SortedSet<java.util.Date> getUnselectableDates()
Returns aSortedSet
ofDates that are unselectable.
- Returns:
- sorted set of dates
-
setUnselectableDates
public void setUnselectableDates(java.util.SortedSet<java.util.Date> unselectables)
Sets a collection of dates which are not selectable.Note: it is up to implementations to define the exact notion of unselectableDate. It does not imply the only the exact date as given is unselectable, it might have a period like "all dates on the same day". PENDING JW: any collection would do - why insist on a SortedSet?
- Parameters:
unselectables
- dates that are unselectable, must not be null and must not contain null dates.
-
isUnselectableDate
public boolean isUnselectableDate(java.util.Date date)
Returns true is the specified date is unselectable.- Parameters:
date
- the date to check for unselectability, must not be null.- Returns:
- true is the date is unselectable, false otherwise
-
addSelectionImpl
private boolean addSelectionImpl(java.util.Date startDate, java.util.Date endDate)
-
getNormalizedDate
public java.util.Date getNormalizedDate(java.util.Date date)
Returns a normalized Date as used by the implementation, if any. F.i. DaySelectionModel returns the start of the day in the model's calendar. If no normalization is applied, a clone of the Date itself is returned. The given Date is never changed.The overall contract:
if ((date != null) && isSelectable(date)) { setSelectionInterval(date, date); assertEquals(getNormalized(date), getFirstSelectionDate(); }
Implemented to return the start of the day which contains the date.
- Returns:
- the date as it would be normalized before used in the model, must not be null.
-
-