Class Date_selector_panel

  • All Implemented Interfaces:
    Date_selector, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    public class Date_selector_panel
    extends javax.swing.JPanel
    implements Date_selector
    A calendar-display/date-selection widget. Here's what it looks like:
    "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 Calendar 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 underlying
     Calendar, which should change with Locale as appropriate.
     </DD>
     </DL>
     
    @see com.holub.ui.Date_selector @see com.holub.ui.Date_selector_dialog @see com.holub.ui.Navigable_date_selector
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  Date_selector_panel.DayButton  
      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.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 java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor Description
      Date_selector_panel()
      Create a Date_selector representing the current date.
      Date_selector_panel​(java.util.Date initialDate)
      Create a Date_selector_panel for an arbitrary date.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addActionListener​(java.awt.event.ActionListener l)
      Add a listener that's notified when the user scrolls the selector or picks a date.
      void addNotify()
      Create a navigation button with an image appropriate to the caption.
      protected javax.swing.JPanel createWeekdayPanel()  
      int get​(int field)
      Works just like Calendar.get(int)
      java.util.Date get_current_date()
      Returns the currently displayed Date.
      java.util.Date get_selected_date()
      Returns the Date selected by the user or null if the window was closed without selecting a date.
      javax.swing.JComponent getComponent()  
      java.lang.String[] getDayNames​(java.util.Locale locale)  
      java.lang.String[] getMonthNames​(java.util.Locale locale)
      Returns an array of locale-specific short month names
      javax.swing.border.Border getSelectedBorder()  
      java.awt.Color getStyleBackground​(int style)  
      java.awt.Color getStyleForeground​(int style)  
      void localeChanged​(java.util.Locale newLocale)
      Components that use Date_selector_panel need to call this when locale changes.
      protected void rebuildCalendar()  
      void removeActionListener​(java.awt.event.ActionListener l)
      Remove a listener.
      void roll​(int field, boolean up)
      Works just like Calendar.roll(int, boolean).
      void set_selected_date​(java.util.Date d)  
      void setEnabled​(boolean b)  
      void setFont​(java.awt.Font font)  
      void setForeground​(java.awt.Color fg)  
      void setSelectedBorder​(javax.swing.border.Border b)  
      void setStyleBackground​(int style, java.awt.Color color)  
      void setStyleForeground​(int style, java.awt.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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Date_selector_panel

        public Date_selector_panel()
        Create a Date_selector representing the current date.
      • Date_selector_panel

        public Date_selector_panel​(java.util.Date initialDate)
        Create a Date_selector_panel for an arbitrary date.
        Parameters:
        initialDate - Calendar will display this date. The specified date is highlighted as "today".
    • Method Detail

      • getStyleBackground

        public java.awt.Color getStyleBackground​(int style)
      • setStyleBackground

        public void setStyleBackground​(int style,
                                       java.awt.Color color)
      • getStyleForeground

        public java.awt.Color getStyleForeground​(int style)
      • setStyleForeground

        public void setStyleForeground​(int style,
                                       java.awt.Color foreground)
      • setSelectedBorder

        public void setSelectedBorder​(javax.swing.border.Border b)
      • getSelectedBorder

        public javax.swing.border.Border getSelectedBorder()
      • localeChanged

        public void localeChanged​(java.util.Locale newLocale)
        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

        public void setFont​(java.awt.Font font)
        Overrides:
        setFont in class javax.swing.JComponent
      • setEnabled

        public void setEnabled​(boolean b)
        Overrides:
        setEnabled in class javax.swing.JComponent
      • setForeground

        public void setForeground​(java.awt.Color fg)
        Overrides:
        setForeground in class javax.swing.JComponent
      • createWeekdayPanel

        protected javax.swing.JPanel createWeekdayPanel()
      • addActionListener

        public void addActionListener​(java.awt.event.ActionListener l)
        Add a listener that's notified when the user scrolls the selector or picks a date.
        Specified by:
        addActionListener in interface Date_selector
        See Also:
        Date_selector
      • addNotify

        public void addNotify()
        Create a navigation button with an image appropriate to the caption. The caption 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 class javax.swing.JComponent
      • get_selected_date

        public java.util.Date get_selected_date()
        Returns the Date 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 interface Date_selector
      • get_current_date

        public java.util.Date get_current_date()
        Returns the currently displayed Date.
        Specified by:
        get_current_date in interface Date_selector
      • roll

        public void roll​(int field,
                         boolean up)
        Works just like Calendar.roll(int, boolean).
        Specified by:
        roll in interface Date_selector
      • get

        public int get​(int field)
        Works just like Calendar.get(int)
        Specified by:
        get in interface Date_selector
      • getMonthNames

        public java.lang.String[] getMonthNames​(java.util.Locale locale)
        Returns an array of locale-specific short month names
      • getDayNames

        public java.lang.String[] getDayNames​(java.util.Locale locale)