Class Date_selector_panel
- All Implemented Interfaces:
Date_selector
,ImageObserver
,MenuContainer
,Serializable
,Accessible
"Today" is highlighted. Select a date by clicking on it. The background is transparent by default — it's grey here because the underlying window is grey.![]()
This "raw" date selector can be "decorated" in several ways
to make it more useful. First, you can add a navigation bar to the bottom to advances the calendar by one month
(single arrow) or one year (double arrow) forwards (right-pointing arrow) or backwards (left-pointing arrow). "Today"
is highlighted. Navigation bars are specified using a Gang-of-Four "Decorator" object that wraps the raw
Date_selector_panel
Both the wrapper and the underlying panel implement the Date_selector
interface, so can be use used interchangeably. The following code creates the date selector at right.
Date_selector selector = new Date_selector_panel(); selector = new Navigable_date_selector(selector);
The same thing can be accomplished with a convenience constructor that creates the wrapped Date_selector_panel for you:
Date_selector selector = new Navigable_date_selector();
The other augmentation of interest is a title that
shows the month name and year that's displayed. (there's an example at right). Use the same decoration strategy as
before to add the title:
Date_selector selector = new Date_selector_panel(); selector = new Navigable_date_selector(selector); selector = new Titled_date_selector(selector);
You can leave out the navigation bar by omitting the second line of the foregoing code. Again, a convenience constructor is provided to create a titled date selector (without the navigation bar) as follows:
Date_selector selector = new Titled_date_selector();
The final variant is the lightweight popup dialog shown at
right. It can be dragged around by the title bar (though dragging can be disabled) and closed by clicking on the
"close" icon on the upper right. As before, use a decorator to manufacture a dialog:
Date_selector selector = new Date_selector_panel(); selector = new Navigable_date_selector(selector); // add navigation selector = new Date_selector_dialog(selector);
Note that you don't need a title because one is supplied for you in the dialog-box title bar. Also as before, a convenience constructor to create a navigable dialog box like the one at right:
Date_selector = new Date_selector_dialog(); <pre> All the earlier examples create a calendar for the current month. Several methods are provided, below, to change the date in your program. For the most part, they work like similar methods of the@see com.holub.ui.Date_selector @see com.holub.ui.Date_selector_dialog @see com.holub.ui.Navigable_date_selectorCalendar
class. <DL> <DT> <b>Known Problems</b> <DD> The week layout (S M T W Th F Sa Su) is the default layout for the underlyingCalendar
, which should change with Locale as appropriate. </DD> </DL>
- See Also:
-
Nested Class Summary
Nested ClassesNested 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
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 com.inductiveautomation.ignition.client.util.gui.date_selector.Date_selector
CHANGE_ACTION, COMMIT_ACTION, SELECT_ACTION
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a Date_selector representing the current date.Date_selector_panel
(Date initialDate) Create a Date_selector_panel for an arbitrary date. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a listener that's notified when the user scrolls the selector or picks a date.void
Create a navigation button with an image appropriate to the caption.protected JPanel
int
get
(int field) Works just likeCalendar.get(int)
Returns the currently displayedDate
.Returns theDate
selected by the user or null if the window was closed without selecting a date.static String[]
getDayNames
(Locale locale) static String[]
getMonthNames
(Locale locale) Returns an array of locale-specific short month namesgetStyleBackground
(int style) getStyleForeground
(int style) void
localeChanged
(Locale newLocale) Components that use Date_selector_panel need to call this when locale changes.protected void
void
Remove a listener.void
roll
(int field, boolean up) Works just likeCalendar.roll(int, boolean)
.void
void
setEnabled
(boolean b) void
void
setForeground
(Color fg) void
void
setStyleBackground
(int style, Color color) void
setStyleForeground
(int style, Color foreground) Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, 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, getBackground, 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
-
Constructor Details
-
Date_selector_panel
public Date_selector_panel()Create a Date_selector representing the current date. -
Date_selector_panel
Create a Date_selector_panel for an arbitrary date.- Parameters:
initialDate
- Calendar will display this date. The specified date is highlighted as "today".
-
-
Method Details
-
getStyleBackground
-
setStyleBackground
-
getStyleForeground
-
setStyleForeground
-
setSelectedBorder
-
getSelectedBorder
-
localeChanged
Components that use Date_selector_panel need to call this when locale changes.Why not just implement LocaleListener, you may ask? Because this class is paying absolutely no attention to locale changes when it's done that way.
-
rebuildCalendar
protected void rebuildCalendar() -
setFont
- Overrides:
setFont
in classJComponent
-
setEnabled
public void setEnabled(boolean b) - Overrides:
setEnabled
in classJComponent
-
setForeground
- Overrides:
setForeground
in classJComponent
-
createWeekdayPanel
-
addActionListener
Add a listener that's notified when the user scrolls the selector or picks a date.- Specified by:
addActionListener
in interfaceDate_selector
- See Also:
-
removeActionListener
Remove a listener.- Specified by:
removeActionListener
in interfaceDate_selector
- See Also:
-
addNotify
public void addNotify()Create a navigation button with an image appropriate to the caption. Thecaption
argument is used as the button's "action command." This method is public only because it has to be. (It overrides a public method.) Pretend it's not here.- Overrides:
addNotify
in classJComponent
-
set_selected_date
- Specified by:
set_selected_date
in interfaceDate_selector
-
get_selected_date
Returns theDate
selected by the user or null if the window was closed without selecting a date. The returned Date has hours, minutes, and seconds values of 0.- Specified by:
get_selected_date
in interfaceDate_selector
-
get_current_date
Returns the currently displayedDate
.- Specified by:
get_current_date
in interfaceDate_selector
-
roll
public void roll(int field, boolean up) Works just likeCalendar.roll(int, boolean)
.- Specified by:
roll
in interfaceDate_selector
-
get
public int get(int field) Works just likeCalendar.get(int)
- Specified by:
get
in interfaceDate_selector
-
getMonthNames
Returns an array of locale-specific short month names -
getDayNames
-
getComponent
- Specified by:
getComponent
in interfaceDate_selector
-
getInnerSelector
- Specified by:
getInnerSelector
in interfaceDate_selector
- Returns:
- A reference to any 'inner' selector inside this
Date_selector
implementation. May returnthis
.
-