KickJava   Java API By Example, From Geeks To Geeks.

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


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.GridLayout JavaDoc;
24 import java.awt.Label JavaDoc;
25 import java.awt.Panel JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28
29 /**
30  * The new Calendar insertion panel.
31  *
32  * @author Fabio Maggi @ Funambol
33  * @author Marco Magistrali @ Funambol
34  */

35 public class CalendarNew
36 extends Panel JavaDoc
37 implements ActionListener JavaDoc, ConfigurationParameters {
38
39     //---------------------------------------------------------- Constants
40

41     //---------------------------------------------------------- Private data
42

43     //
44
// The window containing this panel
45
//
46
private MainWindow mw = null ;
47
48     private CalendarForm form = null ;
49     private CheckCalendarFields cfields = null ;
50
51     private Language ln = new Language() ;
52
53     //---------------------------------------------------------- Public methods
54

55     /**
56      * Creates the panel.
57      *
58      * @param mw the window containing this panel
59      */

60     public CalendarNew(MainWindow mw) {
61
62         Label JavaDoc title = null ;
63         Button JavaDoc butOk = null ;
64         Button JavaDoc butCancel = null ;
65         Panel JavaDoc buttonPanel = null ;
66
67         this.mw = mw;
68
69         setLayout(new BorderLayout JavaDoc());
70         title = new Label JavaDoc(ln.getString ("new_calendar"));
71
72         form = new CalendarForm(mw);
73
74         butOk = new Button JavaDoc (ln.getString ("ok") ) ;
75         butOk.setActionCommand ("ok" ) ;
76         butOk.addActionListener (this ) ;
77
78         butCancel = new Button JavaDoc (ln.getString ("cancel") ) ;
79         butCancel.setActionCommand ("cancel" ) ;
80         butCancel.addActionListener (this ) ;
81
82         buttonPanel = new Panel JavaDoc();
83         buttonPanel.setLayout (new GridLayout JavaDoc(1, 2));
84         buttonPanel.add (butOk ) ;
85         buttonPanel.add (butCancel ) ;
86
87         add(title , BorderLayout.NORTH ) ;
88         add(form , BorderLayout.CENTER ) ;
89         add(buttonPanel , BorderLayout.SOUTH ) ;
90     }
91
92     /**
93      * Invoked when an action occurs (i.e. a button is pressed).
94      *
95      * @param evt the occurred action
96      */

97     public void actionPerformed(ActionEvent JavaDoc evt) {
98
99         if (evt.getActionCommand().equals("ok")) {
100
101                 cfields = new CheckCalendarFields(mw, form);
102                 if (!cfields.areFieldsRight()) {
103                     cfields.show();
104                     mw.setEnabled(false);
105                 }
106                 else {
107                     saveCalendar();
108                 }
109
110         } else if (evt.getActionCommand().equals("cancel")) {
111             mw.show(KEY_CALENDARLIST);
112         }
113     }
114
115     //---------------------------------------------------------- Protected methods
116

117     /**
118      * Sets all the textfields in the DemocCalendarForm
119      * subpanel to an empty string.
120      */

121     protected void blankFields() {
122         form.blankFields();
123     }
124
125     //---------------------------------------------------------- Private methods
126

127     /**
128      * Saves the new Calendar.
129      */

130     private void saveCalendar() {
131         mw.writeNewCalendar(form.getFields());
132         mw.show(KEY_CALENDARLIST);
133     }
134
135
136 }
Popular Tags