org.tentackle.ui
Class DateFormField
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
org.tentackle.ui.FormField
org.tentackle.ui.DateFormField
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants, FormComponent, FormFieldComponent
public class DateFormField
- extends FormField
FormField to edit a Date object.
The date can be entered in the specified format or as a shortcut.
The following shortcuts are defined:
- "5/29/": expands to May 29 of the current year (midnight).
- "0529": dto.
- "052906": if the year is 4-digits in length the century will be added
which is closest to the current date, i.e.:
- "5/29/99": will be expanded to "05/29/1999" and _not_ "05/29/2099".
- "7:00": today at 7:00am
Furthermore, the date can determined in relation
to a reference date by certain commands. By default,
the reference date is the current time:
- "/": current date
- ":": current time
- "+3d": today 0:00:00 plus 3 days
- "-2y": today 2 years ago.
- "17": the "smallest" unit of the field will be set to 17.
For dates this means the 17th of the current month.
If the smalles unit are minutes, it means current hour 17 minutes.
- "+14": same as above but the value will be added (or subtracted if negative)
to (from) the current time. For date fields, for example, this is again shorter than "+14d".
- "4m": the unit according to the letter following the number will be set _and_
the next "smaller" unit set to its minimum.
In this example, the time (if it is a time field) will be set to 4 minutes and 0 seconds.
Likewise, "6y" would mean "January 1st, 2006". Consequently, "8h" is an even shorter
way to express "today at 8am" than "8:00".
The units are the same as described in SimpleDateFormat with some
minor differences:
- "y" or "Y": year(s)
- "M": month(s). In date fields without minutes a lowercase "m" works as well.
- "w or W": week(s) or calendar week. For example: "-2w" means "two weeks ago"
but "30w" means the first day of week 30.
- "d oder D": day(s)
- "h oder H": hour(s). Notice that "-24h" means "24 hours ago" and is not
the dame as "-1d" which means "yesterday 0am".
- "m": minute(s)
- "s oder S": second(s)
The shortcuts (except the units) are locale dependent. In German, for example, the
shortcuts are as follows:
- "29.5.": ergänzt zum 29.Mai des aktuellen Jahres 0 Uhr.
- "2905": dto.
- "290506": dto. falls die Jahreszahl 4-stellig erwartet wird. Dabei wird
das Jahrhundert so ergänzt, dass es möglichst nah am aktuellen Datum liegt, d.h.:
- "29.5.99": wird auf "29.05.1999" erweitert und nicht auf "29.05.2099".
- "7:00": heute um 7:00 Uhr
- Author:
- harald
- See Also:
- Serialized Form
| Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
|
Constructor Summary |
DateFormField()
Creates an empty DateFormField with the default document model
and minimum width.
|
DateFormField(Document doc,
int columns)
Creates an empty DateFormField.
Notice: setting doc != null requires a doc derived from FormFieldDocument. |
DateFormField(int columns)
Creates an empty DateFormField with the default document model.
|
DateFormField(String pattern)
Creates an empty DateFormField with the default document model,
mininum width and a given format.
|
|
Method Summary |
String |
doFormat(Object date)
Does the formatting of the given object.
Renders the object and returns the string. |
Date |
getDate()
Gets the SQL-Date. |
String |
getFormat()
Gets the format string. |
Date |
getFormValue()
Retrieves the value from this component.
The method is used to update the data if the view has changed because
the user edited it. |
Date |
getReferenceDate()
Gets the reference date for the input shortcuts. |
Time |
getTime()
Gets the SQL-Time. |
Timestamp |
getTimestamp()
Gets the SQL-Timestamp. |
boolean |
isLenient()
Returns the lenient flag for the date format |
void |
setFormat(String pattern)
Sets the format string.
The format string is used to format the view of the data. |
void |
setFormValue(Object date)
Sets a value in this component.
The method is used to update the view if the data has changed. |
void |
setLenient(boolean lenient)
Sets the "lenient" flag for the date format. |
void |
setReferenceDate(Date referenceDate)
Sets the reference date for the input shortcuts. |
| Methods inherited from class org.tentackle.ui.FormField |
addValueListener, clearText, createDefaultModel, doActionPerformed, downRight, fireValueChanged, fireValueEntered, getAdjust, getConvert, getConverter, getErrorOffset, getFiller, getHelpURL, getInvalidChars, getMaxColumns, getParentWindow, getText, getToolTipText, getValidChars, getVerticalAlignment, invalidateParentInfo, isAutoNext, isAutoSelect, isAutoUpdate, isCaretLeft, isCaretRight, isCellEditorUsage, isChangeable, isEmpty, isEraseFirst, isFireRunning, isFormTraversable, isHonourChangeable, isInhibitAutoSelect, isOverwrite, isStartEditLeftmost, isValueChanged, prepareFocusLost, processFocusEvent, processKeyBinding, removeValueListener, requestFocusLater, saveValue, setAdjust, setAutoNext, setAutoSelect, setAutoUpdate, setCaretLeft, setCaretRight, setCellEditorUsage, setChangeable, setColumns, setConvert, setConverter, setEraseFirst, setFiller, setFireRunning, setFormTraversable, setFormWrapWindow, setHelpURL, setHonourChangeable, setInhibitAutoSelect, setInvalidChars, setMaxColumns, setOverwrite, setStartEditLeftmost, setText, setValidChars, setVerticalAlignment, showHelp, transferFocus, transferFocusBackward, triggerValueChanged, upLeft, wasFocusGainedFromTransfer, wasFocusGainedFromTransferBackward, wasTransferFocus, wasTransferFocusBackward, wasTransferFocusByEnter |
| Methods inherited from class javax.swing.JTextField |
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setDocument, setFont, setHorizontalAlignment, setScrollOffset |
| Methods inherited from class javax.swing.text.JTextComponent |
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write |
| 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, 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, transferFocusDownCycle, validate, validateTree |
| Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, 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, 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, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocusUpCycle |
DateFormField
public DateFormField(Document doc,
int columns)
- Creates an empty DateFormField.
Notice: setting doc != null requires a doc derived from FormFieldDocument.
- Parameters:
doc - the document model, null = defaultcolumns - the number of columns, 0 = minimum width
DateFormField
public DateFormField(int columns)
- Creates an empty DateFormField with the default document model.
- Parameters:
columns - the number of columns, 0 = minimum width
DateFormField
public DateFormField()
- Creates an empty DateFormField with the default document model
and minimum width.
DateFormField
public DateFormField(String pattern)
- Creates an empty DateFormField with the default document model,
mininum width and a given format.
- Parameters:
pattern - the date format string
setFormValue
public void setFormValue(Object date)
- Description copied from interface:
FormComponent
- Sets a value in this component.
The method is used to update the view if the data has changed.
- Parameters:
date - is the object to set
doFormat
public String doFormat(Object date)
- Description copied from interface:
FormFieldComponent
- Does the formatting of the given object.
Renders the object and returns the string.
- Parameters:
date - the object
- Returns:
- the formatted object as a string
getFormValue
public Date getFormValue()
- Description copied from interface:
FormComponent
- Retrieves the value from this component.
The method is used to update the data if the view has changed because
the user edited it.
- Returns:
- the date, null if field is empty
getDate
public Date getDate()
- Gets the SQL-Date.
- Returns:
- the java.sql.Date, null if field is empty
getTimestamp
public Timestamp getTimestamp()
- Gets the SQL-Timestamp.
- Returns:
- the java.sql.Timestamp, null if field is empty
getTime
public Time getTime()
- Gets the SQL-Time.
- Returns:
- the java.sql.Time, null if field is empty
setFormat
public void setFormat(String pattern)
- Description copied from interface:
FormFieldComponent
- Sets the format string.
The format string is used to format the view of the data.
- Parameters:
pattern - the format string- See Also:
SimpleDateFormat
getFormat
public String getFormat()
- Description copied from interface:
FormFieldComponent
- Gets the format string.
- Returns:
- the format string
setLenient
public void setLenient(boolean lenient)
- Sets the "lenient" flag for the date format.
- Parameters:
lenient - true if lenient- See Also:
SimpleDateFormat
isLenient
public boolean isLenient()
- Returns the lenient flag for the date format
- Returns:
- true if lenient
getReferenceDate
public Date getReferenceDate()
- Gets the reference date for the input shortcuts.
- Returns:
- the reference date for input shortcuts, null = now (default)
setReferenceDate
public void setReferenceDate(Date referenceDate)
- Sets the reference date for the input shortcuts.
- Parameters:
referenceDate - reference date for input shortcuts, null = now
Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de