summaryrefslogtreecommitdiff
path: root/libs/FLib/JCalendar/org/freixas
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2009-03-04 18:25:32 +0000
committerPaul Buetow <paul@buetow.org>2009-03-04 18:25:32 +0000
commit6deeb57d62c238d3f152cdef1d782b441c73797a (patch)
treef12600b080dbcdfed825f2a79f58c2d45fda93de /libs/FLib/JCalendar/org/freixas
parent9129838d208c0df7293e5b757661125545cd6df8 (diff)
jcalendar lib
Diffstat (limited to 'libs/FLib/JCalendar/org/freixas')
-rw-r--r--libs/FLib/JCalendar/org/freixas/jcalendar/DateEvent.java76
-rw-r--r--libs/FLib/JCalendar/org/freixas/jcalendar/DateListener.java18
-rw-r--r--libs/FLib/JCalendar/org/freixas/jcalendar/JCalendar.java2675
-rw-r--r--libs/FLib/JCalendar/org/freixas/jcalendar/JCalendarCombo.java2010
4 files changed, 2391 insertions, 2388 deletions
diff --git a/libs/FLib/JCalendar/org/freixas/jcalendar/DateEvent.java b/libs/FLib/JCalendar/org/freixas/jcalendar/DateEvent.java
index dfd4f9f..9058dc4 100644
--- a/libs/FLib/JCalendar/org/freixas/jcalendar/DateEvent.java
+++ b/libs/FLib/JCalendar/org/freixas/jcalendar/DateEvent.java
@@ -24,63 +24,63 @@ import java.util.Calendar;
// All Rights Reserved.
public class DateEvent
- extends EventObject
+ extends EventObject
{
//**********************************************************************
// Private Members
//**********************************************************************
-private Calendar selectedDate;
+ private Calendar selectedDate;
//**********************************************************************
// Constructors
//**********************************************************************
-/**
- * Create a date event.
- *
- * @param source The object on which the event occurred.
- * @param selectedDate The selected date.
- */
-
-public
-DateEvent(
- Object source,
- Calendar selectedDate)
-{
- super(source);
- this.selectedDate = selectedDate;
-}
+ /**
+ * Create a date event.
+ *
+ * @param source The object on which the event occurred.
+ * @param selectedDate The selected date.
+ */
+
+ public
+ DateEvent(
+ Object source,
+ Calendar selectedDate)
+ {
+ super(source);
+ this.selectedDate = selectedDate;
+ }
//**********************************************************************
// Public
//**********************************************************************
-/**
- * Return the selected date.
- *
- * @return The selected date.
- */
+ /**
+ * Return the selected date.
+ *
+ * @return The selected date.
+ */
-public Calendar
-getSelectedDate()
-{
- return selectedDate;
-}
+ public Calendar
+ getSelectedDate()
+ {
+ return selectedDate;
+ }
//The default equals and hashCode methods are acceptable.
-/**
- * {@inheritDoc}
- */
-
-public String
-toString()
-{
- return
- super.toString() + ",selectedDate=" +
- selectedDate.getTime().toString();
-}
+ /**
+ * {@inheritDoc}
+ */
+
+ public String
+ toString()
+ {
+ return
+ super.toString() + ",selectedDate=" +
+ selectedDate.getTime().toString();
+ }
}
diff --git a/libs/FLib/JCalendar/org/freixas/jcalendar/DateListener.java b/libs/FLib/JCalendar/org/freixas/jcalendar/DateListener.java
index 7d3f723..3d29476 100644
--- a/libs/FLib/JCalendar/org/freixas/jcalendar/DateListener.java
+++ b/libs/FLib/JCalendar/org/freixas/jcalendar/DateListener.java
@@ -22,7 +22,7 @@ import java.util.EventListener;
// All Rights Reserved.
public interface DateListener
- extends EventListener
+ extends EventListener
{
//**********************************************************************
@@ -33,14 +33,14 @@ public interface DateListener
// Public
//**********************************************************************
-/**
- * This method is called each time a date in a calendar changes.
- *
- * @param e The date event information.
- */
+ /**
+ * This method is called each time a date in a calendar changes.
+ *
+ * @param e The date event information.
+ */
-public void
-dateChanged(
- DateEvent e);
+ public void
+ dateChanged(
+ DateEvent e);
}
diff --git a/libs/FLib/JCalendar/org/freixas/jcalendar/JCalendar.java b/libs/FLib/JCalendar/org/freixas/jcalendar/JCalendar.java
index 5e305f1..7843669 100644
--- a/libs/FLib/JCalendar/org/freixas/jcalendar/JCalendar.java
+++ b/libs/FLib/JCalendar/org/freixas/jcalendar/JCalendar.java
@@ -95,33 +95,33 @@ import java.util.ResourceBundle;
// All Rights Reserved.
public class JCalendar
- extends JPanel
+ extends JPanel
{
//**********************************************************************
// Public Constants
//**********************************************************************
-/**
- * Used to indicate that this component should display the date.
- */
+ /**
+ * Used to indicate that this component should display the date.
+ */
-public static final int DISPLAY_DATE = 0x01;
+ public static final int DISPLAY_DATE = 0x01;
-/**
- * Used to indicate that this component should display the time.
- */
+ /**
+ * Used to indicate that this component should display the time.
+ */
-public static final int DISPLAY_TIME = 0x02;
+ public static final int DISPLAY_TIME = 0x02;
//**********************************************************************
// Private Constants
//**********************************************************************
-private static final int MONTH_DECR_BUTTON = 0;
-private static final int MONTH_INCR_BUTTON = 1;
-private static final int YEAR_DECR_BUTTON = 2;
-private static final int YEAR_INCR_BUTTON = 3;
+ private static final int MONTH_DECR_BUTTON = 0;
+ private static final int MONTH_INCR_BUTTON = 1;
+ private static final int YEAR_DECR_BUTTON = 2;
+ private static final int YEAR_INCR_BUTTON = 3;
//**********************************************************************
// Private Members
@@ -130,1364 +130,1365 @@ private static final int YEAR_INCR_BUTTON = 3;
// This determines the components being displayed: the calendar, the
// time spinner, or both
-private int selectedComponents;
+ private int selectedComponents;
// The calendar containing a selected day. The selected day may not be
// always be displayed
-private Calendar selectedCalendar;
-private int selectedYear = -1;
-private int selectedMonth = -1;
-private int selectedDay = -1;
-private int selectedHour = -1;
-private int selectedMinute = -1;
-private int selectedSecond = -1;
+ private Calendar selectedCalendar;
+ private int selectedYear = -1;
+ private int selectedMonth = -1;
+ private int selectedDay = -1;
+ private int selectedHour = -1;
+ private int selectedMinute = -1;
+ private int selectedSecond = -1;
// The calendar we display
-private Calendar displayCalendar;
-private int displayYear;
-private int displayMonth;
+ private Calendar displayCalendar;
+ private int displayYear;
+ private int displayMonth;
// The locale to use
-private Locale locale;
+ private Locale locale;
// True if we display today's date
-private boolean isTodayDisplayed = false;
+ private boolean isTodayDisplayed = false;
// A null date is equivalent to having no date selected. Note that the
// constructor selects the current date (today)
-private boolean isNullAllowed = true;
-private boolean isNullDate = true;
+ private boolean isNullAllowed = true;
+ private boolean isNullDate = true;
// The time pattern used to set the format of the time spinner
-private String timePattern;
+ private String timePattern;
// Components
-private JButton yearDecrButton;
-private JButton monthDecrButton;
-private JLabel monthYearLabel;
-private JButton monthIncrButton;
-private JButton yearIncrButton;
+ private JButton yearDecrButton;
+ private JButton monthDecrButton;
+ private JLabel monthYearLabel;
+ private JButton monthIncrButton;
+ private JButton yearIncrButton;
-private JLabel[] dayOfWeekLabels;
-private JToggleButton[][] dayButtons;
-private JToggleButton offScreenButton;
-private ButtonGroup dayGroup;
+ private JLabel[] dayOfWeekLabels;
+ private JToggleButton[][] dayButtons;
+ private JToggleButton offScreenButton;
+ private ButtonGroup dayGroup;
-private SpinnerDateModel spinnerDateModel;
-private JSpinner spinner;
+ private SpinnerDateModel spinnerDateModel;
+ private JSpinner spinner;
-private JLabel todaysLabel;
+ private JLabel todaysLabel;
// Fonts
-private Font titleFont;
-private Font dayOfWeekFont;
-private Font dayFont;
-private Font timeFont;
-private Font todayFont;
+ private Font titleFont;
+ private Font dayOfWeekFont;
+ private Font dayFont;
+ private Font timeFont;
+ private Font todayFont;
// Date formats
-private DateFormat formatMonth;
-private DateFormat formatWeekDay;
+ private DateFormat formatMonth;
+ private DateFormat formatWeekDay;
-private String lastMonth;
-private String lastYear;
+ private String lastMonth;
+ private String lastYear;
// These maps are used to bind keyboard keys to methods
-static InputMap inputMap = new InputMap();
-static ActionMap actionMap = new ActionMap();
+ static InputMap inputMap = new InputMap();
+ static ActionMap actionMap = new ActionMap();
// The input map maps a key to a name. The action map maps a name to
// an action. The actions below map the action to a method call
-private static Action yearBackward = new AbstractAction("yearBackward") {
- public void actionPerformed(ActionEvent e) {
- ((JCalendar)e.getSource()).yearBackward();
- }
-};
-
-private static Action yearForward = new AbstractAction("yearForward") {
- public void actionPerformed(ActionEvent e) {
- ((JCalendar)e.getSource()).yearForward();
- }
-};
-
-private static Action monthBackward = new AbstractAction("montBackward") {
- public void actionPerformed(ActionEvent e) {
- ((JCalendar)e.getSource()).monthBackward();
- }
-};
-
-private static Action monthForward = new AbstractAction("monthForward") {
- public void actionPerformed(ActionEvent e) {
- ((JCalendar)e.getSource()).monthForward();
- }
-};
-
-private static Action setNullDate = new AbstractAction("setNullDate") {
- public void actionPerformed(ActionEvent e) {
- ((JCalendar)e.getSource()).setDate(null);
- }
-};
+ private static Action yearBackward = new AbstractAction("yearBackward") {
+ public void actionPerformed(ActionEvent e) {
+ ((JCalendar)e.getSource()).yearBackward();
+ }
+ };
+
+ private static Action yearForward = new AbstractAction("yearForward") {
+ public void actionPerformed(ActionEvent e) {
+ ((JCalendar)e.getSource()).yearForward();
+ }
+ };
+
+ private static Action monthBackward = new AbstractAction("montBackward") {
+ public void actionPerformed(ActionEvent e) {
+ ((JCalendar)e.getSource()).monthBackward();
+ }
+ };
+
+ private static Action monthForward = new AbstractAction("monthForward") {
+ public void actionPerformed(ActionEvent e) {
+ ((JCalendar)e.getSource()).monthForward();
+ }
+ };
+
+ private static Action setNullDate = new AbstractAction("setNullDate") {
+ public void actionPerformed(ActionEvent e) {
+ ((JCalendar)e.getSource()).setDate(null);
+ }
+ };
// The resource bundle
-private static ResourceBundle bundle =
- ResourceBundle.getBundle("org.freixas.jcalendar.Bundle");
+ private static ResourceBundle bundle =
+ ResourceBundle.getBundle("org.freixas.jcalendar.Bundle");
//**********************************************************************
// Static Constructors
//**********************************************************************
-static
-{
- // Set up the input map that will be shared by all instances
-
- inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), "setNullDate");
- inputMap.put(KeyStroke.getKeyStroke("DELETE"), "setNullDate");
- inputMap.put(KeyStroke.getKeyStroke("shift LEFT"), "yearBackward");
- inputMap.put(KeyStroke.getKeyStroke("shift RIGHT"), "yearForward");
- inputMap.put(KeyStroke.getKeyStroke("LEFT"), "monthBackward");
- inputMap.put(KeyStroke.getKeyStroke("RIGHT"), "monthForward");
-
- actionMap.put("setNullDate", setNullDate);
- actionMap.put("yearBackward", yearBackward);
- actionMap.put("yearForward", yearForward);
- actionMap.put("monthBackward", monthBackward);
- actionMap.put("monthForward", monthForward);
-}
+ static
+ {
+ // Set up the input map that will be shared by all instances
+
+ inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), "setNullDate");
+ inputMap.put(KeyStroke.getKeyStroke("DELETE"), "setNullDate");
+ inputMap.put(KeyStroke.getKeyStroke("shift LEFT"), "yearBackward");
+ inputMap.put(KeyStroke.getKeyStroke("shift RIGHT"), "yearForward");
+ inputMap.put(KeyStroke.getKeyStroke("LEFT"), "monthBackward");
+ inputMap.put(KeyStroke.getKeyStroke("RIGHT"), "monthForward");
+
+ actionMap.put("setNullDate", setNullDate);
+ actionMap.put("yearBackward", yearBackward);
+ actionMap.put("yearForward", yearForward);
+ actionMap.put("monthBackward", monthBackward);
+ actionMap.put("monthForward", monthForward);
+ }
//**********************************************************************
// Constructors
//**********************************************************************
-/**
- * Create an instance of JCalendar using the default calendar and
- * locale. Display the date but not the time. Don't display today's
- * date at the bottom of the panel.
- */
-
-public
-JCalendar()
-{
- this(Calendar.getInstance(),
- Locale.getDefault(),
- DISPLAY_DATE,
- false,
- null);
-}
-
-/**
- * Create an instance of JCalendar using the default calendar and
- * locale. Display a calendar and/or a time spinner as requested (to
- * display both use DISPLAY_DATE | DISPLAY_TIME). Display today's
- * date if requested. Use the defult pattern to display the time in the
- * time spinner field (if there is one).
- *
- * @param selectedComponents Use DISPLAY_DATE, DISPLAY_TIME or
- * (DISPLAY_DATE | DISPLAY_TIME).
- * @param isTodayDisplayed True if today's date should be displayed at
- * the bottom of the panel.
- */
-
-public
-JCalendar(
- int selectedComponents,
- boolean isTodayDisplayed)
-{
- this(Calendar.getInstance(),
- Locale.getDefault(),
- selectedComponents,
- isTodayDisplayed,
- null);
-}
-
-/**
- * Create an instance of JCalendar using the given calendar and
- * locale. Display a calendar and/or a time spinner as requested (to
- * display both use DISPLAY_DATE | DISPLAY_TIME). Display today's
- * date if requested. Use the default pattern to display the time in the
- * time spinner field (if there is one).
- *
- * @param calendar The calendar to use.
- * @param locale The locale to use.
- * @param selectedComponents Use DISPLAY_DATE, DISPLAY_TIME or
- * (DISPLAY_DATE | DISPLAY_TIME).
- * @param isTodayDisplayed True if today's date should be displayed at
- * the bottom of the panel.
- */
-
-public
-JCalendar(
- Calendar calendar,
- Locale locale,
- int selectedComponents,
- boolean isTodayDisplayed)
-{
- this(calendar,
- locale,
- selectedComponents,
- isTodayDisplayed,
- null);
-}
-
-/**
- * Create an instance of JCalendar using the given calendar and
- * locale. Display a calendar and/or a time spinner as requested (to
- * display both use DISPLAY_DATE | DISPLAY_TIME). Display today's
- * date if requested. Set the pattern used to display the time in the time
- * spinner field (if there is one). If null, use the default MEDIUM
- * format for the given locale. Patterns are from DateFormat and
- * SimpleDateFormat.
- *
- * @param calendar The calendar to use.
- * @param locale The locale to use.
- * @param selectedComponents Use DISPLAY_DATE, DISPLAY_TIME or
- * (DISPLAY_DATE | DISPLAY_TIME).
- * @param isTodayDisplayed True if today's date should be displayed at
- * the bottom of the panel.
- * @param timePattern The pattern used to display the time in the time
- * spinner field.
- * @see DateFormat
- * @see SimpleDateFormat
- */
+ /**
+ * Create an instance of JCalendar using the default calendar and
+ * locale. Display the date but not the time. Don't display today's
+ * date at the bottom of the panel.
+ */
+
+ public
+ JCalendar()
+ {
+ this(Calendar.getInstance(),
+ Locale.getDefault(),
+ DISPLAY_DATE,
+ false,
+ null);
+ }
-public
-JCalendar(
- Calendar calendar,
- Locale locale,
- int selectedComponents,
- boolean isTodayDisplayed,
- String timePattern)
-{
- this.selectedCalendar = (Calendar)calendar.clone();
- this.displayCalendar = (Calendar)selectedCalendar.clone();
- this.selectedComponents = selectedComponents;
- if ((selectedComponents & (DISPLAY_DATE | DISPLAY_TIME)) == 0) {
- throw new IllegalStateException(
- bundle.getString("IllegalStateException"));
+ /**
+ * Create an instance of JCalendar using the default calendar and
+ * locale. Display a calendar and/or a time spinner as requested (to
+ * display both use DISPLAY_DATE | DISPLAY_TIME). Display today's
+ * date if requested. Use the defult pattern to display the time in the
+ * time spinner field (if there is one).
+ *
+ * @param selectedComponents Use DISPLAY_DATE, DISPLAY_TIME or
+ * (DISPLAY_DATE | DISPLAY_TIME).
+ * @param isTodayDisplayed True if today's date should be displayed at
+ * the bottom of the panel.
+ */
+
+ public
+ JCalendar(
+ int selectedComponents,
+ boolean isTodayDisplayed)
+ {
+ this(Calendar.getInstance(),
+ Locale.getDefault(),
+ selectedComponents,
+ isTodayDisplayed,
+ null);
}
- this.locale = locale;
- this.isTodayDisplayed = isTodayDisplayed;
-
- if ((selectedComponents & DISPLAY_TIME) > 0) {
- if (timePattern == null) {
- DateFormat timeFormat =
- DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
- this.timePattern = "HH:mm:ss";
- if (timeFormat instanceof SimpleDateFormat) {
- this.timePattern = ((SimpleDateFormat)timeFormat).toPattern();
- }
- }
- else {
- this.timePattern = timePattern;
- }
+ /**
+ * Create an instance of JCalendar using the given calendar and
+ * locale. Display a calendar and/or a time spinner as requested (to
+ * display both use DISPLAY_DATE | DISPLAY_TIME). Display today's
+ * date if requested. Use the default pattern to display the time in the
+ * time spinner field (if there is one).
+ *
+ * @param calendar The calendar to use.
+ * @param locale The locale to use.
+ * @param selectedComponents Use DISPLAY_DATE, DISPLAY_TIME or
+ * (DISPLAY_DATE | DISPLAY_TIME).
+ * @param isTodayDisplayed True if today's date should be displayed at
+ * the bottom of the panel.
+ */
+
+ public
+ JCalendar(
+ Calendar calendar,
+ Locale locale,
+ int selectedComponents,
+ boolean isTodayDisplayed)
+ {
+ this(calendar,
+ locale,
+ selectedComponents,
+ isTodayDisplayed,
+ null);
}
- createCalendarComponents();
- setDate(new Date());
-}
+ /**
+ * Create an instance of JCalendar using the given calendar and
+ * locale. Display a calendar and/or a time spinner as requested (to
+ * display both use DISPLAY_DATE | DISPLAY_TIME). Display today's
+ * date if requested. Set the pattern used to display the time in the time
+ * spinner field (if there is one). If null, use the default MEDIUM
+ * format for the given locale. Patterns are from DateFormat and
+ * SimpleDateFormat.
+ *
+ * @param calendar The calendar to use.
+ * @param locale The locale to use.
+ * @param selectedComponents Use DISPLAY_DATE, DISPLAY_TIME or
+ * (DISPLAY_DATE | DISPLAY_TIME).
+ * @param isTodayDisplayed True if today's date should be displayed at
+ * the bottom of the panel.
+ * @param timePattern The pattern used to display the time in the time
+ * spinner field.
+ * @see DateFormat
+ * @see SimpleDateFormat
+ */
+
+ public
+ JCalendar(
+ Calendar calendar,
+ Locale locale,
+ int selectedComponents,
+ boolean isTodayDisplayed,
+ String timePattern)
+ {
+ this.selectedCalendar = (Calendar)calendar.clone();
+ this.displayCalendar = (Calendar)selectedCalendar.clone();
+ this.selectedComponents = selectedComponents;
+ if ((selectedComponents & (DISPLAY_DATE | DISPLAY_TIME)) == 0) {
+ throw new IllegalStateException(
+ bundle.getString("IllegalStateException"));
+ }
+
+ this.locale = locale;
+ this.isTodayDisplayed = isTodayDisplayed;
+
+ if ((selectedComponents & DISPLAY_TIME) > 0) {
+ if (timePattern == null) {
+ DateFormat timeFormat =
+ DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
+ this.timePattern = "HH:mm:ss";
+ if (timeFormat instanceof SimpleDateFormat) {
+ this.timePattern = ((SimpleDateFormat)timeFormat).toPattern();
+ }
+ }
+ else {
+ this.timePattern = timePattern;
+ }
+ }
+
+ createCalendarComponents();
+ setDate(new Date());
+ }
//**********************************************************************
// Public
//**********************************************************************
-/**
- * Add a date listener. This listener will receive events each time
- * the selected date changes.
- *
- * @param listener The date listener to add.
- */
-
-public void
-addDateListener(
- DateListener listener)
-{
- listenerList.add(DateListener.class, listener);
-}
-
-/**
- * Remove a date listener.
- *
- * @param listener The date listener to remove.
- */
-
-public void
-removeDateListener(
- DateListener listener)
-{
- listenerList.remove(DateListener.class, listener);
-}
-
-/**
- * Get whether a null date is allowed.
- *
- * @return Whether a null date is allowed.
- */
-
-public boolean
-isNullAllowed()
-{
- return isNullAllowed;
-}
-
-/**
- * Set whether a null date is allowed. A null date means that no date
- * is selected. The user can select a null date by pressing DELETE
- * anywhere within the calendar.
- * <p>
- * If nulls are not allowed, a setDate(null) will be ignored without
- * error. The DELETE key will do nothing.
- * <p>
- * If you switch from allowing nulls to not allowing nulls and the
- * current date is null, it will remain null until a date is selected.
- * <p>
- * The component default is to allow nulls.
- *
- * @param isNullAllowed Whether a null date is allowed.
- */
-
-public void
-setNullAllowed(
- boolean isNullAllowed)
-{
- this.isNullAllowed = isNullAllowed;
-}
-
-/**
- * Get the date currently displayed by the calendar panel. If no date
- * is selected, null is returned.
- *
- * @return The date currently displayed.
- * @see #getCalendar
- */
-
-public Date
-getDate()
-{
- if (isNullDate) return null;
- return selectedCalendar.getTime();
-}
-
-/**
- * Set the calendar panel to display the given date. This will fire a
- * DateEvent. The date may be null. If isNullAllowed() is true, then
- * all dates will be unselected. If isNullAllowed() is false, a null
- * date is ignored.
- *
- * @param date The date to set.
- */
-
-public void
-setDate(
- Date date)
-{
- if (date == null) {
-
- // Ignore nulls if nulls aren't allowed
-
- if (!isNullAllowed) return;
-
- if (!isNullDate) {
- isNullDate = true;
- selectedYear = -1;
- selectedMonth = -1;
- selectedDay = -1;
- selectedCalendar.set(Calendar.YEAR, 9999);
- selectedCalendar.set(Calendar.MONTH, 9);
- selectedCalendar.set(Calendar.DATE, 9);
- selectedCalendar.set(Calendar.HOUR_OF_DAY, 0);
- selectedCalendar.set(Calendar.MINUTE, 0);
- selectedCalendar.set(Calendar.SECOND, 0);
- updateCalendarComponents();
- fireDateChange();
- }
+ /**
+ * Add a date listener. This listener will receive events each time
+ * the selected date changes.
+ *
+ * @param listener The date listener to add.
+ */
+
+ public void
+ addDateListener(
+ DateListener listener)
+ {
+ listenerList.add(DateListener.class, listener);
}
- else {
- int oldYear = selectedYear;
- int oldMonth = selectedMonth;
- int oldDay = selectedDay;
- int oldHour = selectedHour;
- int oldMinute = selectedMinute;
- int oldSecond = selectedSecond;
-
- selectedCalendar.setTime(date);
- selectedYear = selectedCalendar.get(Calendar.YEAR);
- selectedMonth = selectedCalendar.get(Calendar.MONTH);
- selectedDay = selectedCalendar.get(Calendar.DATE);
- selectedHour = selectedCalendar.get(Calendar.HOUR_OF_DAY);
- selectedMinute = selectedCalendar.get(Calendar.MINUTE);
- selectedSecond = selectedCalendar.get(Calendar.SECOND);
-
- if ((((selectedComponents & DISPLAY_DATE) > 0) &&
- oldDay != selectedDay ||
- oldMonth != selectedMonth ||
- oldYear != selectedYear) ||
-
- (((selectedComponents & DISPLAY_TIME) > 0) &&
- oldHour != selectedHour ||
- oldMinute != selectedMinute ||
- oldSecond != selectedSecond)) {
-
- isNullDate = false;
- displayCalendar.setTime(date);
- updateCalendarComponents();
- fireDateChange();
- }
+ /**
+ * Remove a date listener.
+ *
+ * @param listener The date listener to remove.
+ */
+
+ public void
+ removeDateListener(
+ DateListener listener)
+ {
+ listenerList.remove(DateListener.class, listener);
}
-}
-
-/**
- * Reset the displayed date without changing the selected date. No
- * event occurs. A null date will reset to today's date. The display
- * date simply selects the calendar page (month/year) to display.
- *
- * @param date The date to display.
- */
-public void
-setDisplayDate(
- Date date)
-{
- if (date == null) date = new Date();
+ /**
+ * Get whether a null date is allowed.
+ *
+ * @return Whether a null date is allowed.
+ */
- displayCalendar.setTime(date);
- int oldMonth = displayCalendar.get(Calendar.MONTH);
- int oldYear = displayCalendar.get(Calendar.YEAR);
- if (oldMonth != displayMonth || oldYear != displayYear) {
- updateCalendarComponents();
+ public boolean
+ isNullAllowed()
+ {
+ return isNullAllowed;
}
-}
-
-/**
- * Get the pattern used to display the time in the time selection
- * spinner. This is null if the time is not displayed.
- *
- * @return The pattern used to display the time in the time selection
- * spinner.
- */
-public String
-getTimePattern()
-{
- if ((selectedComponents & DISPLAY_TIME) != 0) {
- return timePattern;
+ /**
+ * Set whether a null date is allowed. A null date means that no date
+ * is selected. The user can select a null date by pressing DELETE
+ * anywhere within the calendar.
+ * <p>
+ * If nulls are not allowed, a setDate(null) will be ignored without
+ * error. The DELETE key will do nothing.
+ * <p>
+ * If you switch from allowing nulls to not allowing nulls and the
+ * current date is null, it will remain null until a date is selected.
+ * <p>
+ * The component default is to allow nulls.
+ *
+ * @param isNullAllowed Whether a null date is allowed.
+ */
+
+ public void
+ setNullAllowed(
+ boolean isNullAllowed)
+ {
+ this.isNullAllowed = isNullAllowed;
}
- return null;
-}
-
-/**
- * Get a copy of the calendar used by this JCalendar. This calendar
- * will be set to the currently selected date, so it is an alternative
- * to the getDate() method. If no date is selected (getDate() returns
- * null), the calendar's selected date is 9/9/9999 and should not be
- * used.
- *
- * @return A copy of the calendar used by JCalendar.
- * @see #getDate
- */
-
-public Calendar
-getCalendar()
-{
- return (Calendar)selectedCalendar.clone();
-}
-
-/**
- * Return the locale used by this JCalendar.
- *
- * @return The locale used by this JCalendar.
- */
-
-public Locale
-getLocale()
-{
- return locale;
-}
-/**
- * Return the components being displayed:
- * <code>
- * (getSelectedComponents() & DISPLAY_DATE) > 0
- * </code>
- * means that the date calendar is being displayed.
- * <code>
- * (getSelectedComponents() & DISPLAY_TIME) > 0
- * </code>
- * menas that the time spinner field is being displayed.
- *
- * @return The selected components.
- */
-
-public int
-getSelectedComponents()
-{
- return selectedComponents;
-}
-
-
-/**
- * Returns true if today's date is displayed at the bottom of the
- * calendar.
- *
- * @return True if today's date is displayed at the bottom of the
- * calendar.
- */
+ /**
+ * Get the date currently displayed by the calendar panel. If no date
+ * is selected, null is returned.
+ *
+ * @return The date currently displayed.
+ * @see #getCalendar
+ */
+
+ public Date
+ getDate()
+ {
+ if (isNullDate) return null;
+ return selectedCalendar.getTime();
+ }
-public boolean
-isTodayDisplayed()
-{
- return isTodayDisplayed;
-}
+ /**
+ * Set the calendar panel to display the given date. This will fire a
+ * DateEvent. The date may be null. If isNullAllowed() is true, then
+ * all dates will be unselected. If isNullAllowed() is false, a null
+ * date is ignored.
+ *
+ * @param date The date to set.
+ */
+
+ public void
+ setDate(
+ Date date)
+ {
+ if (date == null) {
+
+ // Ignore nulls if nulls aren't allowed
+
+ if (!isNullAllowed) return;
+
+ if (!isNullDate) {
+ isNullDate = true;
+ selectedYear = -1;
+ selectedMonth = -1;
+ selectedDay = -1;
+ selectedCalendar.set(Calendar.YEAR, 9999);
+ selectedCalendar.set(Calendar.MONTH, 9);
+ selectedCalendar.set(Calendar.DATE, 9);
+ selectedCalendar.set(Calendar.HOUR_OF_DAY, 0);
+ selectedCalendar.set(Calendar.MINUTE, 0);
+ selectedCalendar.set(Calendar.SECOND, 0);
+ updateCalendarComponents();
+ fireDateChange();
+ }
+ }
+
+ else {
+ int oldYear = selectedYear;
+ int oldMonth = selectedMonth;
+ int oldDay = selectedDay;
+ int oldHour = selectedHour;
+ int oldMinute = selectedMinute;
+ int oldSecond = selectedSecond;
+
+ selectedCalendar.setTime(date);
+ selectedYear = selectedCalendar.get(Calendar.YEAR);
+ selectedMonth = selectedCalendar.get(Calendar.MONTH);
+ selectedDay = selectedCalendar.get(Calendar.DATE);
+ selectedHour = selectedCalendar.get(Calendar.HOUR_OF_DAY);
+ selectedMinute = selectedCalendar.get(Calendar.MINUTE);
+ selectedSecond = selectedCalendar.get(Calendar.SECOND);
+
+ if ((((selectedComponents & DISPLAY_DATE) > 0) &&
+ oldDay != selectedDay ||
+ oldMonth != selectedMonth ||
+ oldYear != selectedYear) ||
+
+ (((selectedComponents & DISPLAY_TIME) > 0) &&
+ oldHour != selectedHour ||
+ oldMinute != selectedMinute ||
+ oldSecond != selectedSecond)) {
+
+ isNullDate = false;
+ displayCalendar.setTime(date);
+ updateCalendarComponents();
+ fireDateChange();
+ }
+ }
+ }
-/**
- * Get the title font.
- *
- * @return The title font.
- */
+ /**
+ * Reset the displayed date without changing the selected date. No
+ * event occurs. A null date will reset to today's date. The display
+ * date simply selects the calendar page (month/year) to display.
+ *
+ * @param date The date to display.
+ */
+
+ public void
+ setDisplayDate(
+ Date date)
+ {