uk.co.keang.date
Class IntervalSelector

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by uk.co.keang.date.AbstractDateSelector<org.joda.time.Interval>
                      extended by uk.co.keang.date.IntervalSelector
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class IntervalSelector
extends AbstractDateSelector<org.joda.time.Interval>

A Date Interval selection GUI.
Displays a calendar style view of the days in a month. Two dates are involved in selecting an interval, the base date is selected by selecting any day whilst the shift key is not pressed and the second date is selected by selecting any day whilst the shift key is pressed. The month and year can be easily changed via drop down controls and/or by month increment buttons and the day by clicking on a day button.

If todays date is visible ie the panel is showing the todays month and year then the text on the button with todays day is coloured RED.

As well as being able to select a date using the mouse the following key-strokes are recognised:
LEFT: move the base date back 1 day
RIGHT: move the base date forward one day
UP: move the base date back 1 week
DOWN: move the base date forward 1 week
PAGE_UP: move the base date back 1 month
PAGE_DOWN: move the base date forward 1 month
HOME: move the base date back 1 year
END: move the base date forward 1 year
SHIFT+LEFT: move the second date back 1 day
SHIFT+RIGHT: move the second date forward one day
SHIFT+UP: move the second date back 1 week
SHIFT+DOWN: move the second date forward 1 week
SHIFT+PAGE_UP: move the second date back 1 month
SHIFT+PAGE_DOWN: move the second date forward 1 month
SHIFT+HOME: move the second date back 1 year
SHIFT+END: move the second date forward 1 year
ESC: cancel any selected date and hide the panel
ENTER: retain the selected date and hide the panel

Listeners can be added to receive notification of a change of selected date and/or the selection of a day button.

Factory methods are provided to:
1. Show the selector in a JDialog optionally with OK/Cancel buttons
2. Show the selector in a Popup style panel
3. Attach a popup-on-hover feature to a component to popup a date selector if the mouse hovers over the component.

Alternatively the panel can be constructed directly and added to an existing GUI.

Author:
A.G.Docherty
See Also:
Serialized Form

Nested Class Summary
static class IntervalSelector.PopupIntervalSelector
          The Popup panel for displaying this Interval Selector
 
Nested classes/interfaces inherited from class uk.co.keang.date.AbstractDateSelector
AbstractDateSelector.DayButton
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class uk.co.keang.date.AbstractDateSelector
ACTION_NAME_DAY_DEC, ACTION_NAME_DAY_INC, ACTION_NAME_ENTER, ACTION_NAME_ESC, ACTION_NAME_MONTH_DEC, ACTION_NAME_MONTH_INC, ACTION_NAME_WEEK_DEC, ACTION_NAME_WEEK_INC, ACTION_NAME_YEAR_DEC, ACTION_NAME_YEAR_INC, baseDate, chronology, movingDate, window
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
IntervalSelector(org.joda.time.DateTime base, org.joda.time.DateTime end, boolean includeOkCancel)
          Construct an IntervalSelector.
IntervalSelector(org.joda.time.DateTime base, org.joda.time.DateTime end, boolean includeOkCancel, java.util.Locale loc)
          Construct an IntervalSelector.
IntervalSelector(org.joda.time.Interval interval, boolean includeOkCancel)
          Construct an IntervalSelector.
IntervalSelector(org.joda.time.Interval interval, boolean includeOkCancel, java.util.Locale loc)
          Construct an IntervalSelector.
 
Method Summary
static IntervalSelector.PopupIntervalSelector createPopup(java.awt.Component owner, org.joda.time.Interval interval)
          Creates a popup panel allowing the selection of a date interval.
static IntervalSelector.PopupIntervalSelector createPopup(java.awt.Component owner, IntervalSelector panel)
          Creates a popup panel allowing the selection of a date interval.
 org.joda.time.Interval getSelectedDate()
          Gets the selected date interval.
protected  void initKeyActions()
          init the key strokes that have meaning for this panel
static void removePopupOnHoverFromComponent(java.awt.Component owner)
          Removes the Popup on hover functionality from this component
static void setPopupOnHoverForComponent(java.awt.Component owner, org.joda.time.MutableInterval dt, java.awt.event.ActionListener l)
          Adds a pop up listener to this component.
 void setSelectedDate(org.joda.time.DateTime base, org.joda.time.DateTime end)
          Sets the selected date interval.
 void setSelectedDate(org.joda.time.Interval date)
          Sets the selected date interval.
static org.joda.time.Interval show(java.awt.Component owner, java.lang.String title, org.joda.time.Interval now)
          Displays a modal dialog allowing the selection of a date interval.
static org.joda.time.Interval show(java.awt.Component owner, java.lang.String title, IntervalSelector panel)
          Displays a modal dialog allowing the selection of a date interval.
 
Methods inherited from class uk.co.keang.date.AbstractDateSelector
addDateChangedListener, addDayActionListener, createDialog, fireDateChangeListener, fireDayBtnListener, getWindowForComponent, isShowDayNames, isShowOkCancelPanel, isShowSurroundingDays, isShowWeekNums, removeDateChangedListener, removeDayActionListener, setCancelBtnAction, setFont, setOkBtnAction, setPopupOnHoverForComponent, setShowDayNames, setShowOkCancelPanel, setShowSurroundingDays, setShowWeekNums, updateOnSettingSelectedDate
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntervalSelector

public IntervalSelector(org.joda.time.Interval interval,
                        boolean includeOkCancel)
Construct an IntervalSelector. The base date is assumed to be the start date of the interval.

An interval is half inclusive ie the start date is inclusive and the end date is exclusive.

Parameters:
interval - - the initial date interval
includeOkCancel - - true to include a panel with OK and Cancel buttons

IntervalSelector

public IntervalSelector(org.joda.time.Interval interval,
                        boolean includeOkCancel,
                        java.util.Locale loc)
Construct an IntervalSelector. The base date is assumed to be the start date of the interval.

Parameters:
interval - - the initial date interval
includeOkCancel - - true to include a panel with OK and Cancel buttons

IntervalSelector

public IntervalSelector(org.joda.time.DateTime base,
                        org.joda.time.DateTime end,
                        boolean includeOkCancel)
Construct an IntervalSelector. The base date is assumed to be the start date of the interval.

These values are both inclusive

Parameters:
base - - the base date
end - - the end date, this may be before or after the base date
includeOkCancel - - true to include a panel with OK and Cancel buttons

IntervalSelector

public IntervalSelector(org.joda.time.DateTime base,
                        org.joda.time.DateTime end,
                        boolean includeOkCancel,
                        java.util.Locale loc)
Construct an IntervalSelector. The base date is assumed to be the start date of the interval.

Parameters:
base - - the base date
end - - the end date, this may be before or after the base date
includeOkCancel - - true to include a panel with OK and Cancel buttons
Method Detail

setPopupOnHoverForComponent

public static void setPopupOnHoverForComponent(java.awt.Component owner,
                                               org.joda.time.MutableInterval dt,
                                               java.awt.event.ActionListener l)
Adds a pop up listener to this component. When the mouse hovers over the component an IntervalSelector popup will display.

The panel will close when: 1. a day button is selected 2. the mouse moves out of the panel 3. the ESCAPE key is pressed 4. the ENTER key is pressed

The given listener will be called only if the panel closes due to a day being selected or the ENTER key is pressed

Parameters:
owner - - the component to add the hover popup listener to
dt - - the date that will display when the popup pops up. This objects date can be dynamically changed by the calling code to change the date that displays on popup
l - - a listener that will be called when a day button is selected

removePopupOnHoverFromComponent

public static void removePopupOnHoverFromComponent(java.awt.Component owner)
Removes the Popup on hover functionality from this component

Parameters:
owner - - the component

createPopup

public static IntervalSelector.PopupIntervalSelector createPopup(java.awt.Component owner,
                                                                 org.joda.time.Interval interval)
Creates a popup panel allowing the selection of a date interval. The panel is an undecorated JDialog with OK and cancel buttons. To show the panel use setVisible(true);

Parameters:
owner - - the owning component or null
interval - - the time now
Returns:
the popup panel

createPopup

public static IntervalSelector.PopupIntervalSelector createPopup(java.awt.Component owner,
                                                                 IntervalSelector panel)
Creates a popup panel allowing the selection of a date interval. The panel is an undecorated JDialog. To show/hide the panel use setVisible(boolean);

This method is provided to allow an IntervalSelector pane to be constructed, configured and then displayed.

Parameters:
owner - - the owning component or null
panel - - the panel
Returns:
the pop up panel

show

public static org.joda.time.Interval show(java.awt.Component owner,
                                          java.lang.String title,
                                          org.joda.time.Interval now)
Displays a modal dialog allowing the selection of a date interval.

Parameters:
owner - - the owning component or null
title - - The title to display in the dialog frame or null for no title
now - - the time now
Returns:
the selected date or null if cancel pressed

show

public static org.joda.time.Interval show(java.awt.Component owner,
                                          java.lang.String title,
                                          IntervalSelector panel)
Displays a modal dialog allowing the selection of a date interval.

This method is provided to allow an IntervalSelector pane to be constructed, configured and then displayed.

Parameters:
owner - - the owning component or null
title - - The title to display in the dialog frame or null for no title
panel - - the panel
Returns:
the selected date or null if cancel pressed

initKeyActions

protected void initKeyActions()
init the key strokes that have meaning for this panel

Overrides:
initKeyActions in class AbstractDateSelector<org.joda.time.Interval>

getSelectedDate

public org.joda.time.Interval getSelectedDate()
Gets the selected date interval.

The returned interval is half inclusive ie the start date is inclusive and the end date is exclusive.

Specified by:
getSelectedDate in class AbstractDateSelector<org.joda.time.Interval>
Returns:
the selected date or null if cancel was pressed

setSelectedDate

public void setSelectedDate(org.joda.time.Interval date)
Sets the selected date interval. The base date is assumed to be the start date of the interval.

The interval is half inclusive ie the start date is inclusive and the end date is exclusive.

Specified by:
setSelectedDate in class AbstractDateSelector<org.joda.time.Interval>
Parameters:
date - - the selected date

setSelectedDate

public void setSelectedDate(org.joda.time.DateTime base,
                            org.joda.time.DateTime end)
Sets the selected date interval.

The dates are fully inclusive

Parameters:
base - - the base date
end - - the end date, this may be before or after the base date