Author: bback
Date: 2006-03-14 14:05:52 +0000 (Tue, 14 Mar 2006)
New Revision: 8250
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/CalendarPanel.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_da.properties
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_de.properties
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_fi.properties
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_fr.properties
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/GridSelectionListener.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/Header.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MButtonChanger.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateChanger.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateDisplay.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateOutOfRangeException.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelector.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorConstraints.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorPanel.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorPanelBeanInfo.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorUI.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDefaultPullDownConstraints.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MFieldListener.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MFirstDayEditor.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MMonthEvent.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MMonthListener.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MScrollBarChanger.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MSpinnerChanger.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MTextLocaliserEditor.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MonthPopup.java
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/SpecialDayModel.java
Log:
new date chooser component
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/CalendarPanel.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/CalendarPanel.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/CalendarPanel.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,565 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import javax.swing.*;
+import javax.swing.plaf.ComponentUI;
+import mseries.ui.ScreenUtilities;
+import java.awt.*;
+import java.util.Calendar;
+import java.util.Vector;
+
+/**
+ * This is the component that forms the Calendar Grid. The pluggable look
and feel demands
+ * a separate UI Delegate, an implementation is provided in the laf package.
The actual class
+ * is determined dynamically by the actual look and feel used. This class
therefore is the
+ * controller in the MVC model for the calenar grid. It implements
TableModelListener because
+ * the Model is a TableModel. (the first generation of MDateSelector had the
calendar grid as
+ * a JTable)
+ * @author M Newstead
+ */
+public class CalendarPanel extends JComponent
+{
+ protected Color[] background;
+ protected Color[] foreground;
+
+ protected Color todayBG;
+ protected Color todayFG;
+ protected Color outOfRangeFG;
+ protected Color outOfRangeBG;
+
+ private boolean hasImage = false;
+
+ private MMonth model;
+ private SpecialDayModel specialModel;
+
+ /** The month that the calendar is displaying */
+ public int month;
+
+ private Point selectedCell = new Point(-1, -1);
+
+ /** The cell containing the first day of the month */
+ public Point firstCell = new Point(-1, 0);
+
+ /** The cell containing the last day of the month */
+ public Point lastCell = new Point(-1, -1);
+
+ private Vector listeners = new Vector();
+
+ /** The number of cells across the calendar */
+ public static int DAYS = 7;
+ /** The number of rows in the calendar */
+ public static int WEEKS = 6;
+
+ /** The size of one cell in the calendar grid */
+ public Dimension cellSize = new Dimension(22, 20);
+
+ private static final String uiClassID = "CalendarPanelUI";
+
+ public CalendarPanel()
+ {
+ super();
+ updateUI();
+ background = new Color[DAYS];
+ foreground = new Color[DAYS];
+
+ setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
+
ScreenUtilities.getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
+ setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
+
ScreenUtilities.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
+ }
+
+ public void updateUI()
+ {
+ setUI(registerUIDelegate());
+ }
+
+ protected ComponentUI registerUIDelegate()
+ {
+ ComponentUI compUI = (ComponentUI) UIManager.get(uiClassID);
+ if (compUI == null)
+ {
+ String uiDelegateClassName =
"mseries.plaf.basic.BasicCalendarPanelUI";
+ String lafName = UIManager.getLookAndFeel().getID();
+ /*
+ * There is no UI Delegate for this component so try to install
+ * one of the defaults
+ */
+
+ if (lafName.equals("Windows"))
+ {
+ uiDelegateClassName = "mseries.plaf." + lafName + "." +
lafName + "CalendarPanelUI";
+ }
+ else if (lafName.equals("Metal"))
+ {
+ uiDelegateClassName = "mseries.plaf." + lafName + "." +
lafName + "CalendarPanelUI";
+ }
+ else if (lafName.equals("Motif"))
+ {
+ uiDelegateClassName = "mseries.plaf." + lafName + "." +
lafName + "CalendarPanelUI";
+ }
+ try
+ {
+ compUI = (ComponentUI)
(Class.forName(uiDelegateClassName)).newInstance();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ }
+ return compUI;
+ }
+
+ /**
+ * The component manages the focus by TABBING across cells
+ */
+// public boolean isManagingFocus()
+// {
+// return true;
+// }
+
+
+ /**
+ * Returns true if the point passed in is in the month that the
+ * Calendar is currently is displaying. [The user could click on a cell
+ * that is at the end of the preceeding month or start of the next
month]
+ * @param row the row
+ * @param col the column
+ * @return true if the point is in the month
+ */
+ public boolean isInMonth(int row, int col)
+ {
+ Calendar date = (Calendar) model.getValueAt(row, col);
+ int clickMonth = date.get(Calendar.MONTH);
+
+ return clickMonth == month;
+ }
+
+ public boolean isInRange(int row, int col)
+ {
+ Calendar date = (Calendar) model.getValueAt(row, col);
+ return model.isInRange(date);
+ }
+ /**
+ * Gets the text (number) of the cell passed in
+ * @param row the row
+ * @param col the column
+ * @return the number of the cell
+ */
+ public int getLegendFor(int row, int col)
+ {
+ Calendar date = (Calendar) model.getValueAt(row, col);
+ int day = date.get(Calendar.DAY_OF_MONTH);
+ return day;
+ }
+
+ /**
+ * Gets the day of the week for the cell passed in
+ * @param row the row
+ * @param col the column
+ * @return the day of the week as a java.util.Calendar constant
+ */
+ public int getDOW(int row, int col)
+ {
+ Calendar date = (Calendar) model.getValueAt(row, col);
+ int day = date.get(Calendar.DAY_OF_WEEK);
+ return day;
+ }
+
+
+ protected void setSpecialModel(SpecialDayModel sdm)
+ {
+ this.specialModel = sdm;
+ }
+
+ public void setModel(MMonth model)
+ {
+
+ this.model = model;
+
+ month = calculateMonth();
+
+ DAYS = model.getColumnCount();
+ WEEKS = model.getRowCount();
+ }
+
+ private int calculateMonth()
+ {
+ Calendar firstDate, scratchDate;
+
+ scratchDate = (Calendar) model.getValueAt(0, 0);
+ firstDate = (Calendar) scratchDate.clone();
+ if (firstDate.get(Calendar.DAY_OF_MONTH) != 1)
+ {
+ // The first day of the month is not at the start of the week
+ firstDate.add(Calendar.MONTH, 1);
+ }
+ return firstDate.get(Calendar.MONTH);
+ }
+
+ /**
+ * Recieves changes from the data model
+ */
+ public void tableChanged()
+ {
+ month = calculateMonth();
+ repaint();
+ }
+
+ /**
+ * Makes the point passed the current point in the calendar
+ * @param pnt the point to make the selected date
+ */
+ public void setCurrentDate(Point pnt)
+ {
+ setSelectedCell(pnt);
+ }
+
+ /**
+ * Makes the point passed the current point in the calendar
+ * @param cell the point to make the selected date
+ */
+ public void setSelectedCell(Point cell)
+ {
+ setSelectedCell(cell.x, cell.y);
+ }
+
+ /**
+ * Makes the point passed the current point in the calendar
+ * @param x the column
+ * @param y the row
+ */
+ public void setSelectedCell(int x, int y)
+ {
+ if (isEnabled())
+ {
+ selectedCell.x = x;
+ selectedCell.y = y;
+ }
+ }
+
+ /**
+ * Sets the passed cell as the one displaying the last day of the month
+ * (used by L&F)
+ * @param cell the cell for last day of the month
+ */
+ public void setLastCell(Point cell)
+ {
+ lastCell.x = cell.x;
+ lastCell.y = cell.y;
+ }
+
+ /**
+ * Sets the passed cell as the one displaying the first day of the month
+ * (used by L&F)
+ * @param cell the cell for first day of the month
+ */
+ public void setFirstCell(Point cell)
+ {
+ firstCell.x = cell.x;
+ firstCell.y = cell.y;
+ }
+
+ public Point getSelectedCell()
+ {
+ return selectedCell;
+ }
+
+
+ public void addGridSelectionListener(GridSelectionListener l)
+ {
+ listeners.addElement(l);
+ }
+
+ public void removeGridSelectionListener(GridSelectionListener l)
+ {
+ listeners.removeElement(l);
+ }
+
+ public void notifyListeners()
+ {
+ if (isEnabled())
+ {
+ notifyListeners(new GridSelectionEvent(this, getSelectedCell()));
+ }
+ }
+
+ public void notifyListeners(GridSelectionEvent event)
+ {
+ // Pass these events on to the registered listener
+
+ Vector list = (Vector) listeners.clone();
+ for (int i = 0; i < list.size(); i++)
+ {
+ GridSelectionListener l = (GridSelectionListener)
listeners.elementAt(i);
+ l.gridCellChanged(event);
+ }
+ }
+
+ public boolean isFocusable()
+ {
+ return true;
+ }
+
+ /**
+ * This method gives the UI Manager a constant to use to look up in the
UI Defaults table
+ * to find the class name of the UI Delegate for the installed L&F.
+ * @return string "CalendarPanelUI"
+ */
+ public String getUIClassID()
+ {
+ return uiClassID;
+ }
+
+ /**
+ * Sets the foreground color for the column representing the day given.
+ * @param day a number in the range 1 - 7 from SUNDAY - SATURDAY, days
not
+ * set will assume the default foreground color
+ * @param color the color to set
+ */
+ public void setForeground(int day, Color color)
+ {
+ foreground[day - 1] = color;
+ }
+
+ /**
+ * Sets the background color for the column representing the day given.
+ * @param day a number in the range 1 - 7 from SUNDAY - SATURDAY, days
not
+ * set will assume the default background color
+ * @param color the color to set
+ */
+ public void setBackground(int day, Color color)
+ {
+ background[day - 1] = color;
+ }
+
+ /**
+ * Sets the all the background colors for each day element 0 - SUNDAY, 6
- SATURDAY
+ * @param colors the colors to set
+ */
+ public void setBackground(Color[] colors)
+ {
+ background = colors;
+ }
+
+ /**
+ * Sets the all the foreground colors for each day element 0 - SUNDAY, 6
- SATURDAY
+ * @param colors the colors to set
+ */
+ public void setForeground(Color[] colors)
+ {
+ foreground = colors;
+ }
+
+
+ /**
+ * Sets the foreground colour of out of range dates
+ */
+ public void setOutOfRangeForeground(Color colour)
+ {
+ outOfRangeFG = colour;
+ }
+
+ public Color getOutOfRangeBackground()
+ {
+ return outOfRangeBG;
+ }
+
+ public void setOutOfRangeBackground(Color outOfRangeBG)
+ {
+ this.outOfRangeBG = outOfRangeBG;
+ }
+
+ /**
+ * Sets the foreground colour of the current date
+ */
+ public void setTodayForeground(Color colour)
+ {
+ todayFG = colour;
+ }
+
+ /**
+ * Sets the background colour of the current date
+ */
+ public void setTodayBackground(Color colour)
+ {
+ todayBG = colour;
+ }
+
+ /**
+ * @return the background color for the day passed
+ * @param day in the range 1 (SUNDAY) to 6 (SATURDAY)
+ */
+ public Color getBackground(int day)
+ {
+ Color c = background[day - 1];
+ if (c == null)
+ {
+ return getBackground();
+ }
+ return c;
+ }
+
+ /**
+ * @return the background of cell at column d, row w. If the specified
+ * cell represents the current date (today) the current date background
+ * colour will be returned if specified other wise the colour for the
+ * day of week is returned.
+ */
+ public Color getBackground(int w, int d)
+ {
+ if (model.isCurrentDate(w, d))
+ {
+ if (todayBG != null)
+ return todayBG;
+ }
+ if(!model.isInRange(model.getAsDate(w,d))&& outOfRangeBG!=null)
+ {
+ return outOfRangeBG;
+ }
+ if (specialModel.isSpecialDay(model.getAsDate(w, d)))
+ {
+ Color bg = specialModel.getBackground(model.getAsDate(w, d));
+ if (bg != null)
+ return bg;
+ }
+ return getBackground(getDOW(w, d));
+ }
+
+ /**
+ * @return the foreground color for the day passed
+ * @param day in the range 1 (SUNDAY) to 6 (SATURDAY)
+ */
+ public Color getForeground(int day)
+ {
+ Color c = foreground[day - 1];
+ if (c == null)
+ {
+ return getForeground();
+ }
+ return c;
+ }
+
+ /**
+ * @return the foreground of cell at column d, row w. If the specified
+ * cell represents the current date (today) the current date foreground
+ * colour will be returned if specified other wise the colour for the
+ * day of week is returned.
+ */
+ public Color getForeground(int w, int d)
+ {
+ if (model.isCurrentDate(w, d))
+ {
+
+ if (todayFG != null)
+ return todayFG;
+ }
+ if(!model.isInRange(model.getAsDate(w,d))&& outOfRangeFG!=null)
+ {
+ return outOfRangeFG;
+ }
+ if (specialModel.isSpecialDay(model.getAsDate(w, d)))
+ {
+ Color fg = specialModel.getForeground(model.getAsDate(w, d));
+ if (fg != null)
+ return fg;
+ }
+ return getForeground(getDOW(w, d));
+ }
+
+ /**
+ * Sets the size of one cell in the calendar panel
+ * @param cellSize the cell size
+ */
+ public void setCellSize(Dimension cellSize)
+ {
+ this.cellSize = cellSize;
+ Dimension size = new Dimension(1, 1);
+ size.width = DAYS * cellSize.width;
+ size.height = WEEKS * cellSize.height;
+ setMinimumSize(size);
+ setMaximumSize(size);
+ setPreferredSize(size);
+ }
+
+ /**
+ * Gets the cell size
+ * @return the the cellSize attribute
+ */
+ public Dimension getCellSize()
+ {
+ return cellSize;
+ }
+
+ public void setHasImage(boolean hasImage)
+ {
+ this.hasImage = hasImage;
+ }
+
+ public boolean hasImage()
+ {
+ return hasImage;
+ }
+}
+
+/*
+$Log: CalendarPanel.java,v $
+Revision 1.13 2003/10/04 10:39:06 martin
+*** empty log message ***
+
+Revision 1.12 2003/10/04 09:41:40 martin
+*** empty log message ***
+
+Revision 1.11 2003/03/26 23:29:48 martin
+Changed email address
+
+Revision 1.10 2003/03/24 19:45:07 martin
+Latest 1.4 version
+
+Revision 1.8 2003/03/11 22:35:14 martin
+Upgraded to Java 1.4 on 11/03/03
+
+Revision 1.7 2002/12/21 22:53:05 martin
+*** empty log message ***
+
+Revision 1.6 2002/08/17 20:13:37 martin
+Reformatted code using intellij
+
+Revision 1.5 2002/02/09 12:54:39 martin
+Partial support for 'Special Days'
+
+Revision 1.4 2002/02/03 12:49:09 martin
+Added support for curret date highlighted in different colour
+
+$Log: CalendarPanel.java,v $
+Revision 1.13 2003/10/04 10:39:06 martin
+*** empty log message ***
+
+Revision 1.12 2003/10/04 09:41:40 martin
+*** empty log message ***
+
+Revision 1.11 2003/03/26 23:29:48 martin
+Changed email address
+
+Revision 1.10 2003/03/24 19:45:07 martin
+Latest 1.4 version
+
+Revision 1.8 2003/03/11 22:35:14 martin
+Upgraded to Java 1.4 on 11/03/03
+
+Revision 1.2.2.3 2002/02/02 15:40:33 martin
+Added CVS tag Log
+
+*/
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,52 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.util.ListResourceBundle;
+
+public class DateSelectorRB extends ListResourceBundle
+{
+ public static final String MON="Mo";
+ public static final String TUE="Tu";
+ public static final String WED="We";
+ public static final String THU="Th";
+ public static final String FRI="Fr";
+ public static final String SAT="Sa";
+ public static final String SUN="Su";
+
+ public static final String OK="OK";
+ public static final String CANCEL="Cancel";
+ public static final String TODAY="Today";
+
+ String contents[][] =
+ {
+ {MON, MON},
+ {TUE, TUE},
+ {WED, WED},
+ {THU, THU},
+ {FRI, FRI},
+ {SAT, SAT},
+ {SUN, SUN},
+ {OK, OK},
+ {CANCEL, CANCEL},
+ {TODAY, TODAY},
+ };
+
+
+ public Object[][] getContents()
+ {
+ return contents;
+ }
+}
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_da.properties
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_da.properties
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_da.properties
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,21 @@
+# Sample ResourceBundle properties file
+
+Mo=Ma
+
+Tu=Ti
+
+We=On
+
+Th=To
+
+Fr=Fr
+
+Sa=L\u00F8
+
+Su=S\u00F8
+
+Today=Idag
+
+OK=OK
+
+Cancel=Annuller
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_de.properties
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_de.properties
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_de.properties
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,17 @@
+# Resources for MDateSelector
+# Provided by Arnaud Val?re
+
+# Column Headings
+Mo=Mo
+Tu=Di
+We=Mi
+Th=Do
+Fr=Fr
+Sa=Sa
+Su=So
+
+# Button Labels
+Today=Heute
+OK=OK
+Cancel=Abbrechen
+
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_fi.properties
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_fi.properties
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_fi.properties
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,16 @@
+# Resources for MDateSelector localized in finnish
+
+# Column Headings
+Mo=Ma
+Tu=Ti
+We=Ke
+Th=To
+Fr=Pe
+Sa=La
+Su=Su
+
+# Button Labels
+Today=T?n??n
+OK=OK
+Cancel=Peruuta
+
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_fr.properties
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_fr.properties
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/DateSelectorRB_fr.properties
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,16 @@
+# Resources for MDateSelector
+
+# Column Headings
+Mo=lu
+Tu=ma
+We=me
+Th=je
+Fr=ve
+Sa=sa
+Su=di
+
+# Button Labels
+Today=Aujourdhui
+OK=Oui
+Cancel=Non
+
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/GridSelectionListener.java
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/GridSelectionListener.java
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/GridSelectionListener.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,23 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+/** Interface to which any object must conform if it is to be informed of
+* changes to a grid cell
+*/
+public interface GridSelectionListener
+{
+ public void gridCellChanged(GridSelectionEvent event);
+}
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/Header.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/Header.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/Header.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,283 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.Calendar;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Header extends JComponent
+{
+ protected Color[] background;
+ protected Color[] foreground;
+ boolean opaque = true;
+ final String[] fColumnNames = {DateSelectorRB.SUN,
+ DateSelectorRB.MON,
+ DateSelectorRB.TUE,
+ DateSelectorRB.WED,
+ DateSelectorRB.THU,
+ DateSelectorRB.FRI,
+ DateSelectorRB.SAT};
+ String[] columnNames = new String[fColumnNames.length];
+ private static final String uiClassID = "HeaderUI";
+
+ private ResourceBundle rb;
+ int cols;
+ int n;
+
+ /** The size of one cell in the calendar grid */
+ public Dimension cellSize = new Dimension(22, 20);
+
+
+ public Header(int cols)
+ {
+ super();
+ this.cols = cols;
+
+ System.arraycopy(fColumnNames, 0, columnNames, 0, fColumnNames.length);
+
+ setFirstDay(Calendar.SUNDAY);
+ setCellSize(cellSize);
+ updateUI();
+ background = new Color[columnNames.length];
+ foreground = new Color[columnNames.length];
+ }
+
+ public void updateUI()
+ {
+ registerUIDelegate();
+ setOpaque(false);
+ setUI(UIManager.getUI(this));
+ }
+
+ protected void registerUIDelegate()
+ {
+ if (UIManager.get(uiClassID) == null)
+ {
+ String uiDelegateClassName = "mseries.plaf.basic.BasicHeaderUI";
+ String lafName = UIManager.getLookAndFeel().getName();
+ /*
+ * There is no UI Delegate for this component so try to install
+ * one of the defaults
+ */
+
+ if (lafName.equals("Windows"))
+ {
+ uiDelegateClassName = "mseries.plaf." + lafName +
".WindowsHeaderUI";
+ }
+ else if (lafName.equals("Metal"))
+ {
+ uiDelegateClassName = "mseries.plaf." + lafName +
".MetalHeaderUI";
+ }
+ else if (lafName.equals("Motif"))
+ {
+ uiDelegateClassName = "mseries.plaf." + lafName +
".MotifHeaderUI";
+ }
+ UIManager.put(uiClassID, uiDelegateClassName);
+ }
+ }
+
+
+ public void setTextLocalizer(ResourceBundle rb)
+ {
+ this.rb = rb;
+ }
+
+ public void setFirstDay(int firstDay)
+ {
+ shiftColumnNames(firstDay - 1);
+ }
+
+ private String getString(String source, String def)
+ {
+ String newString;
+ if (rb == null)
+ {
+ return def;
+ }
+ try
+ {
+ newString = rb.getString(source);
+ }
+ catch (MissingResourceException e)
+ {
+ newString = def;
+ }
+ return newString;
+ }
+
+ private void shiftColumnNames(int places)
+ {
+ n = places;
+ for (int i = 0; i < cols; i++)
+ {
+ columnNames[i] = fColumnNames[n];
+ n++;
+ if (n == cols) n = 0;
+ }
+ }
+
+ public String getColumnName(int columnIndex)
+ {
+ return getString(columnNames[columnIndex], columnNames[columnIndex]);
+ }
+
+ public int getCols()
+ {
+ return cols;
+ }
+
+ /**
+ * Sets the foreground color for the column representing the day given.
+ * @param day a number in the range 1 - 7 from SUNDAY - SATURDAY, days
not
+ * set will assume the default foreground color
+ * @param color the color to set
+ */
+ public void setForeground(int day, Color color)
+ {
+ foreground[day - 1] = color;
+ }
+
+ /**
+ * Sets the background color for the column representing the day given.
+ * @param day a number in the range 1 - 7 from SUNDAY - SATURDAY, days
not
+ * set will assume the default foreground color
+ * @param color the color to set
+ */
+ public void setBackground(int day, Color color)
+ {
+ background[day - 1] = color;
+ }
+
+ /**
+ * Sets the all the background colors for each day element 0 - SUNDAY, 6
- SATURDAY
+ * @param colors the color to set
+ */
+ public void setBackground(Color[] colors)
+ {
+ background = colors;
+ }
+
+ /**
+ * Sets the all the foreground colors for each day element 0 - SUNDAY, 6
- SATURDAY
+ * @param colors the color to set
+ */
+ public void setForeground(Color[] colors)
+ {
+ foreground = colors;
+ }
+
+ /**
+ * @return the background color for the day passed
+ * @param day in the range 1 (SUNDAY) to 6 (SATURDAY)
+ */
+ public Color getBackground(int day)
+ {
+ int i;
+ i = day + n;
+ i = (i > 6) ? i - 7 : i;
+
+ Color c = background[i];
+ if (c == null)
+ {
+ return getBackground();
+ }
+ return c;
+ }
+
+ /**
+ * @return the foreground color for the day passed
+ * @param day in the range 1 (SUNDAY) to 6 (SATURDAY)
+ */
+ public Color getForeground(int day)
+ {
+ int i;
+ i = day + n;
+ i = (i > 6) ? i - 7 : i;
+
+ Color c = foreground[i];
+ if (c == null)
+ {
+ return getForeground();
+ }
+ return c;
+ }
+
+ //public boolean isFocusTraversable()
+ public boolean isFocusable()
+ {
+ return false;
+ }
+
+ public String getUIClassID()
+ {
+ return uiClassID;
+ }
+
+ /**
+ * Sets the size of one cell in the calendar panel
+ * @param cellSize the cell size
+ */
+ public void setCellSize(Dimension cellSize)
+ {
+ this.cellSize = cellSize;
+
+ Dimension size = new Dimension(1, 1);
+ size.width = cols * cellSize.width;
+ size.height = cellSize.height;
+ setMinimumSize(size);
+ setMaximumSize(size);
+ setPreferredSize(size);
+ }
+
+ /**
+ * Gets the cell size
+ * @return the the cellSize attribute
+ */
+ public Dimension getCellSize()
+ {
+ return cellSize;
+ }
+
+}
+
+// $Log: Header.java,v $
+// Revision 1.7 2003/03/26 23:29:48 martin
+// Changed email address
+//
+// Revision 1.6 2003/03/24 19:45:07 martin
+// Latest 1.4 version
+//
+// Revision 1.4 2003/03/11 22:35:14 martin
+// Upgraded to Java 1.4 on 11/03/03
+//
+// Revision 1.3 2002/08/17 20:24:50 martin
+// Reformatted code using intellij
+//
+/* $Log: Header.java,v $
+/* Revision 1.7 2003/03/26 23:29:48 martin
+/* Changed email address
+/*
+/* Revision 1.6 2003/03/24 19:45:07 martin
+/* Latest 1.4 version
+/*
+/* Revision 1.4 2003/03/11 22:35:14 martin
+/* Upgraded to Java 1.4 on 11/03/03
+/*
+/* Revision 1.2.2.1 2002/02/02 14:54:35 martin
+/* Removed depredated method for 1.4
+/* */
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MButtonChanger.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MButtonChanger.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MButtonChanger.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,362 @@
+/*
+* Copyright (c) 2002 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import mseries.ui.MChangeEvent;
+import mseries.ui.MChangeListener;
+//import mseries.ui.MDateSpinnerModel;
+import mseries.ui.RollOverButton;
+import mseries.ui.MDateSpinnerModel;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Vector;
+
+/**
+ * A changer component for use in the calendar pull down
+ */
+public class MButtonChanger extends JPanel implements MDateChanger
+{
+ private JLabel date;
+ private RollOverButton down;
+ private RollOverButton up;
+ private DateFormat df = new SimpleDateFormat("MMMMM yyyy");
+ protected MDateSpinnerModel model;
+
+ private static final int DOWN = -1;
+ private static final int UP = 1;
+ private AbstractAction upAction = new UpDownAction(UP,
DateFormat.MONTH_FIELD);
+ private AbstractAction downAction = new UpDownAction(DOWN,
DateFormat.MONTH_FIELD);
+ private Calendar maxC = Calendar.getInstance();
+ private Calendar minC = Calendar.getInstance();
+ private int minMonth, minYear;
+ //private int maxYear;
+
+ protected Vector listeners = new Vector();
+ int offset;
+ MonthPopup mp = new MonthPopup();
+
+ public MButtonChanger()
+ {
+ setLayout(new BorderLayout());
+
+ down = new RollOverButton(SwingConstants.WEST);
+ down.addActionListener(downAction);
+
+ up = new RollOverButton(SwingConstants.EAST);
+ up.addActionListener(upAction);
+
+ add(down, BorderLayout.WEST);
+ add(up, BorderLayout.EAST);
+
+ minC.set(1900, 0, 1);
+ minMonth = minC.get(Calendar.MONTH);
+ minYear = minC.get(Calendar.YEAR);
+
+ maxC.set(2037, 11, 31);
+ //maxYear = maxC.get(Calendar.YEAR);
+
+ date = new JLabel("Error");
+ Font f = date.getFont();
+ String name = f.getFontName();
+ int style = (f.isItalic()) ? Font.ITALIC + Font.BOLD : Font.BOLD;
+ int size = f.getSize();
+
+ date.setFont(new Font(name, style, size));
+ date.setHorizontalAlignment(SwingConstants.CENTER);
+
+ mp.pack();
+
+ date.addMouseListener(new MouseAdapter()
+ {
+ int x, y, d;
+
+ public void mousePressed(MouseEvent e)
+ {
+ x = (MButtonChanger.this.getWidth() - mp.getWidth()) / 2;
+ x += MButtonChanger.this.getLocationOnScreen().x;
+
+ y = MButtonChanger.this.getLocationOnScreen().y;
+ d = mp.getHeight() / 7;
+ d *= 3;
+ y = (y - d > 0) ? y - d : 0;
+
+ mp.setLocationOnScreen(x, y);
+ mp.setVisible(true);
+ mp.setValue((Date) model.getValue());
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ Object x = mp.getValue();
+ if (x != null)
+ {
+ Calendar modelCalendar = Calendar.getInstance();
+ modelCalendar.setTime((Date) model.getValue());
+
+ Calendar newCalendar = Calendar.getInstance();
+ newCalendar.setTime((Date) x);
+
+ int dayOfMonth =
Math.min(newCalendar.getActualMaximum(Calendar.DAY_OF_MONTH),
modelCalendar.get(Calendar.DAY_OF_MONTH));
+ newCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+
+ model.setValue(newCalendar.getTime());
+ setDisplay(newCalendar.getTime());
+ MButtonChanger.this.notifyListeners(MChangeEvent.CHANGE);
+ }
+ mp.setVisible(false);
+ mp.dispose();
+ }
+ });
+
+ date.addMouseMotionListener(new MouseMotionAdapter()
+ {
+ Point p;
+
+ public void mouseDragged(MouseEvent e)
+ {
+ p = e.getPoint();
+
mp.setSelectedPoint(SwingUtilities.convertPoint(MButtonChanger.this, p, mp));
+ }
+ });
+ add(date, BorderLayout.CENTER);
+
+ model = new MDateSpinnerModel();
+ installKeyboardActions();
+ }
+
+ /*
+ * installs the PAGE UP and PAGE DOWN buttons with the increment specifed
+ * in months.
+ * @param advance the number of months to move forward and backwards
+ */
+ private void installKeyboardActions()
+ {
+ registerKeyboardAction(new UpDownAction(UP, DateFormat.MONTH_FIELD),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ registerKeyboardAction(new UpDownAction(DOWN, DateFormat.MONTH_FIELD),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+
+ registerKeyboardAction(new UpDownAction(UP, DateFormat.YEAR_FIELD),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, KeyEvent.SHIFT_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ registerKeyboardAction(new UpDownAction(DOWN, DateFormat.YEAR_FIELD),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, KeyEvent.SHIFT_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ }
+
+ private void setDisplay(Date value)
+ {
+ date.setText(df.format(value));
+ }
+
+ /**
+ * Class to do the increment/decrement when the buttons are pressed
+ */
+ class UpDownAction extends AbstractAction
+ {
+ int direction; // +1 = up; -1 = down
+ int step;
+
+ public UpDownAction(int direction, int step)
+ {
+ super();
+ this.step = step;
+ this.direction = direction;
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ Object val;
+
+ model.setStep(step);
+ if (direction == UP)
+ {
+ val = model.getNextValue();
+ }
+ else
+ {
+ val = model.getPreviousValue();
+ }
+ setValue((Date) val);
+ notifyListeners(MChangeEvent.CHANGE);
+ }
+ }
+
+ /**
+ * Sets the minimum date allowed
+ * @param min the minimum date
+ */
+ public void setMinimum(Date min)
+ {
+ minC.setTime(min);
+ minYear = minC.get(Calendar.YEAR);
+ minMonth = minC.get(Calendar.MONTH);
+
+ model.setMinimum(min);
+ setValue(min);
+ }
+
+ /**
+ * Sets the minimum date allowed
+ * @param max the minimum date
+ */
+ public void setMaximum(Date max)
+ {
+ maxC.setTime(max);
+ //maxYear = maxC.get(Calendar.YEAR);
+
+ model.setMaximum(max);
+ setValue(max);
+ }
+
+ /**
+ * Sets the value
+ * @param newVal the new value
+ */
+ public void setValue(Date newVal)
+ {
+ Calendar valC = Calendar.getInstance();
+ valC.setTime(newVal);
+
+ model.setValue(newVal);
+ mp.setValue(newVal);
+ setDisplay(newVal);
+ }
+
+ /**
+ * Returns the value
+ * @return the number of months since the minimum date
+ */
+ public int getValue()
+ {
+ Calendar valC = Calendar.getInstance();
+ valC.setTime((Date) model.getValue());
+ int y = valC.get(Calendar.YEAR);
+ int m = valC.get(Calendar.MONTH);
+
+ int newValue = (y - minYear) * 12 + m - minMonth;
+ return newValue;
+ }
+
+ public void addMChangeListener(MChangeListener l)
+ {
+ listeners.addElement(l);
+ }
+
+ public void removeMChangeListener(MChangeListener l)
+ {
+ listeners.removeElement(l);
+ }
+
+ /**
+ * Does anything within the component have the focus
+ * @return true if any child component has the focus
+ */
+ public boolean hasFocus()
+ {
+ return up.hasFocus() || down.hasFocus();
+ }
+
+ /**
+ * Adds the focus listener by delegating to each child component
+ * addFocusListener method.
+ */
+ public void addFListener(FocusListener l)
+ {
+ up.addFocusListener(l);
+ down.addFocusListener(l);
+ }
+
+ /**
+ * Removes the focusListner from the child components
+ */
+ public void removeFListener(FocusListener l)
+ {
+ up.removeFocusListener(l);
+ down.removeFocusListener(l);
+ }
+
+ private void notifyListeners(int type)
+ {
+ Vector list = (Vector) listeners.clone();
+ for (int i = 0; i < list.size(); i++)
+ {
+ MChangeListener l = (MChangeListener) listeners.elementAt(i);
+ l.valueChanged(new MChangeEvent(this, new Integer(getValue()),
type));
+ }
+ }
+
+/*
+ public static void main(String[] argv)
+ {
+ try
+ {
+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ }
+ catch(Exception e)
+ {
+ }
+
+ JFrame f = new JFrame("Test");
+ final MButtonChanger c = new MButtonChanger();
+
+ f.getContentPane().add(c);
+
+ f.pack();
+ f.show();
+ }
+*/
+}
+
+// $Log: MButtonChanger.java,v $
+// Revision 1.14 2005/02/01 20:37:47 martin
+// Deleted some unnecessary variables
+//
+// Revision 1.13 2005/02/01 20:15:22 martin
+// *** empty log message ***
+//
+// Revision 1.11 2003/08/22 21:52:45 martin
+// no message
+//
+// Revision 1.10 2003/03/26 23:29:48 martin
+// Changed email address
+//
+// Revision 1.9 2002/08/17 20:01:52 martin
+// Reformatted the code
+//
+// Revision 1.8 2002/07/22 20:06:24 martin
+// Added some comments
+//
+// Revision 1.7 2002/07/21 17:30:57 martin
+// no message
+//
+// Revision 1.6 2002/07/21 17:29:27 martin
+// Removed getGUI, setFground and setBground methods
+//
+// Revision 1.5 2002/07/21 16:24:40 martin
+// no message
+//
+// Revision 1.4 2002/07/18 21:43:49 martin
+// no message
+//
+// Revision 1.3 2002/07/17 21:32:35 martin
+// no message
+//
+// Revision 1.2 2002/06/18 21:32:29 martin
+// no message
+//
+// Revision 1.1 2002/06/16 21:48:12 martin
+// new file
+//
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateChanger.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateChanger.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateChanger.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,73 @@
+/*
+* Copyright (c) 2001 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import mseries.ui.MChangeListener;
+
+import java.awt.event.FocusListener;
+import java.util.Date;
+
+public interface MDateChanger
+{
+
+ public static final int SCROLLBAR=2;
+ public static final int SPINNER=3;
+ public static final int BUTTON=4;
+ public static final int NONE=5;
+
+ public void setOpaque(boolean opaque);
+
+ public void setEnabled(boolean enabled);
+
+ public void setMinimum(Date min);
+
+ public void setMaximum(Date min);
+
+ public void setValue(Date min);
+
+ public boolean hasFocus();
+
+ /**
+ * @return the number of months since the minimum
+ */
+ public int getValue();
+
+ public void addMChangeListener(MChangeListener l);
+
+ public void removeMChangeListener(MChangeListener l);
+
+ /** Adds a focus listener, using the method addFocusListener causes a
+ * NullPointerException for some reason.
+ * @param l a FocusListener
+ */
+ public void addFListener(FocusListener l);
+
+ /** Removes a focus listener, using the method removeFocusListener causes a
+ * NullPointerException for some reason
+ * @param l a FocusListener
+ */
+ public void removeFListener(FocusListener l);
+}
+// $Log: MDateChanger.java,v $
+// Revision 1.7 2004/08/29 17:10:58 martin
+// *** empty log message ***
+//
+// Revision 1.6 2003/03/26 23:29:48 martin
+// Changed email address
+//
+// Revision 1.5 2003/01/10 18:07:50 martin
+// *** empty log message ***
+//
+
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateDisplay.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateDisplay.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateDisplay.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,94 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.text.*;
+import java.util.*;
+
+import javax.swing.*;
+
+
+/**
+ Date entry widget with built in Formatter/Parser and Calendar popup to
+ facilitate input. The earliest and latest possible values may be set using
+ the setMinimum and setMaximum methods, this causes the calendar popup to
+ allow date within the range to be selected. Dates outside of the range may
+ be entered by typing directly into the field.
+*/
+public class MDateDisplay extends JTextField implements MMonthListener
+{
+ Date date;
+ Date minDate=null;
+ Date maxDate=null;
+
+ DateFormat shortFormatter = DateFormat.getDateInstance();
+
+
+ public MDateDisplay(int text)
+ {
+ super(text);
+ initialise();
+ }
+
+ public MDateDisplay()
+ {
+ initialise();
+ }
+
+ public void dataChanged(MMonthEvent e)
+ {
+
+ if ((e.getType() == MMonthEvent.NEW_DATE)
+ || (e.getType() == MMonthEvent.NEW_MONTH)
+ || (e.getType() == MMonthEvent.SELECTED))
+ {
+ setValue(e.getNewDate().getTime());
+ }
+
+ }
+
+ private void initialise()
+ {
+ }
+
+ /** Sets the earliest value that may be selected for this field when
+ * the poup calendar in invoked. The default is 1 January 1900
+ * @param date, the ealiest date
+ */
+ public void setMinimum(Date date)
+ {
+ minDate=date;
+ }
+
+ /** Sets the latest value that may be selected for this field when
+ * the poup calendar in invoked. The default is 31 December 2037
+ * @param date, the latest date
+ */
+ public void setMaximum(Date date)
+ {
+ maxDate=date;
+ }
+
+ public Date getValue() throws ParseException
+ {
+ date = shortFormatter.parse(getText());
+ return date;
+ }
+
+ public void setValue(Date date)
+ {
+ setText(date==null ? "" : shortFormatter.format(date));
+ }
+}
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateOutOfRangeException.java
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateOutOfRangeException.java
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateOutOfRangeException.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.util.Date;
+
+public class MDateOutOfRangeException extends Exception
+{
+ Date date;
+
+ public MDateOutOfRangeException(Date date)
+ {
+ this.date = date;
+ }
+
+ public Date getDate()
+ {
+ return date;
+ }
+}
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelector.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelector.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelector.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,362 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.ResourceBundle;
+
+/**
+ * The controller for the DateSelector. This class is the programming
interface and should
+ * be the only class in the package of which knowledge is needed in order to
use the
+ * MDateSelector.
+ */
+public class MDateSelector implements ActionListener, MMonthListener
+{
+
+ protected Color[] background;
+ protected Color[] foreground;
+ private MDateSelectorUI view;
+ private MDateSelectorPanel panel;
+ private Date today, minDate, maxDate;
+ private Date returnDate;
+ private boolean cancelled;
+ private DateFormat ddf;
+ private ResourceBundle rb = null;
+ private int firstDay = 1;
+ private String imageFile;
+ private int style = MDateChanger.SCROLLBAR;
+
+
+ MDateSelectorConstraints constraints = new MDefaultPullDownConstraints();
+
+ public MDateSelector(Date min, Date max)
+ {
+ this.minDate=min;
+ this.maxDate=max;
+ today = new Date();
+ background = new Color[7];
+ foreground = new Color[7];
+ }
+
+ /**
+ * Gets a panel which is a self contained component to represent the
calendar grid and
+ * scrollbar, defaults to current date
+ * @return a MDateSelectorPanel
+ */
+ public MDateSelectorPanel getDisplay()
+ {
+ return getDisplay(today);
+ }
+
+ /**
+ * @deprecated use setConstraints and a constraints object instead
+ */
+ public void setImageFile(String imageFile)
+ {
+ this.imageFile = imageFile;
+ }
+
+ /**
+ * @deprecated use setConstraints and a constraints object instead
+ */
+ public void setForeground(int day, Color color)
+ {
+ foreground[day - 1] = color;
+ }
+
+ /**
+ * @deprecated use setConstraints and a constraints object instead
+ */
+ public void setBackground(int day, Color color)
+ {
+ background[day - 1] = color;
+
+ }
+
+ /**
+ * Sets the constraints object that contains the parameters used to
configure the
+ * pop up calendar
+ * @param c the constraints object
+ * @see #getConstraints
+ */
+ public void setConstraints(MDateSelectorConstraints c)
+ {
+ this.constraints = c;
+ }
+
+ /**
+ * Gets the constraints object that contains the parameters used to
configure the
+ * pop up calendar
+ * @see #setConstraints
+ */
+ public MDateSelectorConstraints getConstraints()
+ {
+ return this.constraints;
+ }
+
+ /**
+ * Gets a panel which is a self contained component to represent the
calendar grid and
+ * scrollbar
+ * @param date the date to display in the calendar
+ * @return a MDateSelectorPanel
+ */
+ public MDateSelectorPanel getDisplay(Date date)
+ {
+ this.returnDate = date;
+ Date inDate;
+ if (date == null)
+ {
+ inDate = today;
+ }
+ else
+ {
+ inDate = new Date(date.getTime());
+ }
+ if (panel == null)
+ {
+ panel = new MDateSelectorPanel(true, minDate, maxDate);
+ panel.setPullDownConstraints(constraints);
+ panel.setFocusCycleRoot(false);
+ panel.setDate(inDate);
+ }
+ return panel;
+ }
+
+
+ /**
+ * @deprecated use setConstraints and a constraints object instead
+ */
+ public void setChangerStyle(int style)
+ {
+ this.style = style;
+ }
+
+ /**
+ * @deprecated use setConstraints and a constraints object instead
+ */
+ public int getChangerStyle()
+ {
+ return this.style;
+ }
+
+ /** Makes the calendar visible
+ * @param parent the parent or container
+ * @param pnt the position of the popup in the container
+ * @param date the initial date to display
+ */
+ public void show(Component parent, Point pnt, Date date)
+ {
+ showSelector(parent, pnt, date);
+ }
+
+ private void showSelector(Component parent, Point pnt, Date date)
+ {
+ JFrame f;
+ int x = 0;
+ int y = 0;
+ returnDate = date;
+ // Find the frame that is the parent of the component so
+ // that the dialog can be hooked up with it
+ Object frame = parent;
+
+ while (!(frame instanceof JFrame))
+ {
+ x += ((Component) frame).getBounds().x;
+ y += ((Component) frame).getBounds().y;
+ frame = ((Component) frame).getParent();
+ }
+
+ f = (JFrame) frame;
+ // Construct the view
+ if (panel == null)
+ {
+ panel = getDisplay(date);
+ panel.addMMonthListener(this);
+ }
+ if (view == null)
+ {
+ view = new MDateSelectorUI(f, panel, this,
constraints.getResourceBundle(), ddf, constraints.getImageFile());
+ view.pack();
+ }
+ //panel.setMinimum(minDate);
+ //panel.setMaximum(maxDate);
+ view.setTitle(constraints.getPopupTitle());
+ // Get the default (size &) position, change it to the mouse
+ // clicked position
+ Rectangle r = view.getBounds();
+ r.x = pnt.x + f.getBounds().x + x;
+ r.y = pnt.y + f.getBounds().y + y;
+
+
+ // Get the size of the window so we can check for popup going
+ // out of bounds.
+
+ Toolkit t = Toolkit.getDefaultToolkit();
+ Dimension screen = t.getScreenSize();
+
+ if (r.x + r.width > screen.width)
+ r.x = screen.width - r.width;
+
+ if (r.y + r.height > screen.height)
+ r.y = screen.height - r.height;
+
+ view.setBounds(r);
+
+ view.setVisible(true);
+ }
+
+ /**
+ * Sets the minimum date value allowed
+ * @param min the earliest possible date
+ */
+ public void setMinimum(Date min)
+ {
+ minDate = min;
+ }
+
+ /**
+ * Sets the maximum date value allowed
+ * @param max the earliest possible date
+ */
+ public void setMaximum(Date max)
+ {
+ maxDate = max;
+ }
+
+ /**
+ * The first column on the calendar grid shows the dates for
+ * the day passed here.
+ * @param firstDay a day constant from java.util.Calendar such as
Calendar.SUNDAY
+ * @deprecated use setConstraints and a constraints object instead
+ */
+ public void setFirstDay(int firstDay)
+ {
+ this.firstDay = firstDay;
+ }
+
+ /**
+ * The ResourceBundle passed should be able to localize the strings on
the
+ * button labels and calendar day headings, defaults are provided.
+ * @param rb a ResourceBundle to do the localization
+ * @deprecated use setConstraints and a constraints object instead
+ */
+ public void setTextLocalizer(ResourceBundle rb)
+ {
+ this.rb = rb;
+ }
+
+ /**
+ * The passed date format object is used to format the date displayed at
the top
+ * of the calendar popup
+ * @param userDf a DateFormat object configured to format as required
+ */
+ public void setDateFormatter(DateFormat userDf)
+ {
+ this.ddf = userDf;
+ }
+
+
+ /** Reacts to all changes in the data model (MMonth) which is given
+ * by the event type.
+ * from mseries.utils.MMonthListener interface
+ */
+ public void dataChanged(MMonthEvent e)
+ {
+ //Point pnt;
+ //Calendar date = e.getNewDate();
+ switch (e.getType())
+ {
+ case MMonthEvent.SELECTED:
+ if (view != null) view.setVisible(false);
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ cancelled = false;
+ String command = event.getActionCommand();
+ if (command.equals("today"))
+ {
+ panel.setDMY(today);
+ }
+ if (command.equals("ok"))
+ {
+ // return with the selected date from the model
+ view.setVisible(false);
+ }
+ if (command.equals("cancel"))
+ {
+ // return with the date as passed in
+ cancelled = true;
+ view.setVisible(false);
+ }
+ }
+
+ /**
+ * Returns the currently selected date value
+ * @return the date selected
+ */
+ public Date getValue()
+ {
+ if (cancelled)
+ {
+ return returnDate;
+ }
+ else
+ {
+ return panel.getDate();
+ }
+ }
+}
+
+// $Log: MDateSelector.java,v $
+// Revision 1.12 2003/10/04 10:42:52 martin
+// *** empty log message ***
+//
+// Revision 1.11 2003/10/04 09:41:40 martin
+// *** empty log message ***
+//
+// Revision 1.10 2003/10/03 20:00:04 martin
+// *** empty log message ***
+//
+// Revision 1.9 2003/08/22 18:00:53 martin
+// *** empty log message ***
+//
+// Revision 1.8 2003/08/22 17:32:47 martin
+// *** empty log message ***
+//
+// Revision 1.7 2003/03/26 23:29:48 martin
+// Changed email address
+//
+// Revision 1.6 2002/08/17 20:45:19 martin
+// Reformatted with intellij
+//
+// Revision 1.5 2002/08/17 20:40:25 martin
+// Added call to new cosntructor of MDateSelectorPanel with lazy attribute
+//
+// Revision 1.4 2002/03/03 10:07:31 martin
+// Removed "Use MDateFormat throughout" changes
+//
+// Revision 1.3 2002/03/03 09:33:41 martin
+// Use MDateFormat throughout
+//
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorConstraints.java
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorConstraints.java
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorConstraints.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,146 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+
+package mseries.Calendar;
+
+import java.awt.*;
+import java.util.ResourceBundle;
+
+/**
+* The calendar panel, popup and pull down is configured using a constraints
+* object that implements this interface. Applications will probably build
+* an immutable implementaion so that all instances appear and behave the
same.
+* @see mseries.Calendar.MDefaultPullDownConstraints
+*/
+
+public interface MDateSelectorConstraints
+{
+ /** @return the title for the popup window */
+ public String getPopupTitle();
+
+ /** @return the resource bundle for the localisation */
+ public ResourceBundle getResourceBundle();
+
+ /** @return the index of the day that should be displayed first, use DAY
constants
+ * from java.util.Calendar
+ * @see java.util.Calendar
+ */
+ public int getFirstDay();
+
+ /** @return the full path name of the image file for the background */
+ public String getImageFile();
+
+ /** @return the default foreground */
+ public Color getForeground();
+
+ /** @return the default background */
+ public Color getBackground();
+
+ /** @return the colour of the current date foreground */
+ public Color getTodayForeground();
+
+ /** @return the colour of the current date background, the background
+ * in only drawn when no image file has been set */
+ public Color getTodayBackground();
+
+ public Font getFont();
+
+ /** @return an array of colors, each not null value is the colour for the
+ * foreground for the day of the week represented by the index.
+ * 0 is Sunday, 6 is Saturday. Null entries will inherit the
+ * foreground given by getForeground()
+ */
+ public Color[] getForegrounds();
+
+ /** @return an array of colors, each not null value is the colour for the
+ * background for the day of the week represented by the index.
+ * 0 is Sunday, 6 is Saturday. Null entries will inherit the
+ * background given by getBackground()
+ */
+ public Color[] getBackgrounds();
+
+ /** @return the style of changer given by MDateChanger */
+ public int getChangerStyle();
+
+ /** @return true if the changer can be edited by the keyboard (if
appropriate).
+ * For now, only the Spinner can be edited.
+ */
+ public boolean isChangerEditable();
+
+ public Dimension getCellSize();
+
+ /**
+ * @return true if the lightweight popup is to have a shadow. Heavyweights
+ * never have shadows. Heavyweights over lap their parents boundaries.
+ */
+ public boolean hasShadow();
+
+ /** @return the number of mouse clicks required to select a date in the
+ * calendar
+ */
+ public int getSelectionClickCount();
+
+ /** @return true if the selection in the calendar causes events to be
fired.
+ * <p>
+ * Usually the date is echoed by catching the events, so the date in the
+ * textfield changes as the user moves through the calendar using the TAB
+ * and arrow keys. Switching the events off causes the textfield to remain
+ * unchanged until (perhaps) the clanedar is dismissed. A value of false
+ * makes the ESCAPE and RETURN/ENTER keys more effective for the pull
+ * down calendar. In this mode, ESC will cause the value in the date field
+ * to remain unchanged regardless of the setting in the calendar.
+ * RETURN/ENTER selects the value.
+ */
+ public boolean isSelectionEventsEnabled();
+
+ /**
+ * @return a model that can supply the colours representing Special Days
+ */
+ public SpecialDayModel getSpecialDayModel();
+
+ /**
+ * @return the foreground color for out of range cells
+ */
+ public Color getOutOfRangeForeground();
+
+ /**
+ * @return the background color for out of range cells
+ */
+ public Color getOutOfRangeBackground();
+
+}
+/* $Log: MDateSelectorConstraints.java,v $
+/* Revision 1.11 2004/01/31 19:30:13 martin
+/* Make Spinner changer allow editable spinner fields, change provided my
Maarten Coene
+/*
+/* Revision 1.10 2003/10/04 10:39:06 martin
+/* *** empty log message ***
+/*
+/* Revision 1.9 2003/10/04 09:41:40 martin
+/* *** empty log message ***
+/*
+/* Revision 1.8 2003/08/22 18:00:53 martin
+/* *** empty log message ***
+/*
+/* Revision 1.7 2003/03/26 23:29:48 martin
+/* Changed email address
+/*
+/* Revision 1.6 2002/02/24 12:33:26 martin
+/* A SpecialDayModel can be passed using the constraints
+/*
+/* Revision 1.5 2002/02/16 18:12:51 martin
+/* The eens to update the text field are switchable and can be disabled. This
makes the escape key more effective
+/*
+*/
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorPanel.java
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorPanel.java
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorPanel.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,923 @@
+
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+import mseries.ui.*;
+
+/**
+ * A calender component that shows one month at a time with controls to
change the month
+ * and year. The parameters to the calendar, including the style of the
control are given
+ * in the MDateSelectorConstraints object that is passed. There is a default
call
+ * MDefaultPullDownConstraints that can be used or subclassed to provide a
set of application
+ * wide defaults.
+ * @see mseries.Calendar.MDateSelectorConstraints
+ */
+public class MDateSelectorPanel extends MImagePanel implements MMonthListener,
+ GridSelectionListener,
+ MChangeListener,
+ MouseListener
+{
+ private CalendarPanel calendar;
+ private MMonth dataModel;
+ private Date today = new Date();
+ private boolean hasTodayButton = false;
+ private JButton todayButton;
+
+ private boolean changerEditable;
+ private MDateChanger scrollbar;
+
+ private ResourceBundle rb;
+ private Header header;
+
+ private boolean focusCycleRoot = false;
+
+ private GridBagConstraints c;
+ private int clickCount = 2;
+ private SpecialDayModel specialDayModel = null;
+ FocusChecker fc;
+
+ public MDateSelectorPanel()
+ {
+ super(new GridBagLayout());
+ Date minDate=null, maxDate=null;
+ DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, new
Locale("en", "GB"));
+ try
+ {
+ minDate = df.parse("1/1/1900");
+ maxDate = df.parse("31/12/2037");
+ }
+ catch (ParseException pe)
+ {
+ System.out.println(pe.getMessage());
+ }
+ init(false, minDate, maxDate);
+ }
+
+ /**
+ * @param lazy set to true if it is known that the some constraints will
be set before the panel is displayed,
+ * this avoids the default constraints from being used only to get
overridden by a new set.
+ */
+ public MDateSelectorPanel(boolean lazy, Date min, Date max)
+ {
+ super(new GridBagLayout());
+ init(lazy, min, max);
+ }
+ private void init(boolean lazy, Date min, Date max)
+ {
+ this.dataModel = new MMonth(min, max);
+ dataModel.addMMonthListener(this);
+ /* The FocusChecker is a class that works out if the calendar, year
spinner or
+ * month spinner have the focus, if non have it calls a method on the
dataModel
+ */
+ fc = new FocusChecker();
+ fc.setAction(new MDSAction()
+ {
+ public void doAction()
+ {
+ dataModel.lostFocus();
+ }
+ });
+
+ c = new GridBagConstraints();
+ header = new Header(dataModel.getColumnCount());
+
+ /* Set table attributes */
+ calendar = new CalendarPanel();
+ calendar.setModel(dataModel);
+ //calendar.setSpecialModel(new DefaultSpecialDayModel());
+ registerListeners();
+ setColours(calendar);
+
+ if (!lazy)
+ {
+ setPullDownConstraints(new MDefaultPullDownConstraints());
+ }
+ }
+
+ /**
+ * Sets the style of changer for the month & year, implementations
include COMBOBOX/SPINNER
+ * and a scrollbar
+ * @see mseries.Calendar.MDateChanger
+ * @param style a constant from MDateChanger
+ */
+ protected void setChangerStyle(int style)
+ {
+ removeAll();
+
+ /* Place all components on the GUI */
+ c.insets = new Insets(0, 0, 4, 0);
+ c.gridx = 0;
+ c.gridy = 0;
+ c.gridwidth = 1;
+ c.gridheight = 1;
+ c.weightx = 0.0;
+ c.weighty = 0.0;
+ c.gridy = GridBagConstraints.RELATIVE;
+ c.anchor = GridBagConstraints.CENTER;
+
+
+ switch (style)
+ {
+ case MDateChanger.BUTTON:
+ scrollbar = new MButtonChanger();
+
+ c.fill = GridBagConstraints.BOTH;
+ add((Component) scrollbar, c);
+
+ c.fill = GridBagConstraints.NONE;
+ add(header, c);
+
+ c.fill = GridBagConstraints.NONE;
+ add(calendar, c);
+
+ scrollbar.addFListener(fc);
+ fc.addComponent(scrollbar);
+
+ break;
+ case MDateChanger.SPINNER:
+ scrollbar = new MSpinnerChanger(this.changerEditable);
+
+ c.fill = GridBagConstraints.BOTH;
+ add((Component) scrollbar, c);
+
+ c.fill = GridBagConstraints.NONE;
+ add(header, c);
+
+ c.fill = GridBagConstraints.NONE;
+ add(calendar, c);
+
+ scrollbar.addFListener(fc);
+ fc.addComponent(scrollbar);
+
+ break;
+ case MDateChanger.NONE:
+ c.fill = GridBagConstraints.NONE;
+ add(header, c);
+ c.fill = GridBagConstraints.NONE;
+ add(calendar, c);
+ break;
+
+ case MDateChanger.SCROLLBAR:
+ default:
+ scrollbar = new MScrollBarChanger();
+
+ c.fill = GridBagConstraints.BOTH;
+ add(header, c);
+ c.fill = GridBagConstraints.NONE;
+ add(calendar, c);
+ c.fill = GridBagConstraints.BOTH;
+ add((Component) scrollbar, c);
+
+ break;
+
+ }
+ /* Set the scrollbars attributes */
+ scrollbar.setMinimum(dataModel.getMinimum());
+ scrollbar.setMaximum(dataModel.getMaximum());
+ scrollbar.setValue(dataModel.getCurrentDate());
+
+ /* Set up listeners for the buttons, scrollbar, keyboard etc. */
+ scrollbar.addMChangeListener(this);
+
+ setDate(new Date());
+ setColours(this);
+ scrollbar.setOpaque(false);
+
+ if (getShowTodayButton())
+ {
+ todayButton = new JButton(rb.getString("Today"));
+ todayButton.addFocusListener(fc);
+ fc.addComponent(todayButton);
+
+ todayButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ setDMY(today);
+ if (MDateSelectorPanel.this.getCloseOnToday())
+ {
+ close("CLOSE");
+ }
+ }
+ });
+
+ c.fill = GridBagConstraints.NONE;
+ add(todayButton, c);
+ }
+
+ }
+
+ public void requestFocus()
+ {
+ calendar.requestFocus();
+ }
+
+ public void setEnabled(boolean enabled)
+ {
+ super.setEnabled(enabled);
+ calendar.setEnabled(enabled);
+ scrollbar.setEnabled(enabled);
+ }
+
+ /**
+ * Sets the resource bundle for the day labels
+ * @param rb resource bundle
+ */
+ public void setTextLocalizer(ResourceBundle rb)
+ {
+ this.rb = rb;
+ header.setTextLocalizer(rb);
+ }
+
+ /**
+ * @return the resource bundle
+ */
+ public ResourceBundle getTextLocalizer()
+ {
+ return this.rb;
+ }
+
+ /**
+ * Sets the minimum date value allowed
+ * @param min the earliest possible date
+ */
+ public void setMinimum(Date min)
+ {
+ dataModel.setMinimum(min);
+ }
+
+ /** Returns the earliest possible date that can be displayed
+ * @return earliest date
+ */
+ public Date getMinimum()
+ {
+ return dataModel.getMinimum();
+ }
+
+ /**
+ * Sets the maximum date value allowed
+ * @param max the earliest possible date
+ */
+ public void setMaximum(Date max)
+ {
+ dataModel.setMaximum(max);
+ }
+
+ /** Returns the latest possible date that can be displayed
+ * @return latest date
+ */
+ public Date getMaximum()
+ {
+ return dataModel.getMaximum();
+ }
+
+ private boolean closeOnToday = true;
+
+ public void setCloseOnToday(boolean close)
+ {
+ this.closeOnToday = close;
+ }
+
+ public boolean getCloseOnToday()
+ {
+ return closeOnToday;
+ }
+
+ public void setShowTodayButton(boolean show)
+ {
+ this.hasTodayButton = show;
+ }
+
+ public boolean getShowTodayButton()
+ {
+ return hasTodayButton;
+ }
+
+ /**
+ *
+ * Sets the date in the calendar
+ * @param date the date to set
+ */
+ public void setDate(Date date)
+ {
+ try
+ {
+ dataModel.setDate(date);
+ }
+ catch (MDateOutOfRangeException e)
+ {
+ try
+ {
+ dataModel.setDate(dataModel.getMinimum());
+ }
+ catch (MDateOutOfRangeException ex)
+ {
+ }
+ }
+ }
+
+ /**
+ * Sets a value in the component and does not change the time elements.
This method
+ * would be used when a specific date is generated and only the Day,
Month, Year are
+ * really needed along with the time that the component already had.
+ * @param date the new date
+ */
+ public void setDMY(Date date)
+ {
+ try
+ {
+ dataModel.setDMY(date);
+ }
+ catch (MDateOutOfRangeException e)
+ {
+ try
+ {
+ dataModel.setDate(dataModel.getMinimum());
+ }
+ catch (MDateOutOfRangeException ex)
+ {
+ }
+ }
+ }
+
+ /**
+ * Returns the currently selected date value
+ * @return the date selected
+ */
+ public Date getDate()
+ {
+ return dataModel.getCurrentDate();
+ }
+
+ /**
+ * The first column on the calendar grid shows the dates for
+ * the day passed here.
+ * @param firstDay a day constant from java.util.Calendar such as
Calendar.SUNDAY
+ */
+ public void setFirstDay(int firstDay)
+ {
+ header.setFirstDay(firstDay);
+ dataModel.setFirstDay(firstDay);
+ }
+
+ /**
+ * @return the index of the first day in the first column
+ */
+ public int getFirstDay()
+ {
+ return dataModel.getFirstDay();
+ }
+
+ /**
+ * Registers objects that are to listen to events from the DateSelector
+ * Event types of NEW_DATE and NEW_MONTH indicate that the value has
changed
+ * @param l an MMonthListener
+ */
+ public void addMMonthListener(MMonthListener l)
+ {
+ dataModel.addMMonthListener(l);
+ }
+
+ /**
+ * De-Registers objects that are to listen to events from the
DateSelector
+ * @param l an MMonthListener
+ */
+ public void removeMMonthListener(MMonthListener l)
+ {
+ dataModel.removeMMonthListener(l);
+ }
+
+ /**
+ * Sets the display attributes for the pull down calendar
+ * @param c an instance of MDateSelectorConstraints that contains
+ * the desired settings.
+ */
+ public void setPullDownConstraints(MDateSelectorConstraints c)
+ {
+ ResourceBundle rb = c.getResourceBundle();
+ this.changerEditable = c.isChangerEditable();
+ setChangerStyle(c.getChangerStyle());
+ if (rb != null)
+ {
+ try
+ {
+ setTextLocalizer(rb);
+ }
+ catch (Exception e)
+ {
+ System.out.println(e.toString());
+ }
+ }
+ int firstDay = c.getFirstDay();
+ if (firstDay > 0 && firstDay < 8)
+ {
+ setFirstDay(firstDay);
+ }
+ Color[] foregrounds = c.getForegrounds();
+ if (foregrounds != null)
+ {
+ setForeground(foregrounds);
+ }
+ Color[] backgrounds = c.getBackgrounds();
+ if (backgrounds != null)
+ {
+ setBackground(backgrounds);
+ }
+ Color foreground = c.getForeground();
+ if (foreground != null)
+ {
+ setForeground(foreground);
+ }
+ Color background = c.getBackground();
+ if (background != null)
+ {
+ setBackground(background);
+ }
+ String imageFile = c.getImageFile();
+ if (imageFile != null)
+ {
+ setImageFile(imageFile);
+ }
+
+ Dimension cellSize = c.getCellSize();
+ if (cellSize != null)
+ {
+ setCellSize(cellSize);
+ }
+
+ foreground = c.getTodayForeground();
+ if (foreground != null)
+ {
+ calendar.setTodayForeground(foreground);
+ }
+
+ background = c.getTodayBackground();
+ if (background != null)
+ {
+ calendar.setTodayBackground(background);
+ }
+ foreground = c.getOutOfRangeForeground();
+ if (foreground != null)
+ {
+ calendar.setOutOfRangeForeground(foreground);
+ }
+
+
+ background = c.getOutOfRangeBackground();
+ if (background != null)
+ {
+ calendar.setOutOfRangeBackground(background);
+ }
+
+ clickCount = c.getSelectionClickCount();
+
+ specialDayModel = c.getSpecialDayModel();
+ if (specialDayModel != null)
+ {
+ calendar.setSpecialModel(specialDayModel);
+ }
+ Font font = c.getFont();
+ if (font != null)
+ {
+ setFont(font);
+ }
+
+ }
+
+
+ /* ----------- Methods required for interfaces ----------- */
+
+ /** Captures changes in the currently selected cell and sets the current
+ * date in the data model
+ * from com.java.swing.event.ListSelectionListener
+ */
+ public void gridCellChanged(GridSelectionEvent e)
+ {
+ if (e.isExitEvent())
+ {
+ dataModel.exitEvent();
+ }
+ else
+ {
+ try
+ {
+ dataModel.setCurrentDate(e.getY(), e.getX());
+ }
+ catch (MDateOutOfRangeException ex)
+ {
+ }
+ }
+ }
+
+ /** Reacts to all changes in the data model (MMonth) which is given
+ * by the event type.
+ * from mseries.utils.MMonthListener interface
+ */
+ public void dataChanged(MMonthEvent e)
+ {
+ Point pnt;
+ Calendar date = e.getNewDate();
+
+ switch (e.getType())
+ {
+ case MMonthEvent.NEW_MIN:
+ scrollbar.setMinimum(dataModel.getMinimum());
+ scrollbar.setValue(dataModel.getCurrentDate());
+ break;
+ case MMonthEvent.NEW_MAX:
+ scrollbar.setMaximum(dataModel.getMaximum());
+ scrollbar.setValue(dataModel.getCurrentDate());
+ break;
+ case MMonthEvent.NEW_DATE:
+ pnt = dataModel.getCurrentPoint();
+ calendar.setCurrentDate(pnt);
+ break;
+ case MMonthEvent.NEW_RB:
+ break;
+ case MMonthEvent.NEW_FIRST_DAY:
+ header.repaint();
+ //break;
+ case MMonthEvent.NEW_MONTH:
+
+ // Tell the table the data has changed
+ calendar.tableChanged();
+ // Reset the scrollbar
+ scrollbar.setValue(date.getTime());
+
+ pnt = dataModel.getCurrentPoint();
+ calendar.setCurrentDate(pnt);
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Sets the background image, if set the background color is ignored
+ * @param imageFile the image file, usual Java file types (.jpg, .gif,
etc)
+ * are supported.
+ */
+ public void setImageFile(String imageFile)
+ {
+ super.setImageFile(imageFile);
+ calendar.setHasImage(hasImage());
+ calendar.tableChanged();
+ calendar.requestFocus();
+ repaint();
+ }
+
+ /**
+ * for MChangeListener
+ */
+ public void valueChanged(MChangeEvent event)
+ {
+ int increment = getDateValue();
+ switch (event.getType())
+ {
+ case MChangeEvent.EXIT:
+ dataModel.exitEvent();
+ break;
+ case MChangeEvent.CHANGE:
+ try
+ {
+ dataModel.addToMin(increment);
+ }
+ catch (MDateOutOfRangeException e)
+ {
+ }
+ }
+ }
+
+ private void registerListeners()
+ {
+ addMouseListener(new MouseAdapter(){
+ });
+ calendar.addMouseListener(this);
+ calendar.addGridSelectionListener(this);
+ calendar.addFocusListener(fc);
+ fc.addComponent(calendar);
+ }
+
+ public void mouseClicked(MouseEvent event)
+ {
+ if (event.getClickCount() == clickCount)
+ {
+ dataModel.exitEvent();
+ }
+ }
+
+ public void mouseEntered(MouseEvent event)
+ {
+ }
+
+ public void mouseExited(MouseEvent event)
+ {
+ }
+
+ public void mousePressed(MouseEvent event)
+ {
+ }
+
+ public void mouseReleased(MouseEvent event)
+ {
+ }
+
+ private int getDateValue()
+ {
+ return scrollbar.getValue();
+ }
+
+ protected void setColours(Component c)
+ {
+ c.setBackground(getBackground());
+ c.setForeground(getForeground());
+ }
+
+ /**
+ * Set the foreground colour
+ */
+ public void setForeground(Color foreground)
+ {
+ super.setForeground(foreground);
+ updateComponentColours(this);
+ }
+
+ /**
+ * Set the background colour
+ */
+ public void setBackground(Color background)
+ {
+ super.setBackground(background);
+ updateComponentColours(this);
+ }
+
+ /*
+ * Recurse through the components on the panel setting the
+ * colours
+ */
+ private void updateComponentColours(Container c)
+ {
+ Component[] children = c.getComponents();
+
+ for (int i = 0; i < children.length; i++)
+ {
+ setColours(children[i]);
+ }
+ }
+
+ public void setFont(Font font)
+ {
+ super.setFont(font);
+ Component[] children = getComponents();
+
+ for (int i = 0; i < children.length; i++)
+ {
+ setComponentFont(children[i]);
+ }
+ }
+
+ public void setComponentFont(Component c)
+ {
+ c.setFont(getFont());
+ if (c instanceof java.awt.Container)
+ {
+ Component[] children = ((Container) c).getComponents();
+
+ for (int i = 0; i < children.length; i++)
+ {
+ children[i].setFont(getFont());
+ setComponentFont(children[i]);
+ }
+ }
+ }
+
+ /**
+ * Sets the foreground color for the column representing the day given.
+ * @param day a number in the range 1 - 7 from SUNDAY - SATURDAY, days
not
+ * set will assume the default foreground color
+ * @param color the color to set
+ */
+ public void setForeground(int day, Color color)
+ {
+ calendar.setForeground(day, color);
+ header.setForeground(day, color);
+ repaint();
+ }
+
+ /**
+ * Sets the background color for the column representing the day given.
+ * @param day a number in the range 1 - 7 from SUNDAY - SATURDAY, days
not
+ * set will assume the default background color
+ * @param color the color to set
+ */
+ public void setBackground(int day, Color color)
+ {
+ calendar.setBackground(day, color);
+ header.setBackground(day, color);
+ }
+
+ /**
+ * Sets the all the background colors for each day element 0 - SUNDAY, 6
- SATURDAY
+ * @param colors the array of colors to set
+ */
+ public void setBackground(Color[] colors)
+ {
+ calendar.setBackground(colors);
+ header.setBackground(colors);
+ repaint();
+ }
+
+ /**
+ * Sets the all the foreground colors for each day element 0 - SUNDAY, 6
- SATURDAY
+ * @param colors the array of colors to set
+ */
+ public void setForeground(Color[] colors)
+ {
+ calendar.setForeground(colors);
+ header.setForeground(colors);
+ repaint();
+ }
+
+ public void setCellSize(Dimension cellSize)
+ {
+ calendar.setCellSize(cellSize);
+ header.setCellSize(cellSize);
+ }
+
+ public void setFocusCycleRoot(boolean fcr)
+ {
+ focusCycleRoot = fcr;
+ }
+
+ public boolean isFocusCycleRoot()
+ {
+ return focusCycleRoot;
+ }
+
+ public void close(String command)
+ {
+ if (command.equals("CLOSE"))
+ {
+ dataModel.exitEvent();
+ }
+ else
+ {
+ dataModel.lostFocus();
+ }
+ }
+}
+
+/**
+ * Class to report when the components in its group have all lost the
+ * keyboard focus. Any number of components can participate, the action
+ * to execute when they all have lost the focus is encapsulated in the
+ * MDSAction passed in the setAction method
+ */
+class FocusChecker implements FocusListener
+{
+ Vector c = new Vector();;
+ MDSAction action = new MDSAction()
+ {
+ public void doAction()
+ {
+ }
+ };
+
+ public void addComponent(Object c)
+ {
+ this.c.add(c);
+ }
+
+ /**
+ * The action contains the behaviour that will be executed when none of
the
+ * components in the group have the keyboard focus
+ */
+ public void setAction(MDSAction action)
+ {
+ this.action = action;
+ }
+
+ public void setComponents(Vector c)
+ {
+ this.c = c;
+ }
+
+ public void focusLost(FocusEvent e)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ for (int i = 0; i < c.size(); i++)
+ {
+ JComponent comp = (JComponent) c.get(i);
+ if (comp.hasFocus())
+ {
+ return;
+ }
+ }
+ action.doAction();
+ }
+ });
+ }
+
+ public void focusGained(FocusEvent e)
+ {
+ }
+}
+
+
+interface MDSAction
+{
+ public void doAction();
+}
+
+/*
+$Log: MDateSelectorPanel.java,v $
+Revision 1.25 2004/08/29 17:10:50 martin
+*** empty log message ***
+
+Revision 1.24 2004/04/18 10:53:43 martin
+*** empty log message ***
+
+Revision 1.23 2004/01/31 19:30:13 martin
+Make Spinner changer allow editable spinner fields, change provided my Maarten
Coene
+
+Revision 1.22 2003/10/04 10:39:06 martin
+*** empty log message ***
+
+Revision 1.21 2003/10/04 09:41:40 martin
+*** empty log message ***
+
+Revision 1.20 2003/10/03 20:00:04 martin
+*** empty log message ***
+
+Revision 1.19 2003/03/26 23:29:48 martin
+Changed email address
+
+Revision 1.18 2003/03/24 19:45:07 martin
+Latest 1.4 version
+
+Revision 1.16 2003/03/11 22:37:19 martin
+Upgraded to Java 1.4 on 11/03/03
+
+Revision 1.15 2003/01/10 18:07:41 martin
+*** empty log message ***
+
+Revision 1.14 2002/08/17 20:40:00 martin
+Added new cosntructor with lazy attribute
+
+Revision 1.13 2002/07/21 17:30:57 martin
+no message
+
+Revision 1.12 2002/07/21 17:29:35 martin
+no message
+
+Revision 1.11 2002/07/21 16:24:40 martin
+no message
+
+Revision 1.10 2002/06/18 21:32:29 martin
+no message
+
+Revision 1.9 2002/06/13 19:25:06 martin
+Added closeOnToday button support
+
+Revision 1.8 2002/06/09 13:48:18 martin
+Added 'Today' button
+
+Revision 1.7 2002/02/24 12:33:26 martin
+A SpecialDayModel can be passed using the constraints
+
+Revision 1.6 2002/02/16 18:12:51 martin
+The eens to update the text field are switchable and can be disabled. This
makes the escape key more effective
+
+Revision 1.5 2002/02/16 09:48:47 martin
+Added selectionClickCount attribute
+
+Revision 1.4 2002/02/09 12:54:39 martin
+Partial support for 'Special Days'
+
+Revision 1.3 2002/02/03 12:49:09 martin
+Added support for curret date highlighted in different colour
+
+*/
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorPanelBeanInfo.java
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorPanelBeanInfo.java
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorPanelBeanInfo.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,125 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.beans.*;
+import java.awt.*;
+
+/**
+* Bean Info class for MDateSelectorPanel. Not all attributes are editable in
the
+* beanbox but most are.
+*/
+public class MDateSelectorPanelBeanInfo extends SimpleBeanInfo
+{
+ Class mdsClass = MDateSelectorPanel.class;
+
+ public Image getIcon(int kind)
+ {
+ Image image = null;
+
+ if (kind == BeanInfo.ICON_COLOR_16x16)
+ {
+ image = loadImage("calicon16.gif");
+ }
+ else if (kind == BeanInfo.ICON_COLOR_32x32)
+ {
+ image = loadImage("calicon32.gif");
+ }
+ return image;
+ }
+
+ public EventSetDescriptor[] getEventSetDescriptors()
+ {
+ EventSetDescriptor event=null;
+ try
+ {
+ event = new EventSetDescriptor(mdsClass,
+ "mMonth",
+
mseries.Calendar.MMonthListener.class,
+ "dataChanged");
+
+ }
+ catch (IntrospectionException e)
+ {
+ }
+ EventSetDescriptor[] events = {event};
+ return events;
+ }
+
+ public PropertyDescriptor[] getPropertyDescriptors()
+ {
+ try
+ {
+ PropertyDescriptor
+ date = new PropertyDescriptor("date", mdsClass),
+ foreground = new PropertyDescriptor("foreground", mdsClass),
+ background = new PropertyDescriptor("background", mdsClass),
+ db = new PropertyDescriptor("doubleBuffered", mdsClass),
+ opaque = new PropertyDescriptor("opaque", mdsClass),
+ autoscrolls = new PropertyDescriptor("autoscrolls", mdsClass),
+ alx = new PropertyDescriptor("alignmentX", mdsClass),
+ aly = new PropertyDescriptor("alignmentY", mdsClass),
+ dgo = new PropertyDescriptor("debugGraphicsOptions", mdsClass),
+ rfe = new PropertyDescriptor("requestFocusEnabled", mdsClass),
+ ps = new PropertyDescriptor("preferredSize", mdsClass),
+ maxS = new PropertyDescriptor("maximumSize", mdsClass),
+ minS = new PropertyDescriptor("minimumSize", mdsClass),
+ b = new PropertyDescriptor("border", mdsClass),
+ max = new PropertyDescriptor("maximum", mdsClass),
+ min = new PropertyDescriptor("minimum", mdsClass),
+ tl = new PropertyDescriptor("textLocalizer", mdsClass),
+ nfc = new PropertyDescriptor("nextFocusableComponent",
mdsClass),
+ fd = new PropertyDescriptor("firstDay", mdsClass),
+ image = new PropertyDescriptor("imageFile", mdsClass),
+ font = new PropertyDescriptor("font", mdsClass);
+
+
+ ps.setHidden(true);
+ maxS.setHidden(true);
+ minS.setHidden(true);
+ b.setHidden(true);
+ db.setHidden(true);
+ opaque.setHidden(true);
+ autoscrolls.setHidden(true);
+ alx.setHidden(true);
+ aly.setHidden(true);
+ dgo.setHidden(true);
+ rfe.setHidden(true);
+ nfc.setHidden(true);
+
+ date.setPropertyEditorClass(MDateValueEditor.class);
+ max.setPropertyEditorClass(MDateValueEditor.class);
+ min.setPropertyEditorClass(MDateValueEditor.class);
+ fd.setPropertyEditorClass(MFirstDayEditor.class);
+ tl.setPropertyEditorClass(MTextLocaliserEditor.class);
+/* Uncomment for custom editor
+ image.setPropertyEditorClass(MFileNameEditor.class);
+*/
+ min.setShortDescription("Minimum Value");
+ max.setShortDescription("Maximum Value");
+ date.setShortDescription("Current Value");
+
+ PropertyDescriptor[] pd = {image, date, foreground, background,
font,
+ opaque, autoscrolls, alx, aly, dgo,
rfe, db,
+ ps, maxS, minS, b, max, min, tl, nfc,
fd};
+ return pd;
+ }
+ catch (IntrospectionException e)
+ {
+ System.out.println(e.getMessage());
+ return super.getPropertyDescriptors();
+ }
+ }
+}
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorUI.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorUI.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDateSelectorUI.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,250 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import mseries.ui.MImagePanel;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.KeyEvent;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+
+/**
+* GUI for the date selector (Calendar) popup
+*/
+public class MDateSelectorUI extends JDialog implements MMonthListener
+{
+ private JTextField date;
+ private GridBagConstraints c = new GridBagConstraints();
+ private JButton okButton;
+ private JButton todayButton;
+ private JButton cancelButton;
+ private DateFormat df;
+ private ResourceBundle rb;
+
+ MImagePanel innerPanel;
+
+ public MDateSelectorUI(JFrame parent, MDateSelectorPanel panel,
MDateSelector controller,
+ ResourceBundle rb, DateFormat df, String imageFile)
+ {
+
+ super(parent, "MSeries Date Selector", true);
+
+ setResizable(false);
+
+ this.rb = rb;
+
+ if (df == null)
+ {
+ this.df=new SimpleDateFormat(System.getProperty("MDateFormat", "d
MMMMM yyyy"));
+ }
+ else
+ {
+ this.df=df;
+ }
+ innerPanel = new MImagePanel(new GridBagLayout());
+ if (imageFile!=null)
+ innerPanel.setImageFile(imageFile);
+
+ innerPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+
+ date = new JTextField("Error"){
+ public boolean isFocusable()
+ {
+ return false;
+ }
+ };
+ date.setEditable(false);
+
+ setColours(date);
+ date.setHorizontalAlignment(SwingConstants.CENTER);
+
+ c.insets=new Insets(0, 0, 4, 0);
+ c.gridx = 0;
+ c.gridy = 0;
+ c.gridwidth = 1;
+ c.gridheight = 1;
+ c.weightx = 0.0;
+ c.weighty = 0.0;
+ c.fill = GridBagConstraints.HORIZONTAL;
+
+ c.gridy = GridBagConstraints.RELATIVE;
+
+ innerPanel.add(date, c);
+ c.gridheight = 5;
+ c.gridy = 1;
+ innerPanel.add(panel, c);
+
+ c.gridheight = 1;
+ c.gridwidth = 1;
+ okButton = new JButton();
+ okButton.setActionCommand("ok");
+ //setColours(okButton);
+
+ todayButton = new JButton();
+ todayButton.setActionCommand("today");
+ //setColours(todayButton);
+
+ cancelButton = new JButton();
+ cancelButton.setActionCommand("cancel");
+ //setColours(cancelButton);
+
+ setLabels();
+
+ c.insets=new Insets(0, 4, 4, 0);
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor=GridBagConstraints.SOUTH;
+ c.weightx = 0;
+ c.gridx=1;
+ c.gridy=1;
+ innerPanel.add(okButton, c);
+
+ c.anchor=GridBagConstraints.SOUTH;
+ c.weightx = 0;
+ c.gridx=1;
+ c.gridy=2;
+ innerPanel.add(cancelButton,c);
+
+ c.anchor=GridBagConstraints.CENTER;
+ c.weightx = 0;
+ c.gridx=1;
+ c.gridy=5;
+ innerPanel.add(todayButton, c);
+
+ okButton.addActionListener(controller);
+ todayButton.addActionListener(controller);
+ cancelButton.addActionListener(controller);
+
+
+ innerPanel.registerKeyboardAction(controller, "cancel",
+ KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
+ JComponent.WHEN_IN_FOCUSED_WINDOW);
+ panel.addMMonthListener(this);
+
+ updateDate(panel.getDate());
+ getContentPane().add(innerPanel);
+
+ date.setOpaque(false);
+ cancelButton.setOpaque(false);
+ todayButton.setOpaque(false);
+ okButton.setOpaque(false);
+ getRootPane().setDefaultButton(okButton);
+ pack();
+ setSize(getMinimumSize());
+
+ }
+
+ public void setImageFile(String imageFile)
+ {
+ innerPanel.setImageFile(imageFile);
+ }
+
+ private void setLabels()
+ {
+ okButton.setText(getString("OK", "OK"));
+ cancelButton.setText(getString("Cancel", "Cancel"));
+ todayButton.setText(getString("Today", "Today"));
+ }
+
+ private String getString(String in, String def)
+ {
+ String ret;
+ if (rb == null)
+ {
+ return def;
+ }
+ try
+ {
+ ret = rb.getString(in);
+ }
+ catch(MissingResourceException e)
+ {
+ ret = def;
+ }
+ return ret;
+ }
+
+ private void updateDate(Date date)
+ {
+ this.date.setText(df.format(date));
+ }
+
+
+ /** Reacts to all changes in the data model (MMonth) which is given
+ * by the event type.
+ * from mseries.utils.MMonthListener interface
+ */
+ public void dataChanged(MMonthEvent e)
+ {
+ Calendar date = e.getNewDate();
+ switch(e.getType())
+ {
+ case MMonthEvent.NEW_DATE:
+ updateDate(date.getTime());
+ break;
+ case MMonthEvent.NEW_MONTH:
+ updateDate(date.getTime());
+ break;
+ case MMonthEvent.NEW_RB:
+ setLabels();
+ break;
+ default:
+ break;
+ }
+ }
+
+ protected void setColours(Component c)
+ {
+ c.setBackground(UIManager.getColor("control"));
+ c.setForeground(UIManager.getColor("Button.foreground"));
+ }
+
+}
+/*
+$Log: MDateSelectorUI.java,v $
+Revision 1.12 2003/10/04 09:42:24 martin
+*** empty log message ***
+
+Revision 1.11 2003/10/03 19:45:14 martin
+*** empty log message ***
+
+Revision 1.10 2003/03/26 23:29:48 martin
+Changed email address
+
+Revision 1.9 2003/03/24 19:45:07 martin
+Latest 1.4 version
+
+Revision 1.7 2003/03/11 22:35:14 martin
+Upgraded to Java 1.4 on 11/03/03
+
+Revision 1.6 2002/05/24 15:14:03 martin
+Added setSize(..) to end of constructor as pack seems not to work on ceratin
JVM in Linux
+
+Revision 1.5 2002/03/03 10:07:31 martin
+Removed "Use MDateFormat throughout" changes
+
+Revision 1.4 2002/03/03 09:33:41 martin
+Use MDateFormat throughout
+
+Revision 1.3 2002/02/16 14:21:27 martin
+Added Escape Key to dismiss the dialog
+
+*/
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDefaultPullDownConstraints.java
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDefaultPullDownConstraints.java
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MDefaultPullDownConstraints.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,210 @@
+/*
+* Copyright (c) 2001 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+/**
+* A default implementation of MDateSelectorConstraints that can be
instantiated then have
+* the attributes set. Or it can be subclassed to provide specialised system
wide defualts
+*/
+package mseries.Calendar;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Dimension;
+import java.util.ResourceBundle;
+import java.util.Calendar;
+
+/**
+* The defualt implementation of MDateSelectorConstraints
+*/
+public class MDefaultPullDownConstraints implements MDateSelectorConstraints
+{
+ public String bundleName="mseries.Calendar.DateSelectorRB";
+ public ResourceBundle rb;
+ public int firstDay=Calendar.SATURDAY;
+ public String imageFile=null;
+ public Color foreground=null;
+ public Color outOfRangeForeground=Color.gray;
+ public Color outOfRangeBackground=null;
+ public Color todayForeground=null;
+ public Color todayBackground=null;
+ public Color background=null;
+ public Font font=null;
+ public Color[] foregrounds=null;
+ public Color[] backgrounds=null;
+ public int changerStyle=MDateChanger.SCROLLBAR;
+ public Dimension cellSize;
+ public boolean hasShadow=false;
+ public int selectionClickCount=2;
+ public boolean selectionEventsEnabled=true;
+ public SpecialDayModel specialDayModel=null;
+ public String popupTitle;
+ public boolean changerEditable=false;
+
+
+ public MDefaultPullDownConstraints()
+ {
+ foregrounds=new Color[7];
+ foregrounds[0]=Color.blue;
+ foregrounds[6]=Color.blue;
+ cellSize=new Dimension(22, 20);
+ specialDayModel = new DefaultSpecialDayModel();
+ popupTitle="MSeries Date Selector";
+ }
+
+ public String getPopupTitle()
+ {
+ return popupTitle;
+ }
+
+ /** @return the resource bundle for the localisation */
+ public ResourceBundle getResourceBundle()
+ {
+ if (rb==null)
+ {
+ rb=ResourceBundle.getBundle(bundleName);
+ }
+ return rb;
+ }
+
+ /** @return the index of the day that should be displayed first, use DAY
constants
+ * from java.util.Calendar
+ * @see java.util.Calendar
+ */
+ public int getFirstDay()
+ {
+ return firstDay;
+ }
+
+ /** @return the full path name of the image file for the background */
+ public String getImageFile()
+ {
+ return imageFile;
+ }
+
+ /** @return the default foreground */
+ public Color getForeground()
+ {
+ return foreground;
+ }
+
+ /** @return the current date foreground */
+ public Color getTodayForeground()
+ {
+ return todayForeground;
+ }
+
+ /** @return the current date background */
+ public Color getTodayBackground()
+ {
+ return todayBackground;
+ }
+
+ public Color getBackground()
+ {
+ return background;
+ }
+
+ public Font getFont()
+ {
+ return font;
+ }
+
+ public Color[] getForegrounds()
+ {
+ return foregrounds;
+ }
+
+ public Color[] getBackgrounds()
+ {
+ return backgrounds;
+ }
+
+ public int getChangerStyle()
+ {
+ return changerStyle;
+ }
+
+ public Dimension getCellSize()
+ {
+ return cellSize;
+ }
+
+ public boolean hasShadow()
+ {
+ return hasShadow;
+ }
+ public int getSelectionClickCount()
+ {
+ return selectionClickCount;
+ }
+
+ public boolean isSelectionEventsEnabled()
+ {
+ return selectionEventsEnabled;
+ }
+
+ public SpecialDayModel getSpecialDayModel()
+ {
+ return specialDayModel;
+ }
+
+ public Color getOutOfRangeForeground()
+ {
+ return outOfRangeForeground;
+ }
+
+ public Color getOutOfRangeBackground()
+ {
+ return outOfRangeBackground;
+ }
+
+ public boolean isChangerEditable()
+ {
+ return changerEditable;
+
+ }
+}
+/*
+$Log: MDefaultPullDownConstraints.java,v $
+Revision 1.12 2004/01/31 19:30:13 martin
+Make Spinner changer allow editable spinner fields, change provided my Maarten
Coene
+
+Revision 1.11 2003/10/04 10:39:06 martin
+*** empty log message ***
+
+Revision 1.10 2003/10/04 09:41:40 martin
+*** empty log message ***
+
+Revision 1.9 2003/08/22 18:00:53 martin
+*** empty log message ***
+
+Revision 1.8 2003/03/26 23:29:48 martin
+Changed email address
+
+Revision 1.7 2002/02/24 12:33:26 martin
+A SpecialDayModel can be passed using the constraints
+
+Revision 1.6 2002/02/16 18:12:51 martin
+The eens to update the text field are switchable and can be disabled. This
makes the escape key more effective
+
+Revision 1.5 2002/02/16 09:49:38 martin
+fixed typo
+
+Revision 1.4 2002/02/16 09:48:47 martin
+Added selectionClickCount attribute
+
+Revision 1.3 2002/02/03 12:49:09 martin
+Added support for curret date highlighted in different colour
+
+*/
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MFieldListener.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MFieldListener.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MFieldListener.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,33 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.awt.event.FocusEvent;
+import java.util.EventListener;
+
+/** Interface to which any object must conform if it is to be informed of
+* changes to an MSeries field such as MDateEntryField.
+*<P>
+* Focus listeners can't be used as some components artificially lose and
gain the focus
+* but the component is not strictly exited. This interface should be used to
detect the user
+* entering and exiting the field
+*/
+public interface MFieldListener extends EventListener
+{
+ /** The field has recieved focus */
+ public void fieldEntered(FocusEvent event);
+ /** The field has lost focus */
+ public void fieldExited(FocusEvent event);
+}
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MFirstDayEditor.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MFirstDayEditor.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MFirstDayEditor.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,103 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.awt.*;
+import java.beans.*;
+
+public class MFirstDayEditor implements PropertyEditor
+{
+
+ int day; //One less than the enum value in java.util.Calendar
+ protected PropertyChangeSupport listeners = new
PropertyChangeSupport(this);
+ final String[] days={ "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY",
"THURSDAY",
+ "FRIDAY", "SATURDAY" };
+
+ public MFirstDayEditor()
+ {
+ }
+
+ public String getJavaInitializationString()
+ {
+ String buff;
+ buff = "java.util.Calendar."+ days[day];
+ return buff;
+ }
+
+ public boolean isPaintable()
+ {
+ return false;
+ }
+
+ public void paintValue(Graphics g, Rectangle r)
+ {
+ }
+
+ public Component getCustomEditor()
+ {
+ return null;
+ }
+
+ public String getAsText()
+ {
+ String val;
+ val = days[day];
+ return val;
+ }
+
+ public void setAsText(String s)
+ {
+ for (int i = 0; i< days.length; i++)
+ {
+ if (days[i].equals(s))
+ {
+ day = i;
+ listeners.firePropertyChange(null, null, null);
+ break;
+ }
+ }
+ }
+
+ public void setValue(Object object)
+ {
+ Integer x = (Integer)object;
+ day = x.intValue()-1;
+ }
+
+ public Object getValue()
+ {
+ return new Integer (day+1);
+ }
+
+ public String[] getTags()
+ {
+ return days;
+ }
+
+ public boolean supportsCustomEditor()
+ {
+ return false;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener l)
+ {
+ listeners.addPropertyChangeListener(l);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l)
+ {
+ listeners.removePropertyChangeListener(l);
+ }
+}
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MMonthEvent.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MMonthEvent.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MMonthEvent.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,54 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.util.Calendar;
+
+/** An Event class used to notify listeners that ther has been a change
+* in the MMonth data model
+*/
+public class MMonthEvent extends java.util.EventObject
+{
+ public static final int NEW_MONTH=0;
+ public static final int NEW_DATE=1;
+ public static final int NEW_MIN=2;
+ public static final int NEW_MAX=3;
+ public static final int SELECTED=4;
+ public static final int NEW_FIRST_DAY=5;
+ public static final int NEW_RB=6;
+ public static final int EXITED=7;
+ public static final int NEW_AUTO_DATE=8;
+
+ private int type;
+ private Calendar date;
+
+ public MMonthEvent(Object source, int type, Calendar date)
+ {
+ super(source);
+ this.type=type;
+ this.date=date;
+ }
+
+ public int getType()
+ {
+ return type;
+ }
+
+ public Calendar getNewDate()
+ {
+ return date;
+ }
+}
+
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MMonthListener.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MMonthListener.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MMonthListener.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,23 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+/** Interface to which any object must conform if it is to be informed of
+* changes to the MMonth data model.
+*/
+public interface MMonthListener
+{
+ public void dataChanged(MMonthEvent event);
+}
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MScrollBarChanger.java
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MScrollBarChanger.java
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MScrollBarChanger.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,308 @@
+/*
+* Copyright (c) 2002 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import mseries.ui.MChangeEvent;
+import mseries.ui.MChangeListener;
+import mseries.ui.MDateSpinnerModel;
+
+import javax.swing.*;
+import java.awt.event.*;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Vector;
+import java.text.DateFormat;
+
+/** A specific implementation of a scrollbar where the value represents a
+* java.util.Date. The mimimum and maximum values are therefore Dates,
+* the unit increment a month and the block increment a year
+*/
+class MScrollBarChanger extends JScrollBar implements MDateChanger,
AdjustmentListener
+{
+
+ private Calendar maxC=Calendar.getInstance();
+ private Calendar minC=Calendar.getInstance();
+ private int minMonth, minYear, maxMonth, maxYear;
+ private int day;
+ protected Vector listeners = new Vector();
+ protected MDateSpinnerModel model;
+ private static final int UP=1;
+ private static final int DOWN=-1;
+
+
+ /**
+ * Class to do the increment/decrement when the buttons are pressed
+ */
+ protected class UpDownAction extends AbstractAction
+ {
+ int direction; // +1 = up; -1 = down
+ int step;
+
+ public UpDownAction(int direction, int step)
+ {
+ super();
+ this.step=step;
+ this.direction = direction;
+ }
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ Object val;
+
+ model.setStep(step);
+ if (direction==UP)
+ {
+ val = model.getNextValue();
+ }
+ else
+ {
+ val = model.getPreviousValue();
+ }
+ setValue((Date)val);
+ notifyListeners(MChangeEvent.CHANGE);
+ }
+ }
+
+ /**
+ * Inner class to manage the push of the PAGE UP and PAGE DOWN
+ * keys which move the scrollbar and hence the calendar forward
+ * and backwards one month respectively.
+ */
+ //private class PagingAction implements ActionListener
+ //{
+ // int inc;
+ //
+ // public PagingAction(int inc)
+ // {
+ // this.inc = inc;
+ // }
+ //
+ // public void actionPerformed(ActionEvent e)
+ // {
+ // setValue(getValue()+inc);
+ // }
+ //}
+ /** Creates a MScrollBarChanger with HORIZONTAL orientation and
+ * blockIncrement = 12
+ * unitIncrement = 1
+ * minimum = 1 January 1900
+ * maximum = 31 December 2037
+ * value = 1 January 1900
+ * extent = 1
+ */
+ public MScrollBarChanger()
+ {
+ this(JScrollBar.HORIZONTAL);
+ }
+
+ /** Creates a MScrollBarChanger with the orientation specified (in
+ * JScrollBar) and
+ * blockIncrement = 12
+ * unitIncrement = 1
+ * minimum = 1 January 1900
+ * maximum = 31 December 2037
+ * value = 1 January 1900
+ * extent = 1
+ */
+ public MScrollBarChanger(int orientation)
+ {
+ super(orientation);
+ model=new MDateSpinnerModel();
+ model.setValue(new Date());
+
+ super.addAdjustmentListener(this);
+
+ minC.set(1900, 0, 1);
+ minMonth=minC.get(Calendar.MONTH);
+ minYear=minC.get(Calendar.YEAR);
+
+ maxC.set(2037, 11, 31);
+ super.setMinimum(0);
+ super.setMaximum(1656);
+ super.setVisibleAmount(1);
+ super.setBlockIncrement(12); // 12 months = 1 year
+ super.setUnitIncrement(1); // 1 month
+ super.setValue(0);
+
+ installKeyboardActions();
+ }
+
+ /*
+ * installs the PAGE UP and PAGE DOWN buttons with the increment specifed
+ * in months.
+ * @param advance the number of months to move forward and backwards
+ */
+ private void installKeyboardActions()
+ {
+ registerKeyboardAction(new UpDownAction(UP, DateFormat.MONTH_FIELD),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ registerKeyboardAction(new UpDownAction(DOWN, DateFormat.MONTH_FIELD),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+
+ registerKeyboardAction(new UpDownAction(UP, DateFormat.YEAR_FIELD),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, KeyEvent.SHIFT_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ registerKeyboardAction(new UpDownAction(DOWN, DateFormat.YEAR_FIELD),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, KeyEvent.SHIFT_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ }
+ //private void installKeyboardActions()
+ //{
+ // registerKeyboardAction(new PagingAction(1),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ // registerKeyboardAction(new PagingAction(-1),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ //
+ // registerKeyboardAction(new PagingAction(12),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, KeyEvent.SHIFT_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ // registerKeyboardAction(new PagingAction(-12),
KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, KeyEvent.SHIFT_MASK),
JComponent.WHEN_IN_FOCUSED_WINDOW);
+ //}
+
+ /* Sets the earliest possible value for the scrollbar to the start of the
+ * month in date passed in. Also sets the curent value to the same.
+ * @param min a date in the earliest month
+ */
+ public void setMinimum(Date min)
+ {
+ minC.setTime(min);
+ minMonth = minC.get(Calendar.MONTH);
+ minYear = minC.get(Calendar.YEAR);
+
+ maxMonth = maxC.get(Calendar.MONTH);
+ maxYear = maxC.get(Calendar.YEAR);
+
+ int minMonths=(minYear - 1900)*12 + minMonth;
+ int maxMonths=(maxYear - 1900)*12 + maxMonth;
+
+ /* The maximum for the scrollbar is the number of months from
+ * the minimum
+ */
+ super.setMaximum(maxMonths-minMonths);
+
+ setValue(min);
+
+ model.setMinimum(min);
+ }
+
+ /* Sets the latest possible value for the scrollbar to the end of the
+ * month in date passed in.
+ * @param max a date in the latest month
+ */
+ public void setMaximum(Date max)
+ {
+ maxC.setTime(max);
+ int month = maxC.get(Calendar.MONTH) ;
+ int year = maxC.get(Calendar.YEAR);
+
+ int lastMonth = (year - 1900)*12 + month;
+ int minMonths = (minYear - 1900)*12 + minMonth;
+
+ int monthRange = lastMonth - minMonths+1;
+
+ super.setMaximum(monthRange);
+ setValue(minC.getTime());
+ model.setMaximum(max);
+ }
+
+ /* Sets the value of the scrollbar to the number of months since the
+ * the minimum date represented by the date passed
+ * @param newVal - the new value
+ */
+ public void setValue(Date newVal)
+ {
+ Calendar valC = Calendar.getInstance();
+ valC.setTime(newVal);
+
+ int month = valC.get(Calendar.MONTH);
+ int year = valC.get(Calendar.YEAR);
+
+ if ((!newVal.before(minC.getTime())) &&
(!newVal.after(maxC.getTime())))
+ {
+ int newValue = (year - minYear)* 12 + month - minMonth;
+ super.setValue(newValue);
+ }
+ model.setValue(newVal);
+ }
+
+ public void setDay(int day)
+ {
+ this.day = day;
+ }
+
+ /* Overridden to prevent the values being incorrectly set
+ */
+ public void setBlockIncrement(int v)
+ {
+ super.setBlockIncrement(12); // 12 months = 1 year
+ }
+
+ /* Overridden to prevent the values being incorrectly set
+ */
+ public void setUnitIncrement(int v)
+ {
+ super.setUnitIncrement(1); // 1 month
+ }
+
+ private void notifyListeners(int type)
+ {
+ Vector list = (Vector)listeners.clone();
+ for (int i = 0; i < list.size(); i++)
+ {
+ MChangeListener l = (MChangeListener)listeners.elementAt(i);
+ l.valueChanged(new MChangeEvent(this, new Integer(getValue()),
type));
+ }
+ }
+
+ public void addMChangeListener(MChangeListener l)
+ {
+ listeners.addElement(l);
+ }
+
+ public void removeMChangeListener(MChangeListener l)
+ {
+ listeners.removeElement(l);
+ }
+
+ public void adjustmentValueChanged(AdjustmentEvent e)
+ {
+ notifyListeners(MChangeEvent.CHANGE);
+ }
+
+ public boolean hasFocus()
+ {
+ return false;
+ }
+
+ public void addFListener(FocusListener l)
+ {
+ }
+
+ public void removeFListener(FocusListener l)
+ {
+ }
+}
+// $Log: MScrollBarChanger.java,v $
+// Revision 1.7 2003/10/04 09:41:40 martin
+// *** empty log message ***
+//
+// Revision 1.6 2003/10/03 20:00:04 martin
+// *** empty log message ***
+//
+// Revision 1.5 2003/08/22 21:52:45 martin
+// no message
+//
+// Revision 1.4 2003/03/26 23:29:48 martin
+// Changed email address
+//
+// Revision 1.3 2002/07/21 17:30:57 martin
+// no message
+//
+// Revision 1.2 2002/07/21 17:29:27 martin
+// Removed getGUI, setFground and setBground methods
+//
+// Revision 1.1 2002/07/21 16:24:39 martin
+// no message
+//
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MSpinnerChanger.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MSpinnerChanger.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MSpinnerChanger.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,265 @@
+/*
+* Copyright (c) 2001 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import mseries.ui.MChangeEvent;
+import mseries.ui.MChangeListener;
+
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.*;
+import java.awt.event.FocusListener;
+import java.text.DateFormatSymbols;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Vector;
+
+public class MSpinnerChanger extends JPanel implements MDateChanger
+{
+ private Calendar maxC = Calendar.getInstance();
+ private Calendar minC = Calendar.getInstance();
+ private int minMonth, minYear;
+ private int maxYear;
+
+ private JSpinner month;
+ private JSpinner year;
+ private SpinnerNumberModel yearModel;
+ private SpinnerListModel monthModel;
+ private String[] months, mths;
+
+ protected Vector listeners = new Vector();
+
+ public MSpinnerChanger() {
+ this(false);
+ }
+
+ public MSpinnerChanger(boolean editable)
+ {
+ super();
+
+ DateFormatSymbols dfs;
+
+ minC.set(1900, 0, 1);
+ minMonth = minC.get(Calendar.MONTH);
+ minYear = minC.get(Calendar.YEAR);
+
+ maxC.set(2037, 11, 31);
+ maxYear = maxC.get(Calendar.YEAR);
+
+ // Create the widgets
+ month = new JSpinner();
+ month.setBackground(getBackground());
+ month.setMinimumSize(new Dimension(100, 22));
+ dfs = new DateFormatSymbols();
+ mths = dfs.getMonths();
+ months = new String[12];
+ System.arraycopy(mths, 0, months, 0, 12);
+
+ monthModel = new SpinnerListModel(months);
+ month.setModel(monthModel);
+ JSpinner.ListEditor listEd = new JSpinner.ListEditor(month);
+ listEd.getTextField().setEditable(false);
+ listEd.getTextField().setColumns(6);
+ listEd.getTextField().setBorder(null);
+
listEd.getTextField().setBackground(UIManager.getColor("TextField.background"));
+ month.setEditor(listEd);
+ month.addChangeListener(new ChangeListener()
+ {
+ public void stateChanged(ChangeEvent e)
+ {
+ notifyListeners(MChangeEvent.CHANGE);
+ }
+ });
+
+ yearModel = new SpinnerNumberModel(minYear, minYear, maxYear, 1);
+ year = new JSpinner(yearModel);
+ year.setBackground(getBackground());
+ year.setMinimumSize(new Dimension(64, 22));
+ JSpinner.NumberEditor ed = new JSpinner.NumberEditor(year, "0000");
+ ed.getTextField().setEditable(false);
+ ed.getTextField().setBorder(null);
+
ed.getTextField().setBackground(UIManager.getColor("TextField.background"));
+ year.setEditor(ed);
+
+ year.addChangeListener(new ChangeListener()
+ {
+ public void stateChanged(ChangeEvent e)
+ {
+ notifyListeners(MChangeEvent.CHANGE);
+ }
+ });
+
+ // Draw the screen
+ GridBagLayout gridbag = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+
+ setLayout(gridbag);
+ c.insets = new Insets(2, 2, 2, 2);
+ c.gridx = 0;
+ c.gridy = 0;
+ c.gridwidth = 1;
+ c.gridheight = 1;
+ c.fill = GridBagConstraints.BOTH;
+ c.anchor = GridBagConstraints.WEST;
+ add(month, c);
+
+ c.gridx = 1;
+ c.anchor = GridBagConstraints.EAST;
+ add(year, c);
+ }
+
+ public void setMinimum(Date min)
+ {
+ minC.setTime(min);
+ minYear = minC.get(Calendar.YEAR);
+ minMonth = minC.get(Calendar.MONTH);
+
+ yearModel.setMinimum(new Integer(minYear));
+ setValue(min);
+ }
+
+ public void setMaximum(Date max)
+ {
+ maxC.setTime(max);
+ maxYear = maxC.get(Calendar.YEAR);
+
+ yearModel.setMaximum(new Integer(maxYear));
+ setValue(max);
+ }
+
+ public void setValue(Date newVal)
+ {
+ Calendar valC = Calendar.getInstance();
+ valC.setTime(newVal);
+ int y = valC.get(Calendar.YEAR);
+ int m = valC.get(Calendar.MONTH);
+ monthModel.setValue(months[m]);
+ yearModel.setValue(new Integer(y));
+
+ }
+
+ public int getValue()
+ {
+ int m = 0;
+ String mon = (String)month.getValue();
+ for (int i = 0; i < months.length; i++)
+ {
+ if (months[i].equals(mon))
+ {
+ m = i;
+ break;
+ }
+ }
+ int y = ((Integer)yearModel.getValue()).intValue();
+
+ int newValue = (y - minYear) * 12 + m - minMonth;
+ return newValue;
+ }
+
+ private void notifyListeners(int type)
+ {
+ Vector list = (Vector)listeners.clone();
+ for (int i = 0; i < list.size(); i++)
+ {
+ MChangeListener l = (MChangeListener)listeners.elementAt(i);
+ l.valueChanged(new MChangeEvent(this, new Integer(getValue()),
type));
+ }
+ }
+
+ public void addMChangeListener(MChangeListener l)
+ {
+ listeners.addElement(l);
+ }
+
+ public void removeMChangeListener(MChangeListener l)
+ {
+ listeners.removeElement(l);
+ }
+
+ /**
+ * Does anything within the component have the focus
+ * @return true if any child component has the focus
+ */
+ public boolean hasFocus()
+ {
+ JSpinner.DefaultEditor
monthEditor=(JSpinner.DefaultEditor)month.getEditor();
+ JSpinner.DefaultEditor
yearEditor=(JSpinner.DefaultEditor)year.getEditor();
+ boolean hasFocus = monthEditor.getTextField().isFocusOwner() ||
yearEditor.getTextField().isFocusOwner();
+ return hasFocus;
+ }
+
+ /**
+ * Adds the focus listener by delegating to each child component
+ * addFocusListener method.
+ */
+ public void addFListener(FocusListener l)
+ {
+ month.addFocusListener(l);
+ year.addFocusListener(l);
+ }
+
+ /**
+ * Removes the focusListner from the child components
+ */
+ public void removeFListener(FocusListener l)
+ {
+ month.removeFocusListener(l);
+ year.removeFocusListener(l);
+ }
+
+ /**
+ * Sets the background of the two spinner buttons
+ * @param b the background color
+ */
+ public void setBground(Color b)
+ {
+ super.setBackground(b);
+ month.setBackground(b);
+ year.setBackground(b);
+ }
+
+ /**
+ * Sets the foreground of the two spinner buttons
+ * @param b the foreground color
+ */
+ public void setFground(Color b)
+ {
+ super.setForeground(b);
+ month.setForeground(b);
+ year.setForeground(b);
+ }
+
+ public static void main(String[] argv)
+ {
+ JFrame f = new JFrame("Test");
+ final MSpinnerChanger c = new MSpinnerChanger();
+
+ //c.setBground(Color.red);
+ //c.setFground(Color.green);
+ c.addMChangeListener(new MChangeListener()
+ {
+ public void valueChanged(MChangeEvent e)
+ {
+ System.out.println(c.getValue());
+ }
+ });
+
+ f.getContentPane().add(c);
+
+ f.pack();
+ f.setVisible(true);
+ }
+}
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MTextLocaliserEditor.java
===================================================================
---
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MTextLocaliserEditor.java
2006-03-14 14:05:14 UTC (rev 8249)
+++
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MTextLocaliserEditor.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,116 @@
+/*
+* Copyright (c) 2000 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+import java.util.*;
+
+public class MTextLocaliserEditor implements PropertyEditor
+{
+
+ protected ResourceBundle value; // The thing being edited
+ protected String bundleName;
+ protected PropertyChangeSupport listeners = new
PropertyChangeSupport(this);
+
+ public MTextLocaliserEditor()
+ {
+ }
+
+ public String getJavaInitializationString()
+ {
+ String buff;
+ buff = "ResourceBundle.getBundle("+bundleName+")";
+ return buff;
+ }
+
+ public boolean isPaintable()
+ {
+ return false;
+ }
+
+ public void paintValue(Graphics g, Rectangle r)
+ {
+ g.setClip(r);
+ g.drawString(getAsText(), r.x+5, r.y+20);
+ }
+
+ public Component getCustomEditor()
+ {
+ final TextField t = new TextField(getAsText(), 20);
+
+ t.addTextListener(new TextListener() {
+ public void textValueChanged(TextEvent e)
+ {
+ setAsText(t.getText());
+ }
+ });
+ return t;
+ }
+
+ public String getAsText()
+ {
+ bundleName = value.toString();
+ bundleName=bundleName.substring(0, bundleName.lastIndexOf("@"));
+ return bundleName;
+ }
+
+ public void setAsText(String s)
+ {
+ ResourceBundle old=value;
+ try
+ {
+ value = ResourceBundle.getBundle(s);
+ bundleName=s;
+ listeners.firePropertyChange(null, null, null);
+ }
+ catch(Exception e)
+ {
+ System.out.println(e.toString()+ " - Resetting to
"+old.toString());
+ value = old;
+ }
+ }
+
+ public void setValue(Object object)
+ {
+ value = (ResourceBundle)object;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+
+ public String[] getTags()
+ {
+ return null;
+ }
+
+ public boolean supportsCustomEditor()
+ {
+ return true;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener l)
+ {
+ listeners.addPropertyChangeListener(l);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener l)
+ {
+ listeners.removePropertyChangeListener(l);
+ }
+}
Added: trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MonthPopup.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MonthPopup.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/MonthPopup.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,287 @@
+/*
+* Copyright (c) 2002 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.awt.*;
+import java.text.*;
+import java.util.*;
+
+import javax.swing.*;
+
+import mseries.utils.*;
+
+public class MonthPopup extends JWindow // implements
MouseListener (and corresponding methods) removed by S. Ruman
+{
+ JList months;
+ MonthModel model;
+ AutoChanger autoChanger;
+ Calendar c1;
+ int width, height;
+
+ public MonthPopup()
+ {
+ model = new MonthModel();
+ months = new JList();
+ setValue(new Date());
+ months.setModel(model);
+ getContentPane().setLayout(new GridLayout(1, 0));
+ getContentPane().add(months);
+ //addMouseListener(this);
+
+ months.setCellRenderer(getCellRenderer());
+ months.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ months.setBorder(BorderFactory.createLineBorder(Color.black));
+ }
+
+ public void setLocationOnScreen(int x, int y)
+ {
+ this.setLocation(x, y);
+ }
+
+ public Object getValue()
+ {
+ return months.getSelectedValue();
+ }
+
+ public void setValue(Date value)
+ {
+ model.setMonth(value);
+ months.setSelectedIndex(3);
+ }
+
+ public void setSelectedPoint(Point p)
+ {
+ if (p.y < 0 || p.y > height)
+ {
+ months.clearSelection();
+ }
+ else
+ {
+ // added by S. Ruman to enable the auto-scrolling of months when
the first or last month is selected
+ int whichSelected = months.locationToIndex(p);
+ if (whichSelected == 0)
+ {
+ if ((autoChanger == null) || (autoChanger.isIncrementing()))
+ { // top selected, scoll backward in months
+ if (autoChanger != null) // previously scrolling
forwards, cancel that scroll
+ autoChanger.stopThread();
+
+ autoChanger = new AutoChanger(model);
+ autoChanger.setDirection(AutoChanger.DEC);
+ autoChanger.start();
+ }
+ }
+ else if (whichSelected == (months.getModel().getSize() - 1))
+ { // bottom selected, scoll forward in months
+ if ((autoChanger == null) || (autoChanger.isDecrementing()))
+ {
+ if (autoChanger != null) // previously scrolling
backwards, cancel that scroll
+ autoChanger.stopThread();
+
+ autoChanger = new AutoChanger(model);
+ autoChanger.setDirection(AutoChanger.INC);
+ autoChanger.start();
+ }
+ }
+ else
+ {
+ if (autoChanger != null)
+ { // previously scrolling, stop
+ autoChanger.stopThread();
+ autoChanger = null;
+ }
+ }
+ // end S. Ruman addition
+
+
+ months.setSelectedIndex(months.locationToIndex(p));
+ }
+ }
+
+ public ListCellRenderer getCellRenderer()
+ {
+ ListCellRenderer r;
+ r = new DefaultListCellRenderer()
+ {
+
+ DateFormat df = new SimpleDateFormat("MMMMM yyyy");
+
+ public Component getListCellRendererComponent(JList list, Object
value, int index, boolean isSelected, boolean cellHasFocus)
+ {
+ Date d = (Date) value;
+ setText(df.format(d));
+ setHorizontalAlignment(CENTER);
+
+ setBackground(isSelected ?
UIManager.getColor("ComboBox.selectionBackground") :
UIManager.getColor("ComboBox.background"));
+ setForeground(isSelected ?
UIManager.getColor("ComboBox.selectionForeground") :
UIManager.getColor("ComboBox.foreground"));
+ return this;
+ }
+ };
+
+ return r;
+ }
+
+ public void setVisible(boolean visible)
+ {
+ super.setVisible(visible);
+ width = getWidth();
+ height = getHeight();
+ }
+
+ class MonthModel extends AbstractListModel
+ {
+ Date firstDate = new Date();
+ Calendar firstCal;
+
+ public void setMonth(Date month)
+ {
+ firstCal = Calendar.getInstance();
+ firstCal.setTime(month);
+
+
+ // Modification made by S. Ruman (Hyperion) due to the bug with
sun.util.BuddhistCalendar (returned by getInstance() in Thai locales).
+ // This bug messes up the date when the year changes because of an
.add call.
+ // firstCal.add(Calendar.MONTH, -3);
+ SafeCalendarUtils.doSafeAddition(firstCal, Calendar.MONTH, -3);
+ }
+
+ public Object getElementAt(int i)
+ {
+ c1 = (Calendar) firstCal.clone();
+ // see comment above
+ // c1.add(Calendar.MONTH, i);
+ SafeCalendarUtils.doSafeAddition(c1, Calendar.MONTH, i);
+
+ return c1.getTime();
+ }
+
+
+ public int getSize()
+ {
+ return 7;
+ }
+
+ public void increment(int inc)
+ {
+ // see comment above
+// firstCal.add(Calendar.MONTH, inc);
+ SafeCalendarUtils.doSafeAddition(firstCal, Calendar.MONTH, inc);
+
+ fireContentsChanged(this, 0, 6);
+ }
+ }
+
+
+ class AutoChanger extends Thread
+ {
+ static final int INC = 1;
+ static final int DEC = -1;
+ int dir = INC;
+ MonthModel model;
+ boolean keepGoing;
+
+ public AutoChanger(MonthModel model)
+ {
+ this.model = model;
+ keepGoing = true;
+ }
+
+ public void setDirection(int dir)
+ {
+ this.dir = dir;
+ }
+
+ // added by S. Ruman to enable the auto-scrolling of months when the
first or last month is selected
+ public boolean isIncrementing()
+ {
+ return (dir == INC);
+ }
+
+ public boolean isDecrementing()
+ {
+ return (dir == DEC);
+ }
+ // end of S. Ruman addition
+
+ public void run()
+ {
+ // added by S. Ruman to enable the auto-scrolling of months when
the first or last month is selected
+ try
+ {
+ Thread.sleep(1000); // wait for 2 seconds before the
scrolling starts
+ }
+ catch (InterruptedException e)
+ {
+ keepGoing = false;
+ }
+ // end of S. Ruman addition
+
+ keepGoing = true;
+ while (keepGoing)
+ {
+ try
+ {
+ model.increment(dir);
+ sleep(750);
+ }
+ catch (InterruptedException e)
+ {
+ keepGoing = false;
+ }
+ }
+ }
+
+ public void stopThread()
+ {
+ keepGoing = false;
+ }
+ }
+
+ public static void main(String[] argv)
+ {
+ try
+ {
+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ }
+ catch (Exception e)
+ {
+ }
+ MonthPopup f = new MonthPopup();
+
+ f.pack();
+ f.setLocationOnScreen(100, 100);
+ f.setVisible(true);
+ }
+}
+
+// $Log: MonthPopup.java,v $
+// Revision 1.9 2003/03/26 23:29:48 martin
+// Changed email address
+//
+// Revision 1.8 2003/03/24 19:45:07 martin
+// Latest 1.4 version
+//
+// Revision 1.6 2003/03/11 22:35:15 martin
+// Upgraded to Java 1.4 on 11/03/03
+//
+// Revision 1.4 2002/07/21 16:24:39 martin
+// no message
+//
+// Revision 1.3 2002/07/18 21:43:45 martin
+// no message
+//
+// Revision 1.2 2002/07/17 21:32:40 martin
+// no message
+//
Added:
trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/SpecialDayModel.java
===================================================================
--- trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/SpecialDayModel.java
2006-03-14 14:05:14 UTC (rev 8249)
+++ trunk/apps/frost-0.7/lib/datechooser/mseries/Calendar/SpecialDayModel.java
2006-03-14 14:05:52 UTC (rev 8250)
@@ -0,0 +1,58 @@
+/*
+* Copyright (c) 2002 Martin Newstead (mseries at brundell.fsnet.co.uk). All
Rights Reserved.
+*
+* The author makes no representations or warranties about the suitability of
the
+* software, either express or implied, including but not limited to the
+* implied warranties of merchantability, fitness for a particular
+* purpose, or non-infringement. The author shall not be liable for any
damages
+* suffered by licensee as a result of using, modifying or distributing
+* this software or its derivatives.
+*
+* The author requests that he be notified of any application, applet, or
other binary that
+* makes use of this code and that some acknowedgement is given. Comments,
questions and
+* requests for change will be welcomed.
+*/
+package mseries.Calendar;
+
+import java.awt.Color;
+import java.util.Date;
+
+/**
+* Classes implementing this interface define which days are treated as
special
+* in the CalendarPanel. Special days are rendered differently and might not
+* be clickable. The method isSpecialDay(Date) governs the proceedings,
+* if this returns true the getForground and getBackground methods will be
called
+* for the same date. isClickable will always be called to determine of the
user
+* is allowed to select the date.
+*<p>
+* @see mseries.Calendar.DefaultSpecialDayModel
+*/
+public interface SpecialDayModel
+{
+ public boolean isSpecialDay(Date date);
+
+ /**
+ * The foreground for the special days. Return null if the foreground is
+ * to be drawn in the usual colour
+ */
+ public Color getForeground(Date date);
+
+ /**
+ * The background for the special days. Return null if the background is
+ * to be drawn in the usual colour
+ */
+ public Color getBackground(Date date);
+
+}
+/*
+$Log: SpecialDayModel.java,v $
+Revision 1.3 2003/03/26 23:29:48 martin
+Changed email address
+
+Revision 1.2 2002/02/09 17:08:20 martin
+Removed isClickable method
+
+Revision 1.1 2002/02/09 12:54:39 martin
+Partial support for 'Special Days'
+
+*/