KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > demo > CheckCalendarFields


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.demo;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Button JavaDoc;
23 import java.awt.Frame JavaDoc;
24 import java.awt.GridLayout JavaDoc;
25 import java.awt.Image JavaDoc;
26 import java.awt.Label JavaDoc;
27 import java.awt.Panel JavaDoc;
28 import java.awt.Toolkit JavaDoc;
29
30 import java.awt.event.ActionEvent JavaDoc;
31 import java.awt.event.ActionListener JavaDoc;
32 import java.awt.event.WindowEvent JavaDoc;
33 import java.awt.event.WindowListener JavaDoc;
34
35 /**
36  * The new calendar insertion panel.
37  *
38  * @author Fabio Maggi @ Funambol
39  * @author Marco Magistrali @ Funambol
40  * @version $Id: CheckCalendarFields.java,v 1.5 2005/01/19 11:01:11 fabius Exp $
41  */

42
43 public class CheckCalendarFields
44 extends Frame JavaDoc
45 implements ActionListener JavaDoc,
46 WindowListener JavaDoc,
47 ConfigurationParameters {
48
49     //--------------------------------------------------------------- Constants
50

51     //--------------------------------------------------------------- Private data
52

53     /**
54      * The window containing this panel
55      */

56     private MainWindow mw = null ;
57
58     private CalendarForm form = null ;
59     private Label JavaDoc lb1 = null ;
60     private Label JavaDoc lb2 = null ;
61     private Label JavaDoc lb3 = null ;
62
63     private Language ln = new Language() ;
64
65     //--------------------------------------------------------------- Public methods
66

67     public CheckCalendarFields(MainWindow mw, CalendarForm form) {
68
69         super ();
70         setTitle (ln.getString("check_calendar_fields"));
71
72         Image JavaDoc icon = null ;
73         Button JavaDoc butOk = null ;
74         Panel JavaDoc textPanel = null ;
75
76         icon = Toolkit.getDefaultToolkit().getImage(FRAME_ICONNAME);
77
78         setIconImage(icon);
79
80         this.mw = mw ;
81         this.form = form ;
82
83         setSize (300, 150) ;
84         setLocation (400, 200) ;
85         setLayout (new BorderLayout JavaDoc());
86
87         lb1 = new Label JavaDoc("", Label.CENTER ) ;
88         lb2 = new Label JavaDoc("", Label.CENTER ) ;
89         lb3 = new Label JavaDoc("", Label.CENTER ) ;
90
91         butOk = new Button JavaDoc (ln.getString ("ok") ) ;
92         butOk.setActionCommand ("ok" ) ;
93
94         butOk.addActionListener(this );
95
96         textPanel = new Panel JavaDoc();
97         textPanel.setLayout(new GridLayout JavaDoc(3, 1) );
98         textPanel.add(lb1);
99         textPanel.add(lb2);
100         textPanel.add(lb3);
101
102         add(textPanel, BorderLayout.CENTER ) ;
103         add(butOk , BorderLayout.SOUTH ) ;
104
105         addWindowListener(this);
106
107     }
108
109     public boolean areFieldsRight() {
110
111         String JavaDoc startDate = null ;
112         String JavaDoc endDate = null ;
113         String JavaDoc startTime = null ;
114         String JavaDoc endTime = null ;
115
116         startDate = form.getStartDate() ;
117         endDate = form.getEndDate () ;
118         startTime = form.getStartTime() ;
119         endTime = form.getEndTime () ;
120
121         if (startDate == null ||
122             startDate.length() == 0 ||
123             startTime == null ||
124             startTime.length() == 0 ||
125             (!FieldsHelper.checkDate(startDate + " " + startTime + ":00", FieldsHelper.DATE_FORMAT_AND_TIME))) {
126            lb1.setText(ln.getString ("please_insert_valid_start_date_time"));
127            return false;
128         }
129
130         if (endDate == null ||
131             endDate.length() == 0 ||
132             endTime == null ||
133             endTime.length() == 0 ||
134             (!FieldsHelper.checkDate(endDate + " " + endTime + ":00", FieldsHelper.DATE_FORMAT_AND_TIME))) {
135            lb1.setText(ln.getString ("please_insert_valid_end_date_time"));
136            return false;
137         }
138
139         return true;
140     }
141
142     public void actionPerformed(ActionEvent JavaDoc evt) {
143
144         if (evt.getActionCommand().equals("ok")) {
145                mw.setEnabled(true);
146                hide();
147         }
148
149     }
150
151     public void windowClosing(WindowEvent JavaDoc evt) {
152         mw.setEnabled(true);
153         hide();
154     }
155
156     public void windowActivated (WindowEvent JavaDoc e) {}
157
158     public void windowClosed (WindowEvent JavaDoc e) {}
159
160     public void windowDeactivated (WindowEvent JavaDoc e) {}
161
162     public void windowDeiconified (WindowEvent JavaDoc e) {}
163
164     public void windowIconified (WindowEvent JavaDoc e) {}
165
166     public void windowOpened (WindowEvent JavaDoc e) {}
167
168     //--------------------------------------------------------------- Private methods
169

170 }
Popular Tags