Class JTextFieldDateEditor
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.text.JTextComponent
javax.swing.JTextField
javax.swing.JFormattedTextField
edu.wisc.ssec.mcidasv.data.dateChooser.JTextFieldDateEditor
- All Implemented Interfaces:
IDateEditor,ActionListener,FocusListener,ImageObserver,MenuContainer,Serializable,EventListener,Accessible,CaretListener,Scrollable,SwingConstants
public class JTextFieldDateEditor
extends JFormattedTextField
implements IDateEditor, CaretListener, FocusListener, ActionListener
JTextFieldDateEditor is the default editor used by JDateChooser. It is a
formatted text field, that colors valid dates green/black and invalid dates
red. The date format pattern and mask can be set manually. If not set, the
MEDIUM pattern of a SimpleDateFormat with regards to the actual locale is
used.
- Version:
- $LastChangedRevision: 97 $, $LastChangedDate: 2006-05-24 17:30:41 +0200 (Mi, 24 Mai 2006) $
- Author:
- Kai Toedter
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JFormattedTextField
JFormattedTextField.AbstractFormatter, JFormattedTextField.AbstractFormatterFactoryNested classes/interfaces inherited from class javax.swing.JTextField
JTextField.AccessibleJTextFieldNested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBindingNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Calendarprotected Colorprotected Dateprotected SimpleDateFormatprotected Stringprotected DateUtilprivate intprivate booleanprivate booleanprivate static final org.slf4j.Loggerprotected MaskFormatterprotected Stringprivate intprivate intprotected charprivate intprivate static final longFields inherited from class javax.swing.JFormattedTextField
COMMIT, COMMIT_OR_REVERT, PERSIST, REVERTFields inherited from class javax.swing.JTextField
notifyActionFields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields 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
ConstructorsConstructorDescriptionJTextFieldDateEditor(boolean showMask, String datePattern, String maskPattern, char placeholder) JTextFieldDateEditor(String datePattern, String maskPattern, char placeholder) -
Method Summary
Modifier and TypeMethodDescriptionvoidValidates the typed date and sets it (only if it is valid).voidcaretUpdate(CaretEvent event) After any user input, the value of the textfield is proofed.private voidcreateMaskFromDatePattern(String datePattern) Creates a mask from a date pattern.voidvoidfocusLost(FocusEvent focusEvent) getDate()Returns the date.Returns tha date format string.Gets the minimum selectable date.Gets the maximum selectable date.Returns the preferred size.Returns the UI component, e.g. the actual JTextField implementing the editor.booleanReturns true, if the mask is visible.static voidCreates a JFrame with a JCalendar inside and can be used for testing.voidSets the date.protected voidSets the date.voidsetDateFormatString(String dateFormatString) Sets the date format string, e.g.voidsetEnabled(boolean b) Enables and disabled the component.voidSets the locale.voidsetMaskVisible(boolean isMaskVisible) Sets the mask visible.voidsetMaxSelectableDate(Date max) Sets the maximum selectable date.voidsetMinSelectableDate(Date min) Sets the minimum selectable date.voidsetSelectableDateRange(Date min, Date max) Sets a valid date range for selectable dates.Methods inherited from class javax.swing.JFormattedTextField
commitEdit, getActions, getFocusLostBehavior, getFormatter, getFormatterFactory, getUIClassID, getValue, invalidEdit, isEditValid, processFocusEvent, processInputMethodEvent, setDocument, setFocusLostBehavior, setFormatter, setFormatterFactory, setValueMethods inherited from class javax.swing.JTextField
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getScrollOffset, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setFont, setHorizontalAlignment, setScrollOffsetMethods 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, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, paste, print, print, print, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, restoreComposedText, saveComposedText, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, setUI, updateUI, viewToModel, viewToModel2D, writeMethods 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, 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, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods 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, validateTreeMethods 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.wisc.ssec.mcidasv.data.dateChooser.IDateEditor
addPropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
-
Field Details
-
logger
-
serialVersionUID
- See Also:
-
date
-
dateFormatter
-
maskFormatter
-
datePattern
-
maskPattern
-
placeholder
-
darkGreen
-
dateUtil
-
isMaskVisible
-
ignoreDatePatternChange
-
hours
-
minutes
-
seconds
-
millis
-
calendar
-
-
Constructor Details
-
JTextFieldDateEditor
public JTextFieldDateEditor() -
JTextFieldDateEditor
-
JTextFieldDateEditor
public JTextFieldDateEditor(boolean showMask, String datePattern, String maskPattern, char placeholder)
-
-
Method Details
-
getDate
Description copied from interface:IDateEditorReturns the date.- Specified by:
getDatein interfaceIDateEditor- Returns:
- the date
-
setDate
Description copied from interface:IDateEditorSets the date. This should be implemented as a bound property, firing the "date" property.- Specified by:
setDatein interfaceIDateEditor- Parameters:
date- the date to set
-
setDate
Sets the date.- Parameters:
date- the datefirePropertyChange- true, if the date property should be fired.
-
setDateFormatString
Description copied from interface:IDateEditorSets the date format string, e.g. "MM/dd/yy". If the date format string is null or invalid, the date format string will be set to the MEDIUM Simple date format of the current locale.- Specified by:
setDateFormatStringin interfaceIDateEditor- Parameters:
dateFormatString- the date format string
-
getDateFormatString
Description copied from interface:IDateEditorReturns tha date format string.- Specified by:
getDateFormatStringin interfaceIDateEditor- Returns:
- the date format string
-
getUiComponent
Description copied from interface:IDateEditorReturns the UI component, e.g. the actual JTextField implementing the editor.- Specified by:
getUiComponentin interfaceIDateEditor- Returns:
- the UI component
-
caretUpdate
After any user input, the value of the textfield is proofed. Depending on being a valid date, the value is colored green or red.- Specified by:
caretUpdatein interfaceCaretListener- Parameters:
event- the caret event
-
focusLost
- Specified by:
focusLostin interfaceFocusListener
-
checkText
-
focusGained
- Specified by:
focusGainedin interfaceFocusListener
-
setLocale
Description copied from interface:IDateEditorSets the locale. Usually this should have impact on the current date format string.- Specified by:
setLocalein interfaceIDateEditor- Overrides:
setLocalein classComponent- Parameters:
locale- the locale to set
-
createMaskFromDatePattern
Creates a mask from a date pattern. This is a very simple (and incomplete) implementation that works only with numbers. A date pattern of "MM/dd/yy" will result in the mask "##/##/##". Probably you want to override this method if it does not fit your needs.- Parameters:
datePattern- the date pattern- Returns:
- the mask
-
isMaskVisible
Returns true, if the mask is visible.- Returns:
- true, if the mask is visible
-
setMaskVisible
Sets the mask visible.- Parameters:
isMaskVisible- true, if the mask should be visible
-
getPreferredSize
Returns the preferred size. If a date pattern is set, it is the size the date pattern would take.- Overrides:
getPreferredSizein classJTextField
-
actionPerformed
Validates the typed date and sets it (only if it is valid).- Specified by:
actionPerformedin interfaceActionListener
-
setEnabled
Enables and disabled the component. It also fixes the background bug 4991597 and sets the background explicitly to a TextField.inactiveBackground.- Specified by:
setEnabledin interfaceIDateEditor- Overrides:
setEnabledin classJComponent- Parameters:
b- true, if the UI component should be enabled.
-
getMaxSelectableDate
Description copied from interface:IDateEditorGets the minimum selectable date.- Specified by:
getMaxSelectableDatein interfaceIDateEditor- Returns:
- the minimum selectable date
-
getMinSelectableDate
Description copied from interface:IDateEditorGets the maximum selectable date.- Specified by:
getMinSelectableDatein interfaceIDateEditor- Returns:
- the maximum selectable date
-
setMaxSelectableDate
Description copied from interface:IDateEditorSets the maximum selectable date.- Specified by:
setMaxSelectableDatein interfaceIDateEditor- Parameters:
max- maximum selectable date
-
setMinSelectableDate
Description copied from interface:IDateEditorSets the minimum selectable date.- Specified by:
setMinSelectableDatein interfaceIDateEditor- Parameters:
min- minimum selectable date
-
setSelectableDateRange
Description copied from interface:IDateEditorSets a valid date range for selectable dates. If max is before min, the default range with no limitation is set.- Specified by:
setSelectableDateRangein interfaceIDateEditor- Parameters:
min- the minimum selectable date or null (then the minimum date should be set to 01\01\0001)max- the maximum selectable date or null (then the maximum date should be set to 01\01\9999)
-
main
Creates a JFrame with a JCalendar inside and can be used for testing.- Parameters:
s- The command line arguments
-