Package org.jfree.ui

Class DateChooserPanel

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

public class DateChooserPanel extends JPanel implements ActionListener
A panel that allows the user to select a date.
See Also:
  • Field Details

    • chosenDate

      private Calendar chosenDate
      The date selected in the panel.
    • chosenDateButtonColor

      private Color chosenDateButtonColor
      The color for the selected date.
    • chosenMonthButtonColor

      private Color chosenMonthButtonColor
      The color for dates in the current month.
    • chosenOtherButtonColor

      private Color chosenOtherButtonColor
      The color for dates that are visible, but not in the current month.
    • firstDayOfWeek

      private int firstDayOfWeek
      The first day-of-the-week.
    • yearSelectionRange

      private int yearSelectionRange
      The range used for selecting years.
    • dateFont

      private Font dateFont
      The font used to display the date.
    • monthSelector

      private JComboBox monthSelector
      A combo for selecting the month.
    • yearSelector

      private JComboBox yearSelector
      A combo for selecting the year.
    • todayButton

      private JButton todayButton
      A button for selecting today's date.
    • buttons

      private JButton[] buttons
      An array of buttons used to display the days-of-the-month.
    • refreshing

      private boolean refreshing
      A flag that indicates whether or not we are currently refreshing the buttons.
    • WEEK_DAYS

      private int[] WEEK_DAYS
      The ordered set of all seven days of a week, beginning with the 'firstDayOfWeek'.
  • Constructor Details

    • DateChooserPanel

      public DateChooserPanel()
      Constructs a new date chooser panel, using today's date as the initial selection.
    • DateChooserPanel

      public DateChooserPanel(Calendar calendar, boolean controlPanel)
      Constructs a new date chooser panel.
      Parameters:
      calendar - the calendar controlling the date.
      controlPanel - a flag that indicates whether or not the 'today' button should appear on the panel.
  • Method Details

    • setDate

      public void setDate(Date theDate)
      Sets the date chosen in the panel.
      Parameters:
      theDate - the new date.
    • getDate

      public Date getDate()
      Returns the date selected in the panel.
      Returns:
      the selected date.
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Handles action-events from the date panel.
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      e - information about the event that occurred.
    • getCalendarPanel

      private JPanel getCalendarPanel()
      Returns a panel of buttons, each button representing a day in the month. This is a sub-component of the DatePanel.
      Returns:
      the panel.
    • getButtonColor

      private Color getButtonColor(Calendar theDate)
      Returns the button color according to the specified date.
      Parameters:
      theDate - the date.
      Returns:
      the color.
    • equalDates

      private boolean equalDates(Calendar c1, Calendar c2)
      Returns true if the two dates are equal (time of day is ignored).
      Parameters:
      c1 - the first date.
      c2 - the second date.
      Returns:
      boolean.
    • getFirstVisibleDate

      private Calendar getFirstVisibleDate()
      Returns the first date that is visible in the grid. This should always be in the month preceding the month of the selected date.
      Returns:
      the date.
    • getFirstDayOfWeek

      private int getFirstDayOfWeek()
      Returns the first day of the week (controls the labels in the date panel).
      Returns:
      the first day of the week.
    • refreshButtons

      private void refreshButtons()
      Update the button labels and colors to reflect date selection.
    • refreshYearSelector

      private void refreshYearSelector()
      Changes the contents of the year selection JComboBox to reflect the chosen date and the year range.
    • getYears

      private Integer[] getYears(int chosenYear)
      Returns a vector of years preceding and following the specified year. The number of years preceding and following is determined by the yearSelectionRange attribute.
      Parameters:
      chosenYear - the selected year.
      Returns:
      a vector of years.
    • constructSelectionPanel

      private JPanel constructSelectionPanel()
      Constructs a panel containing two JComboBoxes (for the month and year) and a button (to reset the date to TODAY).
      Returns:
      the panel.
    • constructControlPanel

      private JPanel constructControlPanel()
      Returns a panel that appears at the bottom of the calendar panel - contains a button for selecting today's date.
      Returns:
      the panel.
    • getChosenDateButtonColor

      public Color getChosenDateButtonColor()
      Returns the color for the currently selected date.
      Returns:
      a color.
    • setChosenDateButtonColor

      public void setChosenDateButtonColor(Color chosenDateButtonColor)
      Redefines the color for the currently selected date.
      Parameters:
      chosenDateButtonColor - the new color
    • getChosenMonthButtonColor

      public Color getChosenMonthButtonColor()
      Returns the color for the buttons representing the current month.
      Returns:
      the color for the current month.
    • setChosenMonthButtonColor

      public void setChosenMonthButtonColor(Color chosenMonthButtonColor)
      Defines the color for the buttons representing the current month.
      Parameters:
      chosenMonthButtonColor - the color for the current month.
    • getChosenOtherButtonColor

      public Color getChosenOtherButtonColor()
      Returns the color for the buttons representing the other months.
      Returns:
      a color.
    • setChosenOtherButtonColor

      public void setChosenOtherButtonColor(Color chosenOtherButtonColor)
      Redefines the color for the buttons representing the other months.
      Parameters:
      chosenOtherButtonColor - a color.
    • getYearSelectionRange

      public int getYearSelectionRange()
      Returns the range of years available for selection (defaults to 20).
      Returns:
      The range.
    • setYearSelectionRange

      public void setYearSelectionRange(int yearSelectionRange)
      Sets the range of years available for selection.
      Parameters:
      yearSelectionRange - the range.