KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29
30 import sync4j.foundation.pdi.event.Calendar;
31
32 /**
33  * The calendar modification panel.
34  *
35  *
36  * @author Fabio Maggi @ Funambol
37  * @author Alessandro Morandi, Giorgio Orsi
38  * @version $Id: CalendarModify.java,v 1.4 2005/01/19 11:01:11 fabius Exp $
39  */

40 public class CalendarModify
41 extends Panel JavaDoc
42 implements ActionListener JavaDoc, ConfigurationParameters {
43
44     //---------------------------------------------------------- Constants
45

46     //---------------------------------------------------------- Private data
47

48     //
49
// The window containing this panel
50
//
51
private MainWindow mw = null ;
52
53     private CalendarForm form = null ;
54     private CheckCalendarFields cfields = null ;
55
56      private Language ln = new Language() ;
57
58     //---------------------------------------------------------- Public methods
59

60     /**
61      * Creates the panel.
62      *
63      * @param mw the window containing this panel
64      */

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

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

121     /**
122      * Sets the fields with the values contained
123      * in the specified Calendar object
124      * and the checkbox with the specified type.
125      *
126      * @param calendar the Calendar object which is the source of the values
127      */

128     protected void fillFields(Calendar calendar) {
129         form.setFields(calendar);
130     }
131
132     //---------------------------------------------------------- Private methods
133

134     /**
135      * Saves the modified calendar.
136      */

137     private void saveCalendar() {
138         mw.writeModCalendar(form.getFields(),mw.getCurrentIndex().intValue());
139         mw.show(KEY_CALENDARLIST);
140     }
141
142 }
Popular Tags