JDatePicker v4.3

com.standbysoft.component.date.swing
Class JDateComponent

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bycom.standbysoft.component.date.swing.JDateComponent
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
JDateEditComponent, JMonth

public abstract class JDateComponent
extends javax.swing.JComponent

JDateComponent is the base class for all date selection components. You can find task-oriented documentation and examples of using date components in Using a JDateComponent, a section in The JDatePicker Suite Tutorial.

Its purpose is to provide common functionality for all such components. Most of its methods make it easier to work with the date selection model; they just delegate further to the selection model that is set on the component.

Besides that, this class provides a few actions that alter the dates selected by the date selection model. Here is how these actions can be used on a date component.

 InputMap im = dateComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
 ActionMap am = dateComponent.getActionMap();
 
 im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), JDateComponent.selectNextDayAction);
 am.put(JDateComponent.selectNextDayAction, new JDateComponent.RollDateAction(Calendar.DATE, true));
 
 im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), JDateComponent.selectPreviousDayAction);
 am.put(JDateComponent.selectPreviousDayAction, new JDateComponent.RollDateAction(Calendar.DATE, false));
 
 im.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), JDateComponent.selectSameDayPreviousWeekAction);
 am.put(JDateComponent.selectSameDayPreviousWeekAction, new JDateComponent.RollDateAction(Calendar.WEEK_OF_YEAR, false));
 

See Also:
Serialized Form

Nested Class Summary
static class JDateComponent.DateAction
           
static class JDateComponent.RollDateAction
          This action is used to increment/decrement the value of one date field with one unit.
static class JDateComponent.SelectFirstDayAction
          This action is used to select the first selectable day of the currently selected month.
static class JDateComponent.SelectLastDayAction
          This action is used to select the last selectable day of the currently selected month.
static class JDateComponent.SelectNoneAction
          This action is used to deselect all selected dates.
static class JDateComponent.SelectTodayAction
          This action is used to select the today date.
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.String actionCommand
          The name of the action command used when an action event is fired by this component.
protected  java.util.Calendar calendar
           
protected  DateSelectionModel dateSelectionModel
          The selection model used by this component to select one or more dates.
protected  DateSelectionListener dateSelectionModelListener
          Listener that takes date selection listener events from the model and fires them further away as events generated by this component.
protected  java.util.Locale locale
           
static java.lang.String selectFirstDayAction
          Name of the action to select the first selectable day in a month.
static java.lang.String selectLastDayAction
          Name of the action to select the last selectable day in a month.
static java.lang.String selectNextDayAction
          Name of the action to select the next selectable day in a month.
static java.lang.String selectNoneAction
          Name of the action to unselect all selected dates.
static java.lang.String selectPreviousDayAction
          Name of the action to select the previous selectable day in a month.
static java.lang.String selectSameDayNextMonthAction
          Name of the action to select the same day of month, next month.
static java.lang.String selectSameDayNextWeekAction
          Name of the action to select the same day of week, next week.
static java.lang.String selectSameDayNextYearAction
          Name of the action to select the same day of year, next year.
static java.lang.String selectSameDayPreviousMonthAction
          Name of the action to select the same day of month, previous month.
static java.lang.String selectSameDayPreviousWeekAction
          Name of the action to select the same day of week, previous week.
static java.lang.String selectSameDayPreviousYearAction
          Name of the action to select the same day of year, previous year.
static java.lang.String selectTodayAction
          Name of the action to unselect all selected dates.
protected  java.util.TimeZone timeZone
          The dates handled by a date component are always from a certain timezone.
 
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
JDateComponent()
          Creates a date component with a default date selection model.
JDateComponent(DateSelectionModel model)
          Creates a date component with a specified date selection model.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Registers an action listener that is notified when some component specific action is performed.
 void addDateSelectionListener(DateSelectionListener listener)
          Registers a date selection listener that will receive notifications when the date selection model changes.
 void fireActionEvent()
          Notifies all registered listeners that an action happened on this component.
protected  void fireDateSelectionChanged(DateSelectionEvent evt)
           
protected  void fireDisabledDatesChanged(DateSelectionEvent evt)
           
protected  void fireDisabledDateSelectionAttempted(DateSelectionEvent evt)
           
protected  void fireEmptySelectionAllowedChanged(DateSelectionEvent evt)
           
protected  void fireSelectionModeChanged(DateSelectionEvent evt)
           
 java.lang.String getActionCommand()
          Returns the name of the action command that is used when an action event is created.
 java.util.Calendar getCalendar()
          Returns the calendar object used by this component.
 DateSelectionModel getDateSelectionModel()
          Returns the selection model used by this component.
 java.util.Locale getLocale()
          Returns the locale used by this component.
 java.util.Date getSelectedDate()
          Returns the currently selected date.
 java.util.TimeZone getTimeZone()
          Returns the time zone used by this component.
 DateUI getUI()
          Returns the L&F object that renders this component.
 boolean isEmptySelectionAllowed()
          Determines whether empty selection is allowed.
 void removeActionListener(java.awt.event.ActionListener listener)
          Removes a registered action listener.
 void removeDateSelectionListener(DateSelectionListener listener)
          Removes a specified date selection listener.
 void setActionCommand(java.lang.String command)
          Specifies the name of the action command that is used when an action event is created.
 void setDateSelectionModel(DateSelectionModel model)
          Specifies a new selection model for this component.
 void setEmptySelectionAllowed(boolean allowed)
          Specifies whether the model supports empty date selections that is no date can be selected at one time.
 void setLocale(java.util.Locale locale)
          Specifies a new locale to be used by this component.
 void setSelectedDate(java.util.Date date)
          Specifies the currently date selected by this component.
 void setTimeZone(java.util.TimeZone zone)
          Specifies the time zone for this component.
 void setUI(DateUI ui)
          Sets the L&F object that renders this component.
 void updateUI()
          Notification from the UIManager that the L&F has changed.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, 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
 

Field Detail

dateSelectionModel

protected DateSelectionModel dateSelectionModel
The selection model used by this component to select one or more dates.


dateSelectionModelListener

protected DateSelectionListener dateSelectionModelListener
Listener that takes date selection listener events from the model and fires them further away as events generated by this component.


actionCommand

protected java.lang.String actionCommand
The name of the action command used when an action event is fired by this component.


locale

protected java.util.Locale locale

calendar

protected java.util.Calendar calendar

timeZone

protected java.util.TimeZone timeZone
The dates handled by a date component are always from a certain timezone.


selectNoneAction

public static final java.lang.String selectNoneAction
Name of the action to unselect all selected dates.

See Also:
Constant Field Values

selectTodayAction

public static final java.lang.String selectTodayAction
Name of the action to unselect all selected dates.

See Also:
Constant Field Values

selectFirstDayAction

public static final java.lang.String selectFirstDayAction
Name of the action to select the first selectable day in a month.

See Also:
Constant Field Values

selectLastDayAction

public static final java.lang.String selectLastDayAction
Name of the action to select the last selectable day in a month.

See Also:
Constant Field Values

selectNextDayAction

public static final java.lang.String selectNextDayAction
Name of the action to select the next selectable day in a month.

See Also:
Constant Field Values

selectPreviousDayAction

public static final java.lang.String selectPreviousDayAction
Name of the action to select the previous selectable day in a month.

See Also:
Constant Field Values

selectSameDayNextWeekAction

public static final java.lang.String selectSameDayNextWeekAction
Name of the action to select the same day of week, next week.

See Also:
Constant Field Values

selectSameDayPreviousWeekAction

public static final java.lang.String selectSameDayPreviousWeekAction
Name of the action to select the same day of week, previous week.

See Also:
Constant Field Values

selectSameDayNextMonthAction

public static final java.lang.String selectSameDayNextMonthAction
Name of the action to select the same day of month, next month.

See Also:
Constant Field Values

selectSameDayPreviousMonthAction

public static final java.lang.String selectSameDayPreviousMonthAction
Name of the action to select the same day of month, previous month.

See Also:
Constant Field Values

selectSameDayNextYearAction

public static final java.lang.String selectSameDayNextYearAction
Name of the action to select the same day of year, next year.

See Also:
Constant Field Values

selectSameDayPreviousYearAction

public static final java.lang.String selectSameDayPreviousYearAction
Name of the action to select the same day of year, previous year.

See Also:
Constant Field Values
Constructor Detail

JDateComponent

public JDateComponent()
Creates a date component with a default date selection model.


JDateComponent

public JDateComponent(DateSelectionModel model)
Creates a date component with a specified date selection model.

Parameters:
model - specified date selection model
Method Detail

getCalendar

public java.util.Calendar getCalendar()
Returns the calendar object used by this component. This method is intended for private use in the component and its UI delegates. It is not recommended to be accessed from outside this API.

Returns:
calendar object used by this component.

getSelectedDate

public java.util.Date getSelectedDate()
Returns the currently selected date.

Returns:
date selected by this component

setSelectedDate

public void setSelectedDate(java.util.Date date)
Specifies the currently date selected by this component.

Parameters:
date - new selected date

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Registers an action listener that is notified when some component specific action is performed.

Parameters:
listener - listener that is registered

removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
Removes a registered action listener.

Parameters:
listener - listener that is removed

setActionCommand

public void setActionCommand(java.lang.String command)
Specifies the name of the action command that is used when an action event is created.

Parameters:
command - name of the action command

getActionCommand

public java.lang.String getActionCommand()
Returns the name of the action command that is used when an action event is created.

Returns:
name of the action command.

fireActionEvent

public void fireActionEvent()

Notifies all registered listeners that an action happened on this component. This method is especially used by the classes from this package and its subpackages and is not intended for public use.

Action events are a complementary mechanism for outside world notification. For instance, date selection events are fired as the date selection model changes but action events are fired when something happens with the component that cannot be notified somehow else. A calendar component would use an action event to notify a double click mouse event on a selectable date.

Because the action events are generic, one can differentiate between them using the name of the command. Each date component defines its own command names. Context information about the event is supplied by the component itself.


getUI

public DateUI getUI()
Returns the L&F object that renders this component.

Returns:
the DateUI object that renders this component

setUI

public void setUI(DateUI ui)
Sets the L&F object that renders this component.

Parameters:
ui - the DateUI L&F object

updateUI

public void updateUI()
Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.

See Also:
JComponent.updateUI()

addDateSelectionListener

public void addDateSelectionListener(DateSelectionListener listener)
Registers a date selection listener that will receive notifications when the date selection model changes.

Parameters:
listener - listener that is registered
See Also:
setDateSelectionModel(DateSelectionModel), removeDateSelectionListener(DateSelectionListener)

removeDateSelectionListener

public void removeDateSelectionListener(DateSelectionListener listener)
Removes a specified date selection listener. It will not receive date selection events anymore.

Parameters:
listener - removed listener

getDateSelectionModel

public DateSelectionModel getDateSelectionModel()
Returns the selection model used by this component.

Returns:
selection model used by this component.

setDateSelectionModel

public void setDateSelectionModel(DateSelectionModel model)
Specifies a new selection model for this component. The selection model is modified to allow only single date selection.

Parameters:
model - new selection model to be used by this component

isEmptySelectionAllowed

public boolean isEmptySelectionAllowed()
Determines whether empty selection is allowed.

Returns:
true if empty selection is allowed or false otherwise.
See Also:
setEmptySelectionAllowed(boolean)

setEmptySelectionAllowed

public void setEmptySelectionAllowed(boolean allowed)
                              throws DateSelectionException
Specifies whether the model supports empty date selections that is no date can be selected at one time. This feature is also known as null date selection. When changing from true to false there must be at least one date selected because otherwise the model would be in an inconsistent state. If that does not happen, the operation fails throwing an exception.

Parameters:
allowed - true if empty selection is allowed or false otherwise
Throws:
DateSelectionException - exception thrown when the model is set to not allow empty selections but it does not contain any selected date.

getLocale

public java.util.Locale getLocale()
Returns the locale used by this component.

Returns:
locale used by this component.
See Also:
setLocale(Locale)

setLocale

public void setLocale(java.util.Locale locale)
Specifies a new locale to be used by this component. The locale influences the date format, month names, week days names, first day of week.

Parameters:
locale - creates a specific configuration for this component

fireDisabledDatesChanged

protected void fireDisabledDatesChanged(DateSelectionEvent evt)

fireDateSelectionChanged

protected void fireDateSelectionChanged(DateSelectionEvent evt)

fireSelectionModeChanged

protected void fireSelectionModeChanged(DateSelectionEvent evt)

fireEmptySelectionAllowedChanged

protected void fireEmptySelectionAllowedChanged(DateSelectionEvent evt)

fireDisabledDateSelectionAttempted

protected void fireDisabledDateSelectionAttempted(DateSelectionEvent evt)

getTimeZone

public java.util.TimeZone getTimeZone()
Returns the time zone used by this component.

Returns:
time zone used by this component.
See Also:
setTimeZone(TimeZone)

setTimeZone

public void setTimeZone(java.util.TimeZone zone)

Specifies the time zone for this component. This parameter is very important if you need to work with dates from another time zone than the default one. By default, the system's default time zone is used.

For instance, if your application is run by users across different time zones and they all work with GMT dates, then you should configure a date component to use the GMT time zone. If you don't do this, the component will use the system time zone which means local dates, not GMT.

Parameters:
zone - new time zone for this component

JDatePicker v4.3

Visit www.jdatepicker.com for further information or send us your suggestions.

Copyright © 2003-2007 Stand By Soft Ltd. All Rights Reserved.