Package com.portal.pfc.ui.datetime
Class TimeSelector
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
com.portal.pfc.ui.datetime.TimeSelector
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,PropertyChangeListener
,Serializable
,EventListener
A control which allows the user to enter/change a time. The time can
be entered into the textfield manually, or it can be selected by popping
up a small analog clock.
Note that this uses a JPopupMenu to display the popup analog clock, 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 DateTimeSelector
- Author:
- Nathan Brizzee
- See Also:
-
Nested Class Summary
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 TimeChanger
protected JPopupMenu
protected JButton
protected JTextField
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 TimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField.TimeSelector
(boolean showTime) Creates a new TimeSelector 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 colorGets 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 time into the textfieldRetrieves the second hand colorint
Gets the seconds displayed by the clockint
Retrieves the Seconds offset valueboolean
Indicates if the tooltip is displayed or not.getText()
Retrieves the contents of the date textfield.getTime()
Retrieves the current time represented by this component.void
Provides a way to force the pop-up to hideboolean
Returns true if component is editablevoid
Repaints the componentvoid
Watch for user selection date changesmTimePopup from the analogClock componentvoid
Removes a change listener from the textboxvoid
Override requestFocus to pass it on to the actual text fieldvoid
setBackground
(Color bg) Sets the TextField's background colorvoid
Change the background color of the clock.void
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
setShowPatternTip
(boolean b) Turns on/off the tooltip displaying the current date pattern.void
Establishes the current time represented by this componentMethods 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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, updateUI
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, getAccessibleContext, 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
-
mTimeTF
-
mTimePopupInvoker
-
mTimePopup
-
mAnalogClock
-
mChanger
-
-
Constructor Details
-
TimeSelector
public TimeSelector()Creates a new TimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField. Selecting the icon will display an analog clock in a popup menu. -
TimeSelector
public TimeSelector(boolean showTime) Creates a new TimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField. Selecting the icon will display an analog clock in a popup menu.- Parameters:
showTime
- determines if today's time is displayed in the textfield initially. If showTime is false, the textfield is initially blank and the tooltip (containing the time 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 time pattern
-
getPattern
Retrieves the date pattern used to render the time into the textfield- Returns:
- the date format pattern
-
setPattern
-
getText
Retrieves the contents of the date textfield.- Returns:
- the contents of the date textfield
-
getTime
Retrieves the current time represented by this component. If the date manually entered by the user is not a valid time, an IllegalArgumentException is thrown.- Returns:
- the current time
- Throws:
IllegalArgumentException
-
setTime
Establishes the current 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
-
setBackgroundColor
Change the background color of the clock. Default color is light gray- Parameters:
c
- the new background color
-
getBackgroundColor
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
-
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 changesmTimePopup from the analogClock component- Specified by:
propertyChange
in interfacePropertyChangeListener
- Parameters:
e
- property change event
-