Java Date Picker v3.2

com.standbysoft.component.date.swing
Class JDateEditComponent

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

public abstract class JDateEditComponent
extends JDateComponent

JDateEditComponent is the base class for all date editing components. By default, dates are edited using an internal editor that forces users to type correct dates according to a standard or custom date format.

The component can also accept free text entries that are converted to dates using a date parser. This makes it possible to plug special parsers that can convert shortcut strings like 'today' to an appropriate date. If you are using the structured date editor (freeText is false), then you can enable or disable the autoCentury property. If set to true, short years like 80 will be converted to long ones like 1980.

An important part of this component's API is reserved for date validation. You can test if a date is valid, execute your own action when the date is invalid and ask for a certain edit to be commited. For a date to be valid, it must be accepted by the date selection model. A date edit component can be configured to indicate what must happen at validation time. Such properties are:

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class com.standbysoft.component.date.swing.JDateComponent
JDateComponent.DateAction, JDateComponent.RollDateAction, JDateComponent.SelectFirstDayAction, JDateComponent.SelectLastDayAction, JDateComponent.SelectNoneAction, JDateComponent.SelectTodayAction
 
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  boolean autoRestore
           
protected  boolean autoValidate
           
protected  boolean beepOnError
           
protected  java.lang.String customDateFormat
           
protected  int dateFormat
           
protected  DateModel dateModel
           
protected  DateListener dateModelListener
           
protected  DateParser dateParser
           
protected  java.lang.String emptySelectionText
           
protected  boolean freeText
           
protected  java.lang.String text
           
 
Fields inherited from class com.standbysoft.component.date.swing.JDateComponent
actionCommand, dateSelectionModel, dateSelectionModelListener, locale, selectFirstDayAction, selectLastDayAction, selectNextDayAction, selectNoneAction, selectPreviousDayAction, selectSameDayNextMonthAction, selectSameDayNextWeekAction, selectSameDayNextYearAction, selectSameDayPreviousMonthAction, selectSameDayPreviousWeekAction, selectSameDayPreviousYearAction, selectTodayAction
 
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
JDateEditComponent()
          Creates a default date field that has the today date selected.
JDateEditComponent(DateSelectionModel model)
           
 
Method Summary
 void addDateListener(DateListener listener)
          Registers a date listener that will receive notifications when the date model changes.
 void commitEdit()
          Makes the currently edited date to be the selected date but only if it is valid.
protected  void fireDateChanged(DateEvent evt)
           
protected  void fireDateFieldChanged(DateEvent evt)
           
protected  void fireDateFieldCleared(DateEvent evt)
           
 int getAutoCenturyYear()
          Detrmines the year used to build the long year when short years are used.
 java.lang.String getCustomDateFormat()
          Returns the custom date format used to display and edit the dates.
 int getDateFormat()
          Returns the format used to display the selected date.
 DateModel getDateModel()
          Returns the date model used by this component.
 DateParser getDateParser()
          Determines the date parser that converts free text entries into dates.
 java.lang.String getEmptySelectionText()
          Returns the text displayed by this component when there is no date selected.
 java.lang.String getText()
           
protected  void invalidEdit()
          Invoked on an invalid date input.
 boolean isAutoCentury()
          Determines whether century is automatically added to the year field if its value is less than 100.
 boolean isAutoRestore()
          Determines whether an invalid date should be automatically restored to the last valid date.
 boolean isAutoValidate()
          Determines whether the date edited by this component should be validated when focus is lost.
 boolean isBeepOnError()
          Determines whether a beep will sound if the typed date is not valid, at validation time.
 boolean isEditValid()
          Determines whether the current edited date is valid.
 boolean isFreeText()
          Determines whether free text date entries are allowed.
 void removeDateListener(DateListener listener)
          Removes a date listener registered on this component.
 void setAutoCentury(boolean enabled)
          Specifies whether century is automatically added to the year field if its value is less than 100.
 void setAutoCenturyYear(int year)
          Specifies the year used to build the long year when short years are used.
 void setAutoRestore(boolean enabled)
          Specifies whether an invalid date should be automatically restored to the last valid date.
 void setAutoValidate(boolean enabled)
          Specifies whether the temporary represented date is validated when the component loses focus.
 void setBeepOnError(boolean enabled)
          Specifies whether a beep will sound if the typed date is not valid, at validation time.
 void setCustomDateFormat(java.lang.String pattern)
          Specifies a custom date pattern that uses the Date Format Pattern Syntax to display and edit dates.
 void setDateFormat(int format)
          Specifies how the date displayed by this component is formated.
 void setDateModel(DateModel model)
          Specifies a new date model for this component.
 void setDateParser(DateParser parser)
          Specifies the date parser that will be used to convert free text entries into dates.
 void setDateSelectionModel(DateSelectionModel model)
          Specifies a new selection model for this component.
 void setEmptySelectionText(java.lang.String text)
          Specifies the text displayed by this component when there is no date selected.
 void setFreeText(boolean enabled)
          Specifies whether free text date entries are allowed.
 void setText(java.lang.String text)
           
 
Methods inherited from class com.standbysoft.component.date.swing.JDateComponent
addActionListener, addDateSelectionListener, fireActionEvent, fireDateSelectionChanged, fireDisabledDatesChanged, fireEmptySelectionAllowedChanged, fireSelectionModeChanged, getActionCommand, getDateSelectionModel, getLocale, getSelectedDate, getUI, isEmptySelectionAllowed, removeActionListener, removeDateSelectionListener, setActionCommand, setEmptySelectionAllowed, setLocale, setSelectedDate, setUI, updateUI
 
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

dateFormat

protected int dateFormat

customDateFormat

protected java.lang.String customDateFormat

emptySelectionText

protected java.lang.String emptySelectionText

autoRestore

protected boolean autoRestore

autoValidate

protected boolean autoValidate

beepOnError

protected boolean beepOnError

dateModel

protected DateModel dateModel

dateModelListener

protected DateListener dateModelListener

dateParser

protected DateParser dateParser

freeText

protected boolean freeText

text

protected java.lang.String text
Constructor Detail

JDateEditComponent

public JDateEditComponent()
Creates a default date field that has the today date selected. Null dates are allowed by default.


JDateEditComponent

public JDateEditComponent(DateSelectionModel model)
Method Detail

setDateModel

public void setDateModel(DateModel model)
Specifies a new date model for this component. The date model manages date field information.

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

getDateModel

public DateModel getDateModel()
Returns the date model used by this component.

Returns:
date model used by this component.
See Also:
setDateModel(DateModel)

addDateListener

public void addDateListener(DateListener listener)
Registers a date listener that will receive notifications when the date model changes.

Parameters:
listener - listener that is registered
See Also:
setDateModel(DateModel), removeDateListener(DateListener)

removeDateListener

public void removeDateListener(DateListener listener)
Removes a date listener registered on this component.

Parameters:
listener - listener that is removed

setAutoCentury

public void setAutoCentury(boolean enabled)
Specifies whether century is automatically added to the year field if its value is less than 100.

Parameters:
enabled - true if century is automatically added; false otherwise
See Also:
DateModel.setAutoCentury(boolean)

isAutoCentury

public boolean isAutoCentury()
Determines whether century is automatically added to the year field if its value is less than 100.

Returns:
true if century is automatically added; false otherwise.
See Also:
DateModel.isAutoCentury()

setAutoCenturyYear

public void setAutoCenturyYear(int year)
Specifies the year used to build the long year when short years are used.

Parameters:
year - year used to build the long year when short years are used
See Also:
DateModel.setAutoCenturyYear(int)

getAutoCenturyYear

public int getAutoCenturyYear()
Detrmines the year used to build the long year when short years are used.

Returns:
year used to build the long year when short years are used.
See Also:
DateModel.getAutoCenturyYear()

getEmptySelectionText

public java.lang.String getEmptySelectionText()
Returns the text displayed by this component when there is no date selected.

Returns:
the text displayed by this component when there is no date selected.
See Also:
setEmptySelectionText(String)

setEmptySelectionText

public void setEmptySelectionText(java.lang.String text)
Specifies the text displayed by this component when there is no date selected.

Parameters:
text - text displayed by this component when there is no date selected

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.

Overrides:
setDateSelectionModel in class JDateComponent
Parameters:
model - new selection model to be used by this component

getDateFormat

public int getDateFormat()
Returns the format used to display the selected date.

Returns:
the format used to display the selected date.
See Also:
setDateFormat(int)

setDateFormat

public void setDateFormat(int format)
Specifies how the date displayed by this component is formated. For complex date formatting you can use a custom date format that can also specify time fields.

Parameters:
format - format used to display the selected date. Valid values are DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG or DateFormat.FULL.
See Also:
setCustomDateFormat(String)

getCustomDateFormat

public java.lang.String getCustomDateFormat()
Returns the custom date format used to display and edit the dates.

Returns:
custom date format used to display and edit the dates, or null if none is used.
See Also:
setCustomDateFormat(String)

setCustomDateFormat

public void setCustomDateFormat(java.lang.String pattern)
Specifies a custom date pattern that uses the Date Format Pattern Syntax to display and edit dates. It replaces the current date format. For instance if you want the date picker to format dates like "12:08 PM" you must use "h:mm a" as custom date pattern.

Parameters:
pattern - new date pattern that will be used to format dates for display or editing, or null if you do not want to use a custom format
See Also:
setDateFormat(int)

setText

public void setText(java.lang.String text)

getText

public java.lang.String getText()

setDateParser

public void setDateParser(DateParser parser)
Specifies the date parser that will be used to convert free text entries into dates. The date parser is used only if free text is enabled.

Parameters:
parser - date parser that will be used to convert free text entries into dates
See Also:
setFreeText(boolean)

getDateParser

public DateParser getDateParser()
Determines the date parser that converts free text entries into dates.

Returns:
date parser that converts free text entries into dates.
See Also:
setDateParser(DateParser)

setFreeText

public void setFreeText(boolean enabled)
Specifies whether free text date entries are allowed. When free text entries are enabled, the current date parser will be used to parse the specified text to convert it into a date.

Parameters:
enabled - true if free text is enabled; false otherwise
See Also:
setDateParser(DateParser)

isFreeText

public boolean isFreeText()
Determines whether free text date entries are allowed.

Returns:
true if free text date entries are allowed; false otherwise.
See Also:
setFreeText(boolean)

setAutoValidate

public void setAutoValidate(boolean enabled)
Specifies whether the temporary represented date is validated when the component loses focus. If not validated, the represented date is not the same with that selected by this component.

Parameters:
enabled - true if validation should occur when focus is lost; false otherwise
See Also:
JDateComponent.getSelectedDate()

isAutoValidate

public boolean isAutoValidate()
Determines whether the date edited by this component should be validated when focus is lost.

Returns:
true if validation should occur when focus is lost; false otherwise.
See Also:
setAutoValidate(boolean)

setBeepOnError

public void setBeepOnError(boolean enabled)
Specifies whether a beep will sound if the typed date is not valid, at validation time.

Parameters:
enabled - true if the beep will sound on invalid entries; false otherwise
See Also:
invalidEdit()

isBeepOnError

public boolean isBeepOnError()
Determines whether a beep will sound if the typed date is not valid, at validation time.

Returns:
true if the beep will sound on invalid entries; false otherwise.
See Also:
setBeepOnError(boolean)

invalidEdit

protected void invalidEdit()
Invoked on an invalid date input. It beeps if beep on error is enabled. You can override this to implement your own handling scheme.

See Also:
setBeepOnError(boolean)

isEditValid

public boolean isEditValid()

Determines whether the current edited date is valid. A valid date is a date that can be selected by the date selection model.

Returns:
true if the date is accepted by the date selection model; false otherwise.
See Also:
DateSelectionModel.isDateSelectable(Date)

commitEdit

public void commitEdit()
Makes the currently edited date to be the selected date but only if it is valid.

See Also:
isEditValid()

setAutoRestore

public void setAutoRestore(boolean enabled)
Specifies whether an invalid date should be automatically restored to the last valid date.

Parameters:
enabled - true if at validation time, an invalid date should be automatically restored to the last valid date; false otherwise
See Also:
setAutoValidate(boolean)

isAutoRestore

public boolean isAutoRestore()
Determines whether an invalid date should be automatically restored to the last valid date.

Returns:
true if at validation time, an invalid date should be automatically restored to the last valid date; false otherwise.
See Also:
setAutoRestore(boolean)

fireDateFieldChanged

protected void fireDateFieldChanged(DateEvent evt)

fireDateFieldCleared

protected void fireDateFieldCleared(DateEvent evt)

fireDateChanged

protected void fireDateChanged(DateEvent evt)

Java Date Picker v3.2

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

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