Class DateTimeSelector

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible

public class DateTimeSelector extends JPanel implements PropertyChangeListener
A control which allows the user to enter/change a date and time. The date/time can be entered into the textfield manually, or it can be selected by popping up a small minical and analog clock. Note that this uses a JPopupMenu to display the popups, 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 DateSelector and TimeSelector
Author:
Nathan Brizzee
See Also:
  • Field Details

    • mDatetimeTF

      protected JTextField mDatetimeTF
    • mDateTimePopupInvoker

      protected JButton mDateTimePopupInvoker
    • mDateTimePopup

      protected JPopupMenu mDateTimePopup
    • mAnalogClock

      protected JAnalogClock mAnalogClock
    • mMiniCal

      protected MiniCal mMiniCal
    • mNormalizeYear

      protected boolean mNormalizeYear
    • mTimeChanger

      protected TimeChanger mTimeChanger
    • mDateChanger

      protected DateChanger mDateChanger
    • mLeftPanel

      protected JPanel mLeftPanel
    • mRightPanel

      protected JPanel mRightPanel
  • Constructor Details

    • DateTimeSelector

      public DateTimeSelector()
      Creates a new DateTimeSelector instance comprised of a JTextField and an selectable icon to the right of the JTextField. Selecting the icon will display a calendar "month" and an analog clock in a popup menu.
    • DateTimeSelector

      public DateTimeSelector(boolean showTime)
      Creates a new DateTimeSelector 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.
    • DateTimeSelector

      public DateTimeSelector(boolean showTime, boolean timeOptional)
      Creates a new DateTimeSelector 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:
      timeOptional - determines whether the time part is optional. if timeOptional is true, a check box by name "Specify time of day" will be displayed.
      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
    • getBackground

      public Color getBackground()
      Gets the TextField's background color
      Overrides:
      getBackground in class Component
      Returns:
      the current background color
    • setBackground

      public void setBackground(Color bg)
      Sets the TextField's background color
      Overrides:
      setBackground in class JComponent
      Parameters:
      bg - Color to set background to
    • getForeground

      public Color getForeground()
      Gets the TextField's Foreground color
      Overrides:
      getForeground in class Component
      Returns:
      the current foreground color
    • setForeground

      public void setForeground(Color fc)
      Sets the TextField's foreground color
      Overrides:
      setForeground in class JComponent
      Parameters:
      FC - color to set the foreground to
    • addChangeListener

      public void addChangeListener(ChangeListener l)
      Adds a change listener to the textfield
      Parameters:
      l - changeListener to add
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
      Removes a change listener from the textbox
      Parameters:
      l - changeListener to remove
    • paintComponent

      public void paintComponent(Graphics g)
      Repaints the component
      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - - graphics to paint on
    • 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

      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)
    • setTimeOptional

      public void setTimeOptional(boolean timeOptional)
      Sets whether the time is optional or not
      Parameters:
      timeOptional - determines whether the time part is optional. if timeOptional is true, a check box by name "Specify time of day" will be displayed. User can make time option by deselecting the check box.
    • isTimeOptional

      public boolean isTimeOptional()
      returns true if time is optional else false
      Returns:
      true if time is optional else false
    • isTimeSpecified

      public boolean isTimeSpecified()
      Returns whether "Specify Time of Day" option selected or not. If the check box is selected time can be specified else not.
      Returns:
      true means time is not specifield, false means time is speicifed.
    • setTimeSpecified

      public void setTimeSpecified(boolean timeSpecified)
      This will selects or deselects the "Specify Time of Day" checkbox based on the the boolean value passed
      Parameters:
      timeSpecified - true means selects "Specify time of day" checkbox, false will deselects
    • getDateOnlyPattern

      public String getDateOnlyPattern()
      Returns the date only format which is shown when the "Specify time of day" checkbox deselected
      Returns:
      date only format
    • setDateOnlyPattern

      public void setDateOnlyPattern(String dateOnlyPattern)
      Sets the date only format which is shown when the "Specify time of day" checkbox deselected
      Parameters:
      dateOnlyPattern - date only format
    • getText

      public String getText()
      Retrieves the contents of the date/time textfield.
      Returns:
      the contents of the date/time textfield
    • setText

      public void setText(String dateText)
      Sets the contents of the date/time textfield.
      Parameters:
      dateText - the string to set in the date/time textfield - Does not change the date displayed. To change the date/time that is displayed in the pop-up/ use setDateTime
      See Also:
      • invalid reference
        com.portal.pfc.ui.DateTimeSelector#setDateTime
    • getDateTime

      public Date getDateTime() 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
    • setDateTime

      public void setDateTime(Date d)
      Establishes the current date and time represented by this component
      Parameters:
      d - the new date
    • setHour

      public void setHour(int value)
      Sets the hour to be displayed by the clock
      Parameters:
      value - the number representing the current hour
    • getHour

      public int getHour()
      Gets the hour displayed by the clock
      Returns:
      the current hour displayed by the clock
    • setMinutes

      public void setMinutes(int value)
      Sets the minutes to be displayed by the clock
      Parameters:
      value - the number representing the current minutes
    • getMinutes

      public int getMinutes()
      Gets the minutes displayed by the clock
      Returns:
      the current minutes displayed by the clock
    • setSeconds

      public void setSeconds(int value)
      Sets the seconds to be displayed by the clock
      Parameters:
      value - the number representing the current seconds
    • getSeconds

      public int getSeconds()
      Gets the seconds displayed by the clock
      Returns:
      the current seconds displayed by the clock
    • setClockBackgroundColor

      public void setClockBackgroundColor(Color c)
      Change the background color of the clock. Default color is light gray
      Parameters:
      c - the new background color
    • getClockBackgroundColor

      public Color getClockBackgroundColor()
      Retrieves the clock background color
      Returns:
      the background color.
    • setHourHandColor

      public void setHourHandColor(Color c)
      Change the hour hand color of the clock. Default color is blue.
      Parameters:
      c - the new hour hand color
    • getHourHandColor

      public Color getHourHandColor()
      Retrieves the hour hand color
      Returns:
      the hour hand color.
    • setMinuteHandColor

      public void setMinuteHandColor(Color c)
      Change the minute hand color of the clock. Default color is blue.
      Parameters:
      c - the new minute hand color
    • getMinuteHandColor

      public Color getMinuteHandColor()
      Retrieves the minute hand color
      Returns:
      the minute hand color.
    • setSecondHandColor

      public void setSecondHandColor(Color c)
      Change the second hand color of the clock. Default color is black.
      Parameters:
      c - the new second hand color
    • getSecondHandColor

      public Color getSecondHandColor()
      Retrieves the second hand color
      Returns:
      the second hand color.
    • setHoursDotColor

      public void setHoursDotColor(Color c)
      Change the hours dot color of the clock. Default color is red.
      Parameters:
      c - the new hours dot color
    • getHoursDotColor

      public Color getHoursDotColor()
      Retrieves the hours dot color
      Returns:
      the hours dot color.
    • setMinutesDotColor

      public void setMinutesDotColor(Color c)
      Change the Minutes dot color of the clock. Default color is white.
      Parameters:
      c - the new Minutes dot color
    • getMinutesDotColor

      public Color getMinutesDotColor()
      Retrieves the Minutes dot color
      Returns:
      the Minutes dot color.
    • setHourOffset

      public void setHourOffset(int value)
      Changes the number of hours to offset the clock by. Default is 0
      Parameters:
      value - the number of hours to offset the clock by. Valid values are +24 to -24.
    • getHourOffset

      public int getHourOffset()
      Retrieves the Hour offset value
      Returns:
      the Hour offset value
    • setMinutesOffset

      public void setMinutesOffset(int value)
      Changes the number of minutes to offset the clock by. Default is 0
      Parameters:
      value - the number of minutes to offset the clock by. Valid values are +60 to -60.
    • getMinutesOffset

      public int getMinutesOffset()
      Retrieves the Minute offset value
      Returns:
      the Minute offset value
    • setSecondsOffset

      public void setSecondsOffset(int value)
      Changes the number of Seconds to offset the clock by. Default is 0
      Parameters:
      value - the number of Seconds to offset the clock by. Valid values are +60 to -60.
    • getSecondsOffset

      public int getSecondsOffset()
      Retrieves the Seconds offset value
      Returns:
      the Seconds offset value
    • 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)
      Watch for user selection date changes from the AnalogClock component or the minical component
      Specified by:
      propertyChange in interface PropertyChangeListener
      Parameters:
      e - property change event
    • setAccessibleName

      public void setAccessibleName(String s)
    • setAccessibleParent

      public void setAccessibleParent(Accessible parent)