KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > ed > Calendar


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.grid.ed;
15
16 import java.awt.*;
17 import java.awt.event.*;
18 import javax.swing.*;
19 import javax.swing.event.*;
20 import java.util.*;
21 import java.text.*;
22 import java.sql.*;
23
24 import org.compiere.util.*;
25 import org.compiere.apps.*;
26 import org.compiere.plaf.*;
27 import org.compiere.swing.*;
28
29 /**
30  * Pop up Calendar & Time
31  *
32  * @author Jorg Janke
33  * @version $Id: Calendar.java,v 1.12 2003/03/05 06:24:00 jjanke Exp $
34  */

35 public class Calendar extends JDialog
36     implements ActionListener, MouseListener, ChangeListener, KeyListener
37 {
38     /**
39      * Mimimum Constructor for Date editor
40      * @param frame frame
41      */

42     public Calendar (Frame frame)
43     {
44         this (frame, Msg.getMsg(Env.getCtx(), "Calendar"), null, DisplayType.Date);
45     } // Calendar
46

47     /**
48      * Constructor
49      * @param frame frame
50      * @param title title
51      * @param startTS start date/time
52      * @param displayType DisplayType (Date, DateTime, Time)
53      */

54     public Calendar (Frame frame, String JavaDoc title, Timestamp startTS, int displayType)
55     {
56         super (frame, title, true);
57         Log.trace(Log.l1_User, "Calendar", startTS==null ? "null" : startTS.toString() + " " + displayType);
58         m_displayType = displayType;
59         //
60
try
61         {
62             jbInit();
63             setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
64         }
65         catch(Exception JavaDoc ex)
66         {
67             Log.error("Calendar", ex);
68         }
69         //
70
loadData(startTS);
71     } // Calendar
72

73     /** Display Type */
74     private int m_displayType;
75     /** The Date */
76     private GregorianCalendar m_calendar;
77     /** Is there a PM format */
78     private boolean m_hasAM_PM = false;
79     //
80
private CButton[] m_days;
81     private CButton m_today;
82     /** First Dat of week */
83     private int m_firstDay;
84     //
85
private int m_currentDay;
86     private int m_currentMonth;
87     private int m_currentYear;
88     private int m_current24Hour = 0;
89     private int m_currentMinute = 0;
90     //
91
private boolean m_setting = true;
92     private boolean m_abort = true;
93     //
94
private long m_lastClick = System.currentTimeMillis();
95     private int m_lastDay = -1;
96     //
97
private static final Insets ZERO_INSETS = new Insets(0,0,0,0);
98     //
99
private CPanel mainPanel = new CPanel();
100     private CPanel monthPanel = new CPanel();
101     private CComboBox cMonth = new CComboBox();
102     private JSpinner cYear = new JSpinner(new SpinnerNumberModel(2000, 1900,2100,1));
103     private BorderLayout mainLayout = new BorderLayout();
104     private CPanel dayPanel = new CPanel();
105     private GridLayout dayLayout = new GridLayout();
106     private GridBagLayout monthLayout = new GridBagLayout();
107     private CButton bNext = new CButton();
108     private CButton bBack = new CButton();
109     private CPanel timePanel = new CPanel();
110     private CComboBox fHour = new CComboBox(getHours());
111     private CLabel lTimeSep = new CLabel();
112     private JSpinner fMinute = new JSpinner(new MinuteModel(5)); // 5 minute snap size
113
private JCheckBox cbPM = new JCheckBox();
114     private JLabel lTZ = new JLabel();
115     private CButton bOK = new CButton();
116     private GridBagLayout timeLayout = new GridBagLayout();
117
118     /**
119      * Static init
120      * @throws Exception
121      */

122     private void jbInit() throws Exception JavaDoc
123     {
124         CompiereColor.setBackground(this);
125         this.addKeyListener(this);
126         //
127
mainPanel.setLayout(mainLayout);
128         mainLayout.setHgap(2);
129         mainLayout.setVgap(2);
130         mainPanel.setBorder(BorderFactory.createLoweredBevelBorder());
131         getContentPane().add(mainPanel);
132
133         // Month Panel
134
monthPanel.setLayout(monthLayout);
135         monthPanel.add(bBack, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
136             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
137         monthPanel.add(cYear, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0
138             ,GridBagConstraints.SOUTHEAST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
139         monthPanel.add(bNext, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
140             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
141         monthPanel.add(cMonth, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
142             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
143         mainPanel.add(monthPanel, BorderLayout.NORTH);
144         cMonth.addActionListener(this);
145         cYear.addChangeListener(this);
146         bBack.setIcon(Env.getImageIcon("Parent16.gif")); // <
147
bBack.setMargin(new Insets(0,0,0,0));
148         bBack.addActionListener(this);
149         bNext.setIcon(Env.getImageIcon("Detail16.gif")); // >
150
bNext.setMargin(new Insets(0,0,0,0));
151         bNext.addActionListener(this);
152
153         // Day Panel
154
dayPanel.setLayout(dayLayout);
155         dayLayout.setColumns(7);
156         dayLayout.setHgap(2);
157         dayLayout.setRows(7);
158         dayLayout.setVgap(2);
159         mainPanel.add(dayPanel, BorderLayout.CENTER);
160
161         // Time Panel
162
timePanel.setLayout(timeLayout);
163         lTimeSep.setText(" : ");
164         timePanel.add(fHour, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
165             ,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 0, 0));
166         timePanel.add(lTimeSep, new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0
167             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
168         timePanel.add(fMinute, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
169             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
170         timePanel.add(cbPM, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
171             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
172         timePanel.add(lTZ, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
173             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 4, 0, 0), 0, 0));
174         timePanel.add(bOK, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0
175             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 6, 0, 2), 0, 0));
176         mainPanel.add(timePanel, BorderLayout.SOUTH);
177         fHour.addKeyListener(this); // Enter returns
178
// JSpinner ignores KeyListener
179
((JSpinner.DefaultEditor)fMinute.getEditor()).getTextField().addKeyListener(this);
180         fMinute.addChangeListener(this);
181         cbPM.addActionListener(this);
182         cbPM.addKeyListener(this);
183         bOK.setIcon(Env.getImageIcon("Ok16.gif"));
184         bOK.setMargin(new Insets(0,1,0,1));
185         bOK.addActionListener(this);
186     } // jbInit
187

188     /**
189      * Window Events - requestFocus
190      * @param e event
191      */

192     protected void processWindowEvent(WindowEvent e)
193     {
194     // Log.trace(Log.l4_Data, "Calendar.processWindowEvent", e);
195
super.processWindowEvent(e);
196         if (e.getID() == WindowEvent.WINDOW_OPENED)
197         {
198             if (m_displayType == DisplayType.Time)
199                 fHour.requestFocus();
200             else if (m_today != null)
201                 m_today.requestFocus();
202         }
203     } // processWindowEvent
204

205     /*************************************************************************/
206
207     /**
208      * Load Data.
209      * - Years
210      * - Month names
211      * - Day Names
212      * @param startTS time stamp
213      */

214     private void loadData (Timestamp startTS)
215     {
216         m_calendar = new GregorianCalendar(Language.getLanguage().getLocale());
217         if (startTS == null)
218             m_calendar.setTimeInMillis(System.currentTimeMillis());
219         else
220             m_calendar.setTime(startTS);
221         m_firstDay = m_calendar.getFirstDayOfWeek();
222         //
223
Locale loc = Language.getLanguage().getLocale();
224         SimpleDateFormat formatDate = (SimpleDateFormat)DateFormat.getDateInstance(DateFormat.LONG, loc);
225         // Short: h:mm a - HH:mm Long: h:mm:ss a z - HH:mm:ss z
226
SimpleDateFormat formatTime = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, loc);
227         m_hasAM_PM = formatTime.toPattern().indexOf('a') != -1;
228         if (m_hasAM_PM)
229             cbPM.setText(formatTime.getDateFormatSymbols().getAmPmStrings()[1]);
230         else
231             cbPM.setVisible(false);
232
233         // Years
234
m_currentYear = m_calendar.get(java.util.Calendar.YEAR);
235         cYear.setEditor(new JSpinner.NumberEditor(cYear, "0000"));
236         cYear.setValue(new Integer JavaDoc(m_currentYear));
237
238         // Months -> 0=Jan 12=_
239
String JavaDoc[] months = formatDate.getDateFormatSymbols().getMonths();
240         for (int i = 0; i < months.length; i++)
241         {
242             KeyNamePair p = new KeyNamePair(i+1, months[i]);
243             if (!months[i].equals(""))
244                 cMonth.addItem(p);
245         }
246         m_currentMonth = m_calendar.get(java.util.Calendar.MONTH) + 1; // Jan=0
247
cMonth.setSelectedIndex(m_currentMonth-1);
248
249         // Week Days -> 0=_ 1=Su .. 7=Sa
250
String JavaDoc[] days = formatDate.getDateFormatSymbols().getShortWeekdays(); // 0 is blank, 1 is Sunday
251
for (int i = m_firstDay; i < 7 + m_firstDay; i++)
252         {
253             int index = i > 7 ? i -7 : i;
254             dayPanel.add(createWeekday(days[index]), null);
255         }
256
257         // Days
258
m_days = new CButton[6*7];
259         m_currentDay = m_calendar.get(java.util.Calendar.DATE);
260         for (int i = 0; i < 6; i++) // six weeks a month maximun
261
for (int j = 0; j < 7; j++) // seven days
262
{
263                 int index = i*7 + j;
264                 m_days[index] = createDay();
265                 dayPanel.add(m_days[index], null);
266             }
267
268         // Today button
269
m_days[m_days.length-1].setBackground(Color.green);
270         m_days[m_days.length-1].setText("*");
271         m_days[m_days.length-1].setToolTipText(Msg.getMsg(Env.getCtx(), "Today"));
272
273         // Date/Time
274
m_current24Hour = m_calendar.get(java.util.Calendar.HOUR_OF_DAY);
275         m_currentMinute = m_calendar.get(java.util.Calendar.MINUTE);
276
277         // What to show
278
timePanel.setVisible(m_displayType == DisplayType.DateTime || m_displayType == DisplayType.Time);
279         monthPanel.setVisible(m_displayType != DisplayType.Time);
280         dayPanel.setVisible(m_displayType != DisplayType.Time);
281
282         // update UI from m_current...
283
m_setting = false;
284         setCalendar();
285     } // loadData
286

287     /**
288      * Create Week Day Label
289      * @param title Weedkay Title
290      * @return week day
291      */

292     private JLabel createWeekday (String JavaDoc title)
293     {
294         JLabel label = new JLabel(title);
295         label.setBorder(BorderFactory.createRaisedBevelBorder());
296         label.setHorizontalAlignment(SwingConstants.CENTER);
297         label.setHorizontalTextPosition(SwingConstants.CENTER);
298         label.setRequestFocusEnabled(false);
299         return label;
300     } // createWeekday
301

302     /**
303      * Create Day Label
304      * @return button
305      */

306     private CButton createDay()
307     {
308         CButton button = new CButton();
309         button.setBorder(BorderFactory.createLoweredBevelBorder());
310         button.setHorizontalTextPosition(SwingConstants.CENTER);
311         button.setMargin(ZERO_INSETS);
312         button.addActionListener(this);
313         button.addMouseListener(this);
314         button.addKeyListener(this);
315         return button;
316     } // createWeekday
317

318     /**
319      * Create 12/25 hours
320      * @return Array with hours as String
321      */

322     private Object JavaDoc[] getHours()
323     {
324         Locale loc = Language.getLanguage().getLocale();
325         // Short: h:mm a - HH:mm Long: h:mm:ss a z - HH:mm:ss z
326
SimpleDateFormat formatTime = (SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.SHORT, loc);
327         m_hasAM_PM = formatTime.toPattern().indexOf('a') != -1;
328         //
329
Object JavaDoc[] retValue = new Object JavaDoc[m_hasAM_PM ? 12 : 24];
330         if (m_hasAM_PM)
331         {
332             retValue[0] = "12";
333             for (int i = 1; i < 10; i++)
334                 retValue[i] = " " + String.valueOf(i);
335             for (int i = 10; i < 12; i++)
336                 retValue[i] = String.valueOf(i);
337         }
338         else
339         {
340             for (int i = 0; i < 10; i++)
341                 retValue[i] = "0" + String.valueOf(i);
342             for (int i = 10; i < 24; i++)
343                 retValue[i] = String.valueOf(i);
344         }
345         return retValue;
346     } // getHours
347

348     /*************************************************************************/
349
350     /**
351      * Set Calandar from m_current variables and update UI
352      */

353     private void setCalendar()
354     {
355         if (m_setting)
356             return;
357     // Log.trace(Log.l4_Data, "Calendar.setCalendar");
358

359         // --- Set Month & Year
360
m_setting = true;
361         cMonth.setSelectedIndex(m_currentMonth-1);
362         cYear.setValue(new Integer JavaDoc(m_currentYear));
363         m_setting = false;
364
365         // --- Set Day
366
// what is the first day in the selected month?
367
m_calendar.set(m_currentYear, m_currentMonth-1, 1); // Month is zero based
368
int dayOne = m_calendar.get(java.util.Calendar.DAY_OF_WEEK);
369         int lastDate = m_calendar.getActualMaximum(java.util.Calendar.DATE);
370
371         // convert to index
372
dayOne -= m_firstDay;
373         if (dayOne < 0)
374             dayOne += 7;
375         lastDate += dayOne - 1;
376
377         // for all buttons but the last
378
int curDay = 1;
379         for (int i = 0; i < m_days.length-1; i++)
380         {
381             if (i >= dayOne && i <= lastDate)
382             {
383                 if (m_currentDay == curDay)
384                 {
385                     m_days[i].setBackground(Color.blue);
386                     m_days[i].setForeground(Color.yellow);
387                     m_today = m_days[i];
388                     m_today.requestFocus();
389                 }
390                 else
391                 {
392                     m_days[i].setBackground(Color.white);
393                     m_days[i].setForeground(Color.black);
394                 }
395                 m_days[i].setText(String.valueOf(curDay++));
396                 m_days[i].setReadWrite(true);
397             }
398             else
399             {
400                 m_days[i].setText("");
401                 m_days[i].setReadWrite(false);
402                 m_days[i].setBackground(CompierePLAF.getFieldBackground_Inactive());
403             }
404         }
405
406         // Set Hour
407
boolean pm = m_current24Hour > 12;
408         int index = m_current24Hour;
409         if (pm && m_hasAM_PM)
410             index -= 12;
411         if (index < 0 || index >= fHour.getItemCount())
412             index = 0;
413         fHour.setSelectedIndex(index);
414         // Set Minute
415
int m = m_calendar.get(java.util.Calendar.MINUTE);
416         fMinute.setValue(new Integer JavaDoc(m));
417         // Set PM
418
cbPM.setSelected(pm);
419         // Set TZ
420
TimeZone tz = m_calendar.getTimeZone();
421         lTZ.setText(tz.getDisplayName(tz.inDaylightTime(m_calendar.getTime()), TimeZone.SHORT));
422
423         // Update Calendar
424
m_calendar.set(m_currentYear, m_currentMonth-1, m_currentDay, m_current24Hour, m_currentMinute, 0);
425         m_calendar.set(java.util.Calendar.MILLISECOND, 0);
426     } // setCalendar
427

428     /**
429      * Set Current Time from UI.
430      * - set m_current.. variables
431      */

432     private void setTime()
433     {
434         // Hour
435
int h = fHour.getSelectedIndex();
436         m_current24Hour = h;
437         if (m_hasAM_PM && cbPM.isSelected())
438             m_current24Hour += 12;
439         if (m_current24Hour < 0 || m_current24Hour > 23)
440             m_current24Hour = 0;
441
442         // Minute
443
Integer JavaDoc ii = (Integer JavaDoc)fMinute.getValue();
444         m_currentMinute = ii.intValue();
445         if (m_currentMinute < 0 || m_currentMinute > 59)
446             m_currentMinute = 0;
447     } // setTime
448

449     /**
450      * Return Time stamp
451      * @return date and time
452      */

453     public Timestamp getTimestamp()
454     {
455     // Log.trace(Log.l4_Data, "Calendar.getTimeStamp");
456
// Set Calendar
457
m_calendar.set(m_currentYear, m_currentMonth-1, m_currentDay, m_current24Hour, m_currentMinute, 0);
458         m_calendar.set(java.util.Calendar.MILLISECOND, 0);
459
460         // Return value
461
if (m_abort)
462             return null;
463         long time = m_calendar.getTimeInMillis();
464         if (m_displayType == DisplayType.Date)
465             time = new java.sql.Date JavaDoc(time).getTime();
466         else if (m_displayType == DisplayType.Time)
467             time = new Time(time).getTime(); // based on 1970-01-01
468
return new Timestamp(time);
469     } // getTimestamp
470

471     /*************************************************************************/
472
473     /**
474      * Action Listener for Month/Year combo & dat buttons.
475      * - Double clicking on a date closes it
476      * - set m_current...
477      * @param e Event
478      */

479     public void actionPerformed (ActionEvent e)
480     {
481         if (m_setting)
482             return;
483     // Log.trace(Log.l4_Data, "Calendar.actionPerformed");
484
setTime();
485
486         if (e.getSource() == bOK)
487         {
488             m_abort = false;
489             dispose();
490             return;
491         }
492         else if (e.getSource() == bBack)
493         {
494             if (--m_currentMonth < 1)
495             {
496                 m_currentMonth = 12;
497                 m_currentYear--;
498             }
499             m_lastDay = -1;
500         }
501         else if (e.getSource() == bNext)
502         {
503             if (++m_currentMonth > 12)
504             {
505                 m_currentMonth = 1;
506                 m_currentYear++;
507             }
508             m_lastDay = -1;
509         }
510         else if (e.getSource() instanceof JButton)
511         {
512             JButton b = (JButton)e.getSource();
513             String JavaDoc text = b.getText();
514             // Set to today's date
515
if (text.equals("*"))
516             {
517                 m_calendar.setTime(new Timestamp(System.currentTimeMillis()));
518                 m_currentDay = m_calendar.get(java.util.Calendar.DATE);
519                 m_currentMonth = m_calendar.get(java.util.Calendar.MONTH) + 1;
520                 m_currentYear = m_calendar.get(java.util.Calendar.YEAR);
521             }
522             // we have a day
523
else if (text.length() > 0)
524             {
525                 m_currentDay = Integer.parseInt(text);
526                 long currentClick = System.currentTimeMillis();
527                 if (m_currentDay == m_lastDay
528                     && currentClick-m_lastClick < 1000) // double click 1 second
529
{
530                     m_abort = false;
531                     dispose();
532                     return;
533                 }
534                 m_lastClick = currentClick;
535                 m_lastDay = m_currentDay;
536             }
537         }
538         else if (e.getSource() == cbPM)
539         {
540             setTime();
541             m_lastDay = -1;
542         }
543         else
544         {
545             // Set Month
546
m_currentMonth = cMonth.getSelectedIndex()+1;
547             m_lastDay = -1;
548         }
549         setCalendar();
550     } // actionPerformed
551

552     /**
553      * ChangeListener (Year/Minute Spinner)
554      * @param e Event
555      */

556     public void stateChanged(ChangeEvent e)
557     {
558         if (m_setting)
559             return;
560
561         // Set Minute
562
if (e.getSource() == fMinute)
563         {
564             setTime();
565             return;
566         }
567         // Set Year
568
m_currentYear = ((Integer JavaDoc)cYear.getValue()).intValue();
569         m_lastDay = -1;
570         setCalendar();
571     } // stateChanged
572

573     /*************************************************************************/
574
575     /**
576      * Mouse Clicked
577      * @param e Evant
578      */

579     public void mouseClicked(MouseEvent e)
580     {
581         if (e.getClickCount() == 2)
582         {
583             m_abort = false;
584             dispose();
585         }
586     } // mouseClicked
587

588     public void mousePressed(MouseEvent e) {}
589     public void mouseEntered(MouseEvent e) {}
590     public void mouseExited(MouseEvent e) {}
591     public void mouseReleased(MouseEvent e) {}
592
593     /*************************************************************************/
594
595     /**
596      * Key Released - Return on enter
597      * @param e event
598      */

599     public void keyReleased(KeyEvent e)
600     {
601     // System.out.println("Released " + e);
602
// Day Buttons
603
if (e.getSource() instanceof JButton)
604         {
605             if (e.getKeyCode() == KeyEvent.VK_PAGE_DOWN)
606             {
607                 if (++m_currentMonth > 12)
608                 {
609                      m_currentMonth = 1;
610                      m_currentYear++;
611                 }
612                 setCalendar();
613                 return;
614             }
615             if (e.getKeyCode() == KeyEvent.VK_PAGE_UP)
616             {
617                 if (--m_currentMonth < 1)
618                 {
619                      m_currentMonth = 12;
620                      m_currentYear--;
621                 }
622                 setCalendar();
623                 return;
624             }
625
626             // Arrows
627
int offset = 0;
628             if (e.getKeyCode() == KeyEvent.VK_RIGHT)
629                 offset = 1;
630             else if (e.getKeyCode() == KeyEvent.VK_LEFT)
631                 offset = -1;
632             else if (e.getKeyCode() == KeyEvent.VK_UP)
633                 offset = -7;
634             else if (e.getKeyCode() == KeyEvent.VK_DOWN)
635                 offset = 7;
636             if (offset != 0)
637             {
638                 System.out.println(m_calendar.getTime() + " offset=" + offset);
639                 m_calendar.add(java.util.Calendar.DAY_OF_YEAR, offset);
640                 System.out.println(m_calendar.getTime());
641
642                 m_currentDay = m_calendar.get(java.util.Calendar.DAY_OF_MONTH);
643                 m_currentMonth = m_calendar.get(java.util.Calendar.MONTH) + 1;
644                 m_currentYear = m_calendar.get(java.util.Calendar.YEAR);
645                 setCalendar();
646                 return;
647             }
648             // something else
649
actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, ""));
650         }
651
652         // Pressed Enter anywhere
653
if (e.getKeyCode() == KeyEvent.VK_ENTER)
654         {
655             m_abort = false;
656             setTime();
657             dispose();
658             return;
659         }
660
661         // Modified Hour/Miinute
662
setTime();
663         m_lastDay = -1;
664     } // keyReleased
665

666     public void keyTyped(KeyEvent e)
667     {
668     // System.out.println("Typed " + e);
669
}
670     public void keyPressed(KeyEvent e)
671     {
672     // System.out.println("Pressed " + e);
673
}
674
675 } // Calendar
676

677 /**
678  * Minute Spinner Model.
679  * Based on Number Model - uses snap size to determine next value.
680  * Allows to manually set any ninute, but return even snap value
681  * when spinner buttons are used.
682  *
683  * @author Jorg Janke
684  * @version $Id: Calendar.java,v 1.12 2003/03/05 06:24:00 jjanke Exp $
685  */

686 class MinuteModel extends SpinnerNumberModel
687 {
688     /**
689      * Constructor.
690      * Creates Integer Spinner with minimum=0, maximum=59, stepsize=1
691      * @param snapSize snap size
692      */

693     public MinuteModel(int snapSize)
694     {
695         super(0,0,59, 1); // Integer Model
696
m_snapSize = snapSize;
697     } // MinuteModel
698

699     /** Snap size */
700     private int m_snapSize;
701
702     /**
703      * Return next full snap value
704      * @return next snap value
705      */

706     public Object JavaDoc getNextValue()
707     {
708         int minutes = ((Integer JavaDoc)getValue()).intValue();
709         minutes += m_snapSize;
710         if (minutes >= 60)
711             minutes -= 60;
712         //
713
int steps = minutes / m_snapSize;
714         return new Integer JavaDoc(steps * m_snapSize);
715     } // getNextValue
716

717
718     /**
719      * Return previous full step value
720      * @return previous snap value
721      */

722     public Object JavaDoc getPreviousValue()
723     {
724         int minutes = ((Integer JavaDoc)getValue()).intValue();
725         minutes -= m_snapSize;
726         if (minutes < 0)
727             minutes += 60;
728         //
729
int steps = minutes / m_snapSize;
730         if (minutes % m_snapSize != 0)
731             steps++;
732         if (steps * m_snapSize > 59)
733             steps = 0;
734         return new Integer JavaDoc(steps * m_snapSize);
735     } // getNextValue
736

737 } // MinuteModel
738
Popular Tags