Package com.portal.pfc.ui.datetime
Class DateTimeSelector
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.portal.pfc.ui.datetime.DateTimeSelector
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,PropertyChangeListener
,Serializable
,EventListener
,Accessible
A control which allows the user to enter/change a date and time. The date/time can
be entered into the textfield manually, or it can be selected by popping
up a small minical and analog clock.
Note that this uses a JPopupMenu to display the popups, and there
are known clipping bugs with JPopupMenu instances in modal dialogs.
Note: Any changes done to this class might also need to be copied to
DateSelector and TimeSelector
- Author:
- Nathan Brizzee
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JAnalogClock
protected DateChanger
protected JPopupMenu
protected JButton
protected JTextField
protected JPanel
protected MiniCal
protected boolean
protected JPanel
protected TimeChanger
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
ConstructorsConstructorDescriptionCreates a new DateTimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField.DateTimeSelector
(boolean showTime) Creates a new DateTimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField.DateTimeSelector
(boolean showTime, boolean timeOptional) Creates a new DateTimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a change listener to the textfieldGets the TextField's background colorRetrieves the clock background colorReturns the date only format which is shown when the "Specify time of day" checkbox deselectedRetrieves the current date represented by this component.Gets the TextField's Foreground colorint
getHour()
Gets the hour displayed by the clockRetrieves the hour hand colorint
Retrieves the Hour offset valueRetrieves the hours dot colorRetrieves the minute hand colorint
Gets the minutes displayed by the clockRetrieves the Minutes dot colorint
Retrieves the Minute offset valueRetrieves the date pattern used to render the date into the textfieldRetrieves the second hand colorint
Gets the seconds displayed by the clockint
Retrieves the Seconds offset valueRetrieves the color representing the user selected dateboolean
Indicates if the tooltip is displayed or not.getText()
Retrieves the contents of the date/time textfield.Retrieves the color representing "today"void
Provides a way to force the pop-up to hideboolean
Returns true if component is editableboolean
returns true if time is optional else falseboolean
Returns whether "Specify Time of Day" option selected or not.void
Repaints the componentvoid
Watch for user selection date changes from the AnalogClock component or the minical componentvoid
Removes a change listener from the textboxvoid
Override requestFocus to pass it on to the actual text fieldvoid
void
setAccessibleParent
(Accessible parent) void
setBackground
(Color bg) Sets the TextField's background colorvoid
Change the background color of the clock.void
setDateOnlyPattern
(String dateOnlyPattern) Sets the date only format which is shown when the "Specify time of day" checkbox deselectedvoid
setDateTime
(Date d) Establishes the current date and time represented by this componentvoid
setEditable
(boolean editable) Set editability of componentvoid
setEnabled
(boolean b) Enables/disables the subcomponents that comprise the main componentvoid
setForeground
(Color fc) Sets the TextField's foreground colorvoid
setHour
(int value) Sets the hour to be displayed by the clockvoid
Change the hour hand color of the clock.void
setHourOffset
(int value) Changes the number of hours to offset the clock by.void
Change the hours dot color of the clock.void
Change the minute hand color of the clock.void
setMinutes
(int value) Sets the minutes to be displayed by the clockvoid
Change the Minutes dot color of the clock.void
setMinutesOffset
(int value) Changes the number of minutes to offset the clock by.void
setPattern
(String p) void
Change the second hand color of the clock.void
setSeconds
(int value) Sets the seconds to be displayed by the clockvoid
setSecondsOffset
(int value) Changes the number of Seconds to offset the clock by.void
Change the color representing the user selected date.void
setShowPatternTip
(boolean b) Turns on/off the tooltip displaying the current date pattern.void
Sets the contents of the date/time textfield.void
setTimeOptional
(boolean timeOptional) Sets whether the time is optional or notvoid
setTimeSpecified
(boolean timeSpecified) This will selects or deselects the "Specify Time of Day" checkbox based on the the boolean value passedvoid
Change the color representing "today".Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, 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, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, 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, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
mDatetimeTF
-
mDateTimePopupInvoker
-
mDateTimePopup
-
mAnalogClock
-
mMiniCal
-
mNormalizeYear
protected boolean mNormalizeYear -
mTimeChanger
-
mDateChanger
-
mLeftPanel
-
mRightPanel
-
-
Constructor Details
-
DateTimeSelector
public DateTimeSelector()Creates a new DateTimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField. Selecting the icon will display a calendar "month" and an analog clock in a popup menu. -
DateTimeSelector
public DateTimeSelector(boolean showTime) Creates a new DateTimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField. Selecting the icon will display a calendar "month" in a popup menu.- Parameters:
showDate
- determines if today's date is displayed in the textfield initially. If showDate is false, the textfield is initially blank and the tooltip (containing the date pattern) is turned on.
-
DateTimeSelector
public DateTimeSelector(boolean showTime, boolean timeOptional) Creates a new DateTimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField. Selecting the icon will display a calendar "month" in a popup menu.- Parameters:
timeOptional
- determines whether the time part is optional. if timeOptional is true, a check box by name "Specify time of day" will be displayed.showDate
- determines if today's date is displayed in the textfield initially. If showDate is false, the textfield is initially blank and the tooltip (containing the date pattern) is turned on.
-
-
Method Details
-
hidePopup
public void hidePopup()Provides a way to force the pop-up to hide -
requestFocus
public void requestFocus()Override requestFocus to pass it on to the actual text field- Overrides:
requestFocus
in classJComponent
-
getBackground
Gets the TextField's background color- Overrides:
getBackground
in classComponent
- Returns:
- the current background color
-
setBackground
Sets the TextField's background color- Overrides:
setBackground
in classJComponent
- Parameters:
bg
- Color to set background to
-
getForeground
Gets the TextField's Foreground color- Overrides:
getForeground
in classComponent
- Returns:
- the current foreground color
-
setForeground
Sets the TextField's foreground color- Overrides:
setForeground
in classJComponent
- Parameters:
FC
- color to set the foreground to
-
addChangeListener
Adds a change listener to the textfield- Parameters:
l
- changeListener to add
-
removeChangeListener
Removes a change listener from the textbox- Parameters:
l
- changeListener to remove
-
paintComponent
Repaints the component- Overrides:
paintComponent
in classJComponent
- Parameters:
g
- - graphics to paint on
-
setShowPatternTip
public void setShowPatternTip(boolean b) Turns on/off the tooltip displaying the current date pattern. This is potentially useful if the user doesn't know what format to manually enter a date string.- Parameters:
b
- the flag dictating if the tooltip should be on or off
-
setEditable
public void setEditable(boolean editable) Set editability of component- Parameters:
editable
- New editable flag
-
isEditable
public boolean isEditable()Returns true if component is editable- Returns:
- true if component is editable
-
getShowPatternTip
public boolean getShowPatternTip()Indicates if the tooltip is displayed or not.- Returns:
- the state of the tooltip containing the current date pattern
-
getPattern
Retrieves the date pattern used to render the date into the textfield- Returns:
- the date format pattern
-
setPattern
-
setTimeOptional
public void setTimeOptional(boolean timeOptional) Sets whether the time is optional or not- Parameters:
timeOptional
- determines whether the time part is optional. if timeOptional is true, a check box by name "Specify time of day" will be displayed. User can make time option by deselecting the check box.
-
isTimeOptional
public boolean isTimeOptional()returns true if time is optional else false- Returns:
- true if time is optional else false
-
isTimeSpecified
public boolean isTimeSpecified()Returns whether "Specify Time of Day" option selected or not. If the check box is selected time can be specified else not.- Returns:
- true means time is not specifield, false means time is speicifed.
-
setTimeSpecified
public void setTimeSpecified(boolean timeSpecified) This will selects or deselects the "Specify Time of Day" checkbox based on the the boolean value passed- Parameters:
timeSpecified
- true means selects "Specify time of day" checkbox, false will deselects
-
getDateOnlyPattern
Returns the date only format which is shown when the "Specify time of day" checkbox deselected- Returns:
- date only format
-
setDateOnlyPattern
Sets the date only format which is shown when the "Specify time of day" checkbox deselected- Parameters:
dateOnlyPattern
- date only format
-
getText
Retrieves the contents of the date/time textfield.- Returns:
- the contents of the date/time textfield
-
setText
Sets the contents of the date/time textfield.- Parameters:
dateText
- the string to set in the date/time textfield - Does not change the date displayed. To change the date/time that is displayed in the pop-up/ use setDateTime- See Also:
-
getDateTime
Retrieves the current date represented by this component. If the date manually entered by the user is not a valid date, an IllegalArgumentException is thrown.- Returns:
- the current date
- Throws:
IllegalArgumentException
-
setDateTime
Establishes the current date and time represented by this component- Parameters:
d
- the new date
-
setHour
public void setHour(int value) Sets the hour to be displayed by the clock- Parameters:
value
- the number representing the current hour
-
getHour
public int getHour()Gets the hour displayed by the clock- Returns:
- the current hour displayed by the clock
-
setMinutes
public void setMinutes(int value) Sets the minutes to be displayed by the clock- Parameters:
value
- the number representing the current minutes
-
getMinutes
public int getMinutes()Gets the minutes displayed by the clock- Returns:
- the current minutes displayed by the clock
-
setSeconds
public void setSeconds(int value) Sets the seconds to be displayed by the clock- Parameters:
value
- the number representing the current seconds
-
getSeconds
public int getSeconds()Gets the seconds displayed by the clock- Returns:
- the current seconds displayed by the clock
-
setClockBackgroundColor
Change the background color of the clock. Default color is light gray- Parameters:
c
- the new background color
-
getClockBackgroundColor
Retrieves the clock background color- Returns:
- the background color.
-
setHourHandColor
Change the hour hand color of the clock. Default color is blue.- Parameters:
c
- the new hour hand color
-
getHourHandColor
Retrieves the hour hand color- Returns:
- the hour hand color.
-
setMinuteHandColor
Change the minute hand color of the clock. Default color is blue.- Parameters:
c
- the new minute hand color
-
getMinuteHandColor
Retrieves the minute hand color- Returns:
- the minute hand color.
-
setSecondHandColor
Change the second hand color of the clock. Default color is black.- Parameters:
c
- the new second hand color
-
getSecondHandColor
Retrieves the second hand color- Returns:
- the second hand color.
-
setHoursDotColor
Change the hours dot color of the clock. Default color is red.- Parameters:
c
- the new hours dot color
-
getHoursDotColor
Retrieves the hours dot color- Returns:
- the hours dot color.
-
setMinutesDotColor
Change the Minutes dot color of the clock. Default color is white.- Parameters:
c
- the new Minutes dot color
-
getMinutesDotColor
Retrieves the Minutes dot color- Returns:
- the Minutes dot color.
-
setHourOffset
public void setHourOffset(int value) Changes the number of hours to offset the clock by. Default is 0- Parameters:
value
- the number of hours to offset the clock by. Valid values are +24 to -24.
-
getHourOffset
public int getHourOffset()Retrieves the Hour offset value- Returns:
- the Hour offset value
-
setMinutesOffset
public void setMinutesOffset(int value) Changes the number of minutes to offset the clock by. Default is 0- Parameters:
value
- the number of minutes to offset the clock by. Valid values are +60 to -60.
-
getMinutesOffset
public int getMinutesOffset()Retrieves the Minute offset value- Returns:
- the Minute offset value
-
setSecondsOffset
public void setSecondsOffset(int value) Changes the number of Seconds to offset the clock by. Default is 0- Parameters:
value
- the number of Seconds to offset the clock by. Valid values are +60 to -60.
-
getSecondsOffset
public int getSecondsOffset()Retrieves the Seconds offset value- Returns:
- the Seconds offset value
-
setTodayColor
Change the color representing "today". Today is red by default- Parameters:
c
- the new today color
-
getTodayColor
Retrieves the color representing "today"- Returns:
- the color representing "today"
-
setSelectedDateColor
Change the color representing the user selected date. This is yellow by default.- Parameters:
c
- the new current date color
-
getSelectedDateColor
Retrieves the color representing the user selected date- Returns:
- the color representing the user selected date
-
setEnabled
public void setEnabled(boolean b) Enables/disables the subcomponents that comprise the main component- Overrides:
setEnabled
in classJComponent
- Parameters:
b
- If true, the component is enabled; otherwise it is disabled.
-
propertyChange
Watch for user selection date changes from the AnalogClock component or the minical component- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
e
- property change event
-
setAccessibleName
-
setAccessibleParent
-