View Javadoc

1   package org.wcb.common;
2   
3   import org.wcb.common.component.JTimeSlider;
4   import org.wcb.autohome.AutoHomeAdminSession;
5   import org.wcb.autohome.interfaces.I18nConstants;
6   
7   import javax.swing.*;
8   import javax.swing.event.ChangeListener;
9   import javax.swing.event.ChangeEvent;
10  import java.awt.*;
11  import java.util.Calendar;
12  import java.util.GregorianCalendar;
13  import java.text.SimpleDateFormat;
14  import java.text.ParseException;
15  
16  /***
17   * Copyright (C) 1999  Walter Bogaardt
18   *
19   * This library is free software; you can redistribute it and/or
20   * modify it under the terms of the GNU Lesser General Public
21   * License as published by the Free Software Foundation; either
22   * version 2 of the License, or (at your option) any later version.
23   *
24   * This library is distributed in the hope that it will be useful,
25   * but WITHOUT ANY WARRANTY; without even the implied warranty of
26   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27   * Lesser General Public License for more details.
28   *
29   * You should have received a copy of the GNU Lesser General Public
30   * License along with this library; if not, write to the Free Software
31   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
32   *
33   * Project: Alice X10 Home Automation
34   * Filename:  $Id: JTimeDialog.java,v 1.5 2004/07/22 03:06:50 wbogaardt Exp $<BR>
35   * Abstract: Used to display general configuration settings such as serial port settings and languages.
36   *
37   * $Log: JTimeDialog.java,v $
38   * Revision 1.5  2004/07/22 03:06:50  wbogaardt
39   * removed deprecated method calls.
40   *
41   * Revision 1.4  2004/02/06 23:27:13  wbogaardt
42   * added clock label to internationalization, refactored menu bar from home center panel, fixed display of JTimeDialog so that it looks a bit better.
43   *
44   * Revision 1.3  2004/02/06 20:06:36  wbogaardt
45   * replaced ampm drop boxes with time buttons which launch a time panel move menu items around on main panel
46   *
47   * Revision 1.2  2004/02/06 05:58:22  wbogaardt
48   * have a working time slider panel that gets and sets time
49   *
50   * Revision 1.1  2004/02/05 14:30:30  wbogaardt
51   * added dialog
52   *
53   */
54  public class JTimeDialog extends JDialog implements ChangeListener{
55  
56      JTextField time;
57      JTimeSlider timeslider;
58  
59      /***
60       * This dialog takes the frame reference a calender object to to
61       * display a time dialog box. This dialog box makes it easier for the
62       * user to set the time as they can drag a slide bar across and it will
63       * change the time rather than typing in the time.
64       * @param frame main frame reference
65       * @param cal Time to set the slide bar and print in a text box.
66       * @param controller The button that will controll closing this dialog.
67       */
68      public JTimeDialog(Frame frame, Calendar cal, JButton controller){
69          super(frame,"Time Settings",true);
70          Container pane  = getContentPane();
71          pane.setLayout(new BorderLayout());
72          time = new JTextField(5);
73          time.setText(cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE));
74          timeslider = new JTimeSlider(cal);
75          timeslider.addChangeListener(this);
76          JPanel northPanel = new JPanel();
77          northPanel.add(new JLabel(AutoHomeAdminSession.getInstance().getI18n().getString(I18nConstants.TIME_LABEL)));
78          northPanel.add(time);
79          JPanel centerPanel = new JPanel();
80          centerPanel.add(timeslider);
81          JPanel southPanel = new JPanel();
82          southPanel.add(controller);
83          pane.add(northPanel, BorderLayout.NORTH);
84          pane.add(centerPanel, BorderLayout.CENTER);
85          pane.add(southPanel, BorderLayout.SOUTH);
86          pane.setSize(200,50);
87          pack();
88      }
89  
90      public String getTime(){
91          GregorianCalendar calendar = new GregorianCalendar();
92          try{
93              SimpleDateFormat sdfParse = new SimpleDateFormat("HH:mm");
94              calendar.setTime(sdfParse.parse(time.getText()));
95          }catch(ParseException pe){}
96          SimpleDateFormat sdfShow = new SimpleDateFormat("h:mm a");
97          return sdfShow.format(calendar.getTime());
98      }
99  
100     public void stateChanged(ChangeEvent e){
101         Object s = e.getSource();
102         if(s == timeslider){
103             time.setText(timeslider.getCalenderOfSlider());
104         }
105     }
106 }