Package com.portal.ctrl
Class DateSelector
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
com.portal.ctrl.DateSelector
- All Implemented Interfaces:
FocusListener
,ImageObserver
,MenuContainer
,PropertyChangeListener
,Serializable
,EventListener
A control which allows the user to enter/change a date. The date can
be entered into the textfield manually, or it can be selected by popping
up a small calendar window which displays dates one month at a time. The
calendar popup will always display the current date in a specified color
(default red) and the user selected date (if different from the current
date) in a different color (default yellow).
Note that this uses a JPopupMenu to display the popup calendar, and there are known clipping bugs with JPopupMenu instances in modal dialogs.
Note that this uses a JPopupMenu to display the popup calendar, and there are known clipping bugs with JPopupMenu instances in modal dialogs.
- Author:
- Kapono Carter
- 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 JPopupMenu
protected JTextField
protected MiniCal
protected boolean
protected JButton
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 DateSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField.DateSelector
(boolean showDate) Creates a new DateSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField. -
Method Summary
Modifier and TypeMethodDescriptionvoid
static Point
computePopupBounds
(int px, int py, int pw, int ph, Component comp) Computes the location on the screen for a Popup taking into account the edges of the screen.void
Invoked when a component gains the keyboard focus.void
Invoked when a component loses the keyboard focus.getDate()
Retrieves the current date represented by this component.Retrieves the date pattern used to render the date into the textfieldRetrieves the color representing the user selected dateboolean
Indicates if the tooltip is displayed or not.getText()
Retrieves the contents of the date textfield.Retrieves the color representing "today"void
Provides a way to force the pop-up to hideboolean
Returns true if component is editablevoid
void
void
void
Override requestFocus to pass it on to the actual text fieldvoid
setBackground
(Color bg) void
Establishes the current date represented by this componentvoid
setEditable
(boolean editable) Set editability of componentvoid
setEnabled
(boolean b) Enables/disables the subcomponents that comprise the main componentvoid
void
setPattern
(String p) void
Change the color representing the user selected date.void
setShowPatternTip
(boolean b) Turns on/off the tooltip displaying the current date pattern.void
Change the color representing "today".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, 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, setForeground, 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, 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, getForeground, 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
-
dateTF
-
popupInvoker
-
calPopup
-
minical
-
normalizeYear
protected boolean normalizeYear
-
-
Constructor Details
-
DateSelector
public DateSelector()Creates a new DateSelector 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. -
DateSelector
public DateSelector(boolean showDate) Creates a new DateSelector 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.
-
-
Method Details
-
hidePopup
public void hidePopup()Provides a way to force the pop-up to hide -
computePopupBounds
Computes the location on the screen for a Popup taking into account the edges of the screen.- Parameters:
px
- : x coordinate - relative to the Component (usually 0)py
- : y coordinate - The height of the control (usually : comp.getBounds().height)pw
- : width - width of the popup (usually Popup.getSize().width)ph
- : height - height of the popup (usually Popup.getSize().height)comp
- : The component the pop-up belongs to. Like a JTextBox.- Returns:
- Point : The location to set the popup at. With this point, call : Popup.show(comp, Point.x, Point.y);
-
requestFocus
public void requestFocus()Override requestFocus to pass it on to the actual text field- Overrides:
requestFocus
in classJComponent
-
setLayout
-
getBackground
- Overrides:
getBackground
in classComponent
-
setBackground
- Overrides:
setBackground
in classJComponent
-
addChangeListener
-
removeChangeListener
-
paintComponent
- Overrides:
paintComponent
in classJComponent
-
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
-
getText
Retrieves the contents of the date textfield.- Returns:
- the contents of the date textfield
-
getDate
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
-
setDate
Establishes the current date represented by this component- Parameters:
d
- the new date
-
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
- Specified by:
propertyChange
in interfacePropertyChangeListener
-
focusGained
Invoked when a component gains the keyboard focus.- Specified by:
focusGained
in interfaceFocusListener
- Parameters:
event
- The focus event
-
focusLost
Invoked when a component loses the keyboard focus.- Specified by:
focusLost
in interfaceFocusListener
- Parameters:
event
- The focus event
-