java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.inductiveautomation.ignition.client.util.gui.date_selector.Date_selector_panel
All Implemented Interfaces:
Date_selector, ImageObserver, MenuContainer, Serializable, Accessible

public class Date_selector_panel extends 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:
  • Constructor Details

    • Date_selector_panel

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

      public Date_selector_panel(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 Details

    • getStyleBackground

      public Color getStyleBackground(int style)
    • setStyleBackground

      public void setStyleBackground(int style, Color color)
    • getStyleForeground

      public Color getStyleForeground(int style)
    • setStyleForeground

      public void setStyleForeground(int style, Color foreground)
    • setSelectedBorder

      public void setSelectedBorder(Border b)
    • getSelectedBorder

      public Border getSelectedBorder()
    • localeChanged

      public void localeChanged(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(Font font)
      Overrides:
      setFont in class JComponent
    • setEnabled

      public void setEnabled(boolean b)
      Overrides:
      setEnabled in class JComponent
    • setForeground

      public void setForeground(Color fg)
      Overrides:
      setForeground in class JComponent
    • createWeekdayPanel

      protected JPanel createWeekdayPanel()
    • addActionListener

      public void addActionListener(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:
    • removeActionListener

      public void removeActionListener(ActionListener l)
      Remove a listener.
      Specified by:
      removeActionListener in interface Date_selector
      See Also:
    • 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 JComponent
    • set_selected_date

      public void set_selected_date(Date d)
      Specified by:
      set_selected_date in interface Date_selector
    • get_selected_date

      public 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 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)
      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 static String[] getMonthNames(Locale locale)
      Returns an array of locale-specific short month names
    • getDayNames

      public static String[] getDayNames(Locale locale)
    • getComponent

      public JComponent getComponent()
      Specified by:
      getComponent in interface Date_selector
    • getInnerSelector

      public Date_selector getInnerSelector()
      Specified by:
      getInnerSelector in interface Date_selector
      Returns:
      A reference to any 'inner' selector inside this Date_selector implementation. May return this.