Version: 1.1.1

org.biomoby.service.dashboard.chooser
Class DateTimeChooser

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 org.biomoby.service.dashboard.chooser.DateTimeChooser
All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible

public class DateTimeChooser
extends JPanel
implements PropertyChangeListener

A Swing component that lets choose date and time. It is just a thin wrapper around an open-source package jcalendar, written by Kai Toedter, and released under GNU Lesser General Public License.

Regarding functionality, the wrapper is similar to the standard Java JColorChooser. Which means that a date-time chooser can be either instantiate as a standalone component, or as part of a modal dialog. In former case, the user can listen to the date-time changes in the chooser by implementing a standard ChangeListener, in the later case the returned value of showDialog contains the selected date-time.

It also allows to add a user-defined preview panel that can indicate (in any user-defined format) directly in the chooser window what date is selected.

Version:
$Id: DateTimeChooser.java,v 1.4 2006/02/20 05:51:10 senger Exp $
Author:
Martin Senger
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
DateTimeChooser()
          Creates a date-time chooser with the curent date as an initial date.
DateTimeChooser(Date initialDate)
          Creates a date-time chooser with the given date as an initial date.
 
Method Summary
 void addChangeListener(ChangeListener listener)
          Adds a listener that is notified when a new date is selected.
 ChangeListener[] getChangeListeners()
          Returns an array of all the ChangeListeners.
 Date getDate()
          Gets the current value from the date-time chooser.
 Date getInitialDate()
          Returns a date that was used to initiate this date-time chooser instance.
 JPanel getPreviewPanel()
          Returns the preview panel that shows a currently chosen date.
 void propertyChange(PropertyChangeEvent evt)
          Implementing PropertyChangeListener.
 void removeChangeListener(ChangeListener listener)
          Remove a listener that has been previously added by addChangeListener(javax.swing.event.ChangeListener).
 void setDate(Date newDate)
          Sets the given date as a new value for the date-time chooser.
 void setPreviewPanel(JPanel preview)
          Sets the current preview panel.
static Date showDialog(Component parent, String title, Date initialDate)
          Shows a modal date-time chooser dialog and blocks until the dialog is hidden.
static Date showDialog(Component parent, String title, DateTimeChooser chooser)
          Shows a modal date-time chooser dialog and blocks until the dialog is hidden.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateTimeChooser

public DateTimeChooser()
Creates a date-time chooser with the curent date as an initial date.


DateTimeChooser

public DateTimeChooser(Date initialDate)
Creates a date-time chooser with the given date as an initial date.

Method Detail

getDate

public Date getDate()
Gets the current value from the date-time chooser.


setDate

public void setDate(Date newDate)
Sets the given date as a new value for the date-time chooser.

Parameters:
newDate - to be set into the chooser

getInitialDate

public Date getInitialDate()
Returns a date that was used to initiate this date-time chooser instance. It can be null.


getPreviewPanel

public JPanel getPreviewPanel()
Returns the preview panel that shows a currently chosen date.

Returns:
the current preview panel

setPreviewPanel

public void setPreviewPanel(JPanel preview)
Sets the current preview panel. Usually a preview panel implements ChangeListener interface and registers its wish to be notified when a new date is selected in the chooser.

Parameters:
preview - is a panel used to display currently selected date

showDialog

public static Date showDialog(Component parent,
                              String title,
                              Date initialDate)
Shows a modal date-time chooser dialog and blocks until the dialog is hidden. The dialog has three buttons: OK, Empty, Cancel.

If the user presses the "OK" button, then this method hides/disposes the dialog and returns the selected date.

If the user presses the "Cancel" button or closes the dialog without pressing "OK", then this method hides/disposes the dialog and returns the initial date (which could have been null).

If the user presses the "Empty" button, then this method hides/disposes the dialog and returns null. It indicates that no date is selected (even though that might have been a date as an initial value).

Parameters:
parent - is the parent Component for the dialog
title - contains the dialog's title
initialDate - is shown when the dialog starts; if this is null the current date is shown
Returns:
the selected date (if OK pressed), the initial date (if Cancel presed), or null (if Empty pressed)

showDialog

public static Date showDialog(Component parent,
                              String title,
                              DateTimeChooser chooser)
Shows a modal date-time chooser dialog and blocks until the dialog is hidden. The dialog has three buttons: OK, Empty, Cancel. See details how the buttons are dealt with in showDialog.

This method allows to create an instance of a date-time chooser separately, and perhaps to customize it (e.g. by calling chooser.setPreviewPanel (myPreviewPanel)) before it is used in a modal dialog.

Parameters:
parent - is the parent Component for the dialog
title - contains the dialog's title
chooser - is the chooser instance that was created separately and will be used in this dialog
Returns:
the selected date (if OK pressed), the initial date (if Cancel presed), or null (if Empty pressed)

addChangeListener

public void addChangeListener(ChangeListener listener)
Adds a listener that is notified when a new date is selected.

Parameters:
listener - to be added

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Remove a listener that has been previously added by addChangeListener(javax.swing.event.ChangeListener).

Parameters:
listener - to be added

getChangeListeners

public ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners.

Returns:
all of the ChangeListeners added, or an empty array if no listeners have been added

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Implementing PropertyChangeListener. This implementation only propagates all property change events as a ChangeEvent.

Specified by:
propertyChange in interface PropertyChangeListener

Version: 1.1.1

Submit a bug or feature
Generated: Sat May 29 04:26:35 EDT 2010