/** * Returns a boolean indication whether the given date is below * the lower or above the upper bound. * * @param date * @return */ private boolean outOfBounds(Date date) { if (belowLowerBound(date)) return true; if (aboveUpperBound(date)) return true; return false; }
/** * @param date * @return */ private boolean aboveUpperBound(Date date) { if (upperBound != null) { return endOfDay(upperBound).before(date); } return false; }
/** * {@inheritDoc} */ @Override public void clearSelection() { if (isSelectionEmpty()) return; selectedDates.clear(); fireValueChanged(EventType.SELECTION_CLEARED); }
/** * Returns a boolean indicating whether the given date is selectable. * * @param date the date to check for selectable, must not be null. * @return true if the given date is selectable, false if not. */ public boolean isSelectable(Date date) { if (outOfBounds(date)) return false; return !inUnselectables(date); }
/** * {@inheritDoc} */ @Override public void removeSelectionInterval(Date startDate, Date endDate) { Contract.asNotNull(startDate, "date must not be null"); if (isSelectionEmpty()) return; if (isSelectionInInterval(startDate, endDate)) { selectedDates.clear(); fireValueChanged(EventType.DATES_REMOVED); } }
/** * Selects the given date if it is selectable and not yet selected. * Does nothing otherwise. * If this operation changes the current selection, it will fire a * DateSelectionEvent of type DATES_SET. * * @param date the Date to select, must not be null. */ protected void setSelection(Date date) { Contract.asNotNull(date, "date must not be null"); if (isSelectedStrict(date)) return; if (isSelectable(date)) { selectedDates.clear(); // PENDING JW: use normalized selectedDates.add(date); fireValueChanged(EventType.DATES_SET); } }
/** * {@inheritDoc} */ @Override public boolean isSelected(Date date) { Contract.asNotNull(date, "date must not be null"); if (isSelectionEmpty()) return false; return isSameDay(selectedDates.first(), date); }
/** * {@inheritDoc} */ public void setUnselectableDates(SortedSet<Date> unselectables) { Contract.asNotNull(unselectables, "unselectable dates must not be null"); this.unselectableDates.clear(); for (Date unselectableDate : unselectables) { removeSelectionInterval(unselectableDate, unselectableDate); unselectableDates.add(unselectableDate); } fireValueChanged(EventType.UNSELECTED_DATES_CHANGED); }
/** * Checks and returns whether the selected date is contained in the interval * given by startDate/endDate. The selection must not be empty when * calling this method. <p> * * This implementation interprets the interval between the start of the day * of startDay to the end of the day of endDate. * * @param startDate the start of the interval, must not be null * @param endDate the end of the interval, must not be null * @return true if the selected date is contained in the interval */ protected boolean isSelectionInInterval(Date startDate, Date endDate) { if (selectedDates.first().before(startOfDay(startDate)) || (selectedDates.first().after(endOfDay(endDate)))) return false; return true; }
/** * {@inheritDoc} */ @Override public Date getFirstSelectionDate() { return isSelectionEmpty() ? null : selectedDates.first(); }
/** * {@inheritDoc} */ public boolean isUnselectableDate(Date date) { return !isSelectable(date); }
/** * @param date * @return */ private boolean inUnselectables(Date date) { for (Date unselectable : unselectableDates) { if (isSameDay(unselectable, date)) return true; } return false; }
/** * {@inheritDoc} */ @Override public void removeSelectionInterval(Date startDate, Date endDate) { Contract.asNotNull(startDate, "date must not be null"); if (isSelectionEmpty()) return; if (isSelectionInInterval(startDate, endDate)) { selectedDates.clear(); fireValueChanged(EventType.DATES_REMOVED); } }
/** * Selects the given date if it is selectable and not yet selected. * Does nothing otherwise. * If this operation changes the current selection, it will fire a * DateSelectionEvent of type DATES_SET. * * @param date the Date to select, must not be null. */ protected void setSelection(Date date) { Contract.asNotNull(date, "date must not be null"); if (isSelectedStrict(date)) return; if (isSelectable(date)) { selectedDates.clear(); // PENDING JW: use normalized selectedDates.add(date); fireValueChanged(EventType.DATES_SET); } }
/** * {@inheritDoc} */ @Override public boolean isSelected(Date date) { Contract.asNotNull(date, "date must not be null"); if (isSelectionEmpty()) return false; return isSameDay(selectedDates.first(), date); }
/** * {@inheritDoc} */ @Override public void setUnselectableDates(SortedSet<Date> unselectables) { Contract.asNotNull(unselectables, "unselectable dates must not be null"); this.unselectableDates.clear(); for (Date unselectableDate : unselectables) { removeSelectionInterval(unselectableDate, unselectableDate); unselectableDates.add(unselectableDate); } fireValueChanged(EventType.UNSELECTED_DATES_CHANGED); }
/** * Returns a boolean indicating whether the given date is selectable. * * @param date the date to check for selectable, must not be null. * @return true if the given date is selectable, false if not. */ public boolean isSelectable(Date date) { if (outOfBounds(date)) return false; return !inUnselectables(date); }
/** * Checks and returns whether the selected date is contained in the interval * given by startDate/endDate. The selection must not be empty when * calling this method. <p> * * This implementation interprets the interval between the start of the day * of startDay to the end of the day of endDate. * * @param startDate the start of the interval, must not be null * @param endDate the end of the interval, must not be null * @return true if the selected date is contained in the interval */ protected boolean isSelectionInInterval(Date startDate, Date endDate) { if (selectedDates.first().before(startOfDay(startDate)) || (selectedDates.first().after(endOfDay(endDate)))) return false; return true; }
/** * {@inheritDoc} */ @Override public Date getFirstSelectionDate() { return isSelectionEmpty() ? null : selectedDates.first(); }
/** * {@inheritDoc} */ @Override public boolean isUnselectableDate(Date date) { return !isSelectable(date); }