Class DateSelector

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible
Direct Known Subclasses:
PIADateField

public class DateSelector extends JPanel implements PropertyChangeListener
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: Any changes done to this class might also need to be copied to DateTimeSelector and TimeSelector
Author:
Kapono Carter
See Also:
  • Field Details

    • dateTF

      protected JTextField dateTF
    • popupInvoker

      protected JButton popupInvoker
    • calPopup

      protected JPopupMenu calPopup
    • minical

      protected MiniCal 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
    • requestFocus

      public void requestFocus()
      Override requestFocus to pass it on to the actual text field
      Overrides:
      requestFocus in class JComponent
    • setLayout

      public void setLayout(LayoutManager lm)
      Overrides:
      setLayout in class Container
    • getBackground

      public Color getBackground()
      Overrides:
      getBackground in class Component
    • setBackground

      public void setBackground(Color bg)
      Overrides:
      setBackground in class JComponent
    • addChangeListener

      public void addChangeListener(ChangeListener l)
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
    • paintComponent

      public void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • 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
    • setTextEditable

      public void setTextEditable(boolean b)
      Set editability of text field that displays date
      Parameters:
      b - If true, the date text field is editable; otherwise it is disabled.
    • 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

      public String getPattern()
      Retrieves the date pattern used to render the date into the textfield
      Returns:
      the date format pattern
    • setPattern

      public void setPattern(String p)
    • getText

      public String getText()
      Retrieves the contents of the date textfield.
      Returns:
      the contents of the date textfield
    • getDate

      public Date getDate() throws IllegalArgumentException
      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

      public void setDate(Date d)
      Establishes the current date represented by this component
      Parameters:
      d - the new date
    • setTodayColor

      public void setTodayColor(Color c)
      Change the color representing "today". Today is red by default
      Parameters:
      c - the new today color
    • getTodayColor

      public Color getTodayColor()
      Retrieves the color representing "today"
      Returns:
      the color representing "today"
    • setSelectedDateColor

      public void setSelectedDateColor(Color c)
      Change the color representing the user selected date. This is yellow by default.
      Parameters:
      c - the new current date color
    • getSelectedDateColor

      public 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 class JComponent
      Parameters:
      b - If true, the component is enabled; otherwise it is disabled.
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Specified by:
      propertyChange in interface PropertyChangeListener
    • setAccessibleName

      public void setAccessibleName(String s)
    • setAccessibleParent

      public void setAccessibleParent(Accessible parent)