Class DefaultDateSelectionModel

java.lang.Object
org.jdesktop.swingx.calendar.AbstractDateSelectionModel
org.jdesktop.swingx.calendar.DefaultDateSelectionModel
All Implemented Interfaces:
DateSelectionModel

public class DefaultDateSelectionModel extends AbstractDateSelectionModel
Author:
Joshua Outwater
  • Constructor Details

    • DefaultDateSelectionModel

      public DefaultDateSelectionModel()
    • DefaultDateSelectionModel

      public DefaultDateSelectionModel(Locale locale)
      The selection mode defaults to SINGLE_SELECTION.
      Parameters:
      locale - Locale
  • Method Details

    • getSelectionMode

      public DateSelectionModel.SelectionMode getSelectionMode()
      Get the selection mode.
      Returns:
      return the current selection mode
    • setSelectionMode

      public void setSelectionMode(DateSelectionModel.SelectionMode selectionMode)
      Set the selection mode.
      Parameters:
      selectionMode - new selection mode
    • addSelectionInterval

      public void addSelectionInterval(Date startDate, Date endDate)
      Adds the specified selection interval to the selection model.
      Parameters:
      startDate - interval start date, must not be null
      endDate - interval end date >= start date, must not be null
    • setSelectionInterval

      public void setSelectionInterval(Date startDate, Date endDate)
      Sest the specified selection interval to the selection model.
      Parameters:
      startDate - interval start date, must not be null
      endDate - interval end date >= start date, must not be null
    • removeSelectionInterval

      public void removeSelectionInterval(Date startDate, 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 null
      endDate - 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.
    • getSelection

      public SortedSet<Date> getSelection()
      Returns the current selection.
      Returns:
      sorted set of selected dates, guaranteed to be never null.
    • getFirstSelectionDate

      public 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:
    • getLastSelectionDate

      public 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:
    • isSelected

      public boolean isSelected(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
    • getNormalizedDate

      public Date getNormalizedDate(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();
       }
       
      Parameters:
      date - date to normalize
      Returns:
      the date as it would be normalized before used in the model, must not be null.
    • isSelectionEmpty

      public boolean isSelectionEmpty()
      Returns true if the selection is empty, false otherwise.
      Returns:
      true if the selection is empty, false otherwise
    • getUnselectableDates

      public SortedSet<Date> getUnselectableDates()
      Returns a SortedSet of Dates that are unselectable.
      Returns:
      sorted set of dates
    • setUnselectableDates

      public void setUnselectableDates(SortedSet<Date> unselectableDates)
      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:
      unselectableDates - dates that are unselectable, must not be null and must not contain null dates.
    • isUnselectableDate

      public boolean isUnselectableDate(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