KickJava   Java API By Example, From Geeks To Geeks.

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


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.Checkbox JavaDoc;
24 import java.awt.CheckboxGroup JavaDoc;
25 import java.awt.GridLayout JavaDoc;
26 import java.awt.Label JavaDoc;
27 import java.awt.Panel JavaDoc;
28 import java.awt.TextField JavaDoc;
29
30 import java.awt.event.ActionEvent JavaDoc;
31 import java.awt.event.ActionListener JavaDoc;
32
33 import java.util.Hashtable JavaDoc;
34
35 /**
36  * The configuration panel.
37  *
38  * @author Fabio Maggi @ Funambol
39  * @author Alessandro Morandi, Giorgio Orsi
40  * @version $Id: Configuration.java,v 1.8 2005/03/14 16:46:03 fabius Exp $
41  */

42 public class Configuration
43 extends Panel JavaDoc
44 implements ActionListener JavaDoc,
45 ConfigurationParameters {
46
47     //---------------------------------------------------------- Constants
48

49     private final static String JavaDoc SYNC_NONE = "none" ;
50     private final static String JavaDoc SYNC_TWOWAY = "two-way" ;
51
52     //---------------------------------------------------------- Private data
53

54     //
55
// The window containing this panel
56
//
57
private MainWindow mw = null ;
58
59     private TextField JavaDoc tf1 = null ;
60     private TextField JavaDoc tf2 = null ;
61     private TextField JavaDoc tf3 = null ;
62     private TextField JavaDoc tf4 = null ;
63     private TextField JavaDoc tf5 = null ;
64     private TextField JavaDoc tf6 = null ;
65
66     //
67
//Checkbox enable sync
68
//
69
private Checkbox JavaDoc cbSyncContact = null ;
70     private Checkbox JavaDoc cbSyncCalendar = null ;
71
72     //
73
//Select message type, log level
74
//
75
private CheckboxGroup JavaDoc cbgMessageType = null ;
76     private CheckboxGroup JavaDoc cbgLogLevel = null ;
77     private Checkbox JavaDoc cbMsgXML = null ;
78     private Checkbox JavaDoc cbMsgWBXML = null ;
79     private Checkbox JavaDoc cbLogNone = null ;
80     private Checkbox JavaDoc cbLogInfo = null ;
81     private Checkbox JavaDoc cbLogDebug = null ;
82
83     private Language ln = new Language() ;
84
85     //---------------------------------------------------------- Public methods
86

87     /**
88      * Creates the panel.
89      *
90      * @param mw the window containing this panel
91      */

92     public Configuration(MainWindow mw) {
93
94         Panel JavaDoc configPanel = null ;
95         Panel JavaDoc buttonPanel = null ;
96         Panel JavaDoc messagePanel = null ;
97         Panel JavaDoc logPanel = null ;
98
99         Button JavaDoc butOk = null ;
100         Button JavaDoc butCancel = null ;
101
102         Label JavaDoc lb1 = null ;
103         Label JavaDoc lb2 = null ;
104         Label JavaDoc lb3 = null ;
105         Label JavaDoc lb4 = null ;
106         Label JavaDoc lb5 = null ;
107         Label JavaDoc lb6 = null ;
108         Label JavaDoc lb7 = null ;
109         Label JavaDoc lb8 = null ;
110         Label JavaDoc lb10 = null ;
111         Label JavaDoc lb11 = null ;
112
113         this.mw = mw;
114
115         setLayout(new BorderLayout JavaDoc());
116
117         configPanel = new Panel JavaDoc();
118         configPanel.setLayout (new GridLayout JavaDoc(12, 2));
119
120         messagePanel = new Panel JavaDoc ();
121         messagePanel.setLayout(new GridLayout JavaDoc(1, 2));
122
123         logPanel = new Panel JavaDoc ();
124         logPanel.setLayout (new GridLayout JavaDoc(1, 3));
125
126         lb1 = new Label JavaDoc (ln.getString ("sync_server_url" ) ) ;
127         lb2 = new Label JavaDoc (ln.getString ("username" ) ) ;
128         lb3 = new Label JavaDoc (ln.getString ("password" ) ) ;
129         lb4 = new Label JavaDoc (ln.getString ("remote_address_book" ) ) ;
130         lb5 = new Label JavaDoc (ln.getString ("remote_calendar" ) ) ;
131         lb6 = new Label JavaDoc (ln.getString ("synchronizing_address_book" ) ) ;
132         lb7 = new Label JavaDoc (ln.getString ("synchronizing_calendar" ) ) ;
133         lb8 = new Label JavaDoc (ln.getString ("device_id" ) ) ;
134         lb10 = new Label JavaDoc (ln.getString ("message_type" ) ) ;
135         lb11 = new Label JavaDoc (ln.getString ("log_level" ) ) ;
136
137         tf1 = new TextField JavaDoc () ;
138         tf2 = new TextField JavaDoc () ;
139         tf3 = new TextField JavaDoc () ;
140         tf3.setEchoChar('*');
141         tf4 = new TextField JavaDoc () ;
142         tf5 = new TextField JavaDoc () ;
143         tf6 = new TextField JavaDoc () ;
144
145         cbSyncContact = new Checkbox JavaDoc () ;
146         cbSyncCalendar = new Checkbox JavaDoc () ;
147
148         cbgMessageType = new CheckboxGroup JavaDoc () ;
149         cbgLogLevel = new CheckboxGroup JavaDoc () ;
150
151         cbMsgXML = new Checkbox JavaDoc (ln.getString ("xml" ) ,
152                                         cbgMessageType ,
153                                         true );
154
155         cbMsgWBXML = new Checkbox JavaDoc (ln.getString ("wbxml" ) ,
156                                         cbgMessageType ,
157                                         false );
158
159         cbLogNone = new Checkbox JavaDoc (ln.getString ("none" ) ,
160                                         cbgLogLevel ,
161                                         false );
162
163         cbLogInfo = new Checkbox JavaDoc (ln.getString ("info" ) ,
164                                         cbgLogLevel ,
165                                         true );
166
167         cbLogDebug = new Checkbox JavaDoc (ln.getString ("debug" ) ,
168                                         cbgLogLevel ,
169                                         false );
170
171         configPanel.add (lb1 ) ;
172         configPanel.add (tf1 ) ;
173         configPanel.add (lb2 ) ;
174         configPanel.add (tf2 ) ;
175         configPanel.add (lb3 ) ;
176         configPanel.add (tf3 ) ;
177         configPanel.add (lb4 ) ;
178         configPanel.add (tf4 ) ;
179         configPanel.add (lb5 ) ;
180         configPanel.add (tf5 ) ;
181         configPanel.add (lb6 ) ;
182         configPanel.add (cbSyncContact ) ;
183         configPanel.add (lb7 ) ;
184         configPanel.add (cbSyncCalendar ) ;
185         configPanel.add (lb8 ) ;
186         configPanel.add (tf6 ) ;
187         configPanel.add (lb10 ) ;
188
189         messagePanel.add (cbMsgXML ) ;
190         messagePanel.add (cbMsgWBXML ) ;
191
192         configPanel.add (messagePanel ) ;
193
194         configPanel.add (lb11 ) ;
195
196         logPanel.add (cbLogNone ) ;
197         logPanel.add (cbLogInfo ) ;
198         logPanel.add (cbLogDebug ) ;
199
200         configPanel.add (logPanel ) ;
201
202         butOk = new Button JavaDoc (ln.getString ("ok" ) ) ;
203         butOk.setActionCommand ("ok" ) ;
204         butOk.addActionListener (this ) ;
205
206         butCancel = new Button JavaDoc (ln.getString ("cancel" ) ) ;
207         butCancel.setActionCommand ("cancel" ) ;
208         butCancel.addActionListener (this ) ;
209
210         buttonPanel = new Panel JavaDoc ();
211         buttonPanel.setLayout (new GridLayout JavaDoc(1, 2) ) ;
212         buttonPanel.add (butOk ) ;
213         buttonPanel.add (butCancel ) ;
214
215         add(configPanel, BorderLayout.NORTH ) ;
216         add(buttonPanel, BorderLayout.SOUTH ) ;
217
218     }
219
220     /**
221      * Invoked when an action occurs (i.e. a button is pressed).
222      *
223      * @param evt the occurred action
224      */

225     public void actionPerformed(ActionEvent JavaDoc evt) {
226
227         if (evt.getActionCommand().equals("ok")) {
228             mw.writeConfig (getFields());
229             mw.show (KEY_CONTACTLIST);
230         } else if (evt.getActionCommand().equals("cancel")) {
231             mw.show (KEY_CONTACTLIST);
232         }
233     }
234
235     //------------------------------------------------------- Protected methods
236

237     /**
238      * Sets the fields with some of the values contained
239      * in the specified Hashtables.
240      * It also sets the checkboxes.
241      *
242      * @param values DM values from DM_VALUE_PATH
243      * @param xmlContactValues DM values from contact source
244      * @param xmlCalendarValues DM values from calendar source
245      */

246     protected void setAllFields(Hashtable JavaDoc values ,
247                                 Hashtable JavaDoc xmlContactValues ,
248                                 Hashtable JavaDoc xmlCalendarValues ) {
249
250         String JavaDoc syncContact = null ;
251         String JavaDoc syncCalendar = null ;
252         String JavaDoc messageType = null ;
253         String JavaDoc logLevel = null ;
254
255         tf1.setText ((String JavaDoc) values.get (PARAM_SYNCMLURL) ) ;
256         tf2.setText ((String JavaDoc) values.get (PARAM_USERNAME) ) ;
257         tf3.setText ((String JavaDoc) values.get (PARAM_PASSWORD) ) ;
258         tf4.setText ((String JavaDoc) xmlContactValues.get
259                     (PARAM_SOURCEURI) ) ;
260         tf5.setText ((String JavaDoc) xmlCalendarValues.get
261                     (PARAM_SOURCEURI) ) ;
262         tf6.setText ((String JavaDoc) values.get (PARAM_DEVICEID) ) ;
263
264         syncContact = (String JavaDoc) xmlContactValues.get
265                         (PARAM_SYNCMODE ) ;
266         syncCalendar = (String JavaDoc) xmlCalendarValues.get
267                         (PARAM_SYNCMODE ) ;
268         messageType = (String JavaDoc) values.get (PARAM_MESSAGETYPE ) ;
269         logLevel = (String JavaDoc) values.get (PARAM_LOGLEVEL ) ;
270
271         if (SYNC_TWOWAY.equals(syncContact)) {
272             cbSyncContact.setState (true );
273         } else {
274             cbSyncContact.setState (false);
275         }
276
277         if (SYNC_TWOWAY.equals(syncCalendar)) {
278             cbSyncCalendar.setState (true );
279         } else {
280             cbSyncCalendar.setState (false );
281         }
282
283         if (MESSAGE_XML.equals(messageType)) {
284             cbMsgXML.setState (true);
285         } else if (MESSAGE_WBXML.equals(messageType)) {
286             cbMsgWBXML.setState (true);
287         }
288
289         if (LOG_NONE.equals(logLevel)) {
290             cbLogNone.setState (true);
291         } else if (LOG_INFO.equals(logLevel)) {
292             cbLogInfo.setState (true);
293         } else if (LOG_DEBUG.equals (logLevel)) {
294             cbLogDebug.setState (true);
295         }
296
297     }
298
299     /**
300      * Returns an hashtable containing the values specified in the textfields.
301      * Note that this hashtable does not belong
302      * to a single node of the management tree.
303      *
304      * @return a list of values
305      */

306     protected Hashtable JavaDoc getFields() {
307
308         Hashtable JavaDoc tmpHashtable = new Hashtable JavaDoc();
309
310         String JavaDoc syncContact = null ;
311         String JavaDoc syncCalendar = null ;
312         String JavaDoc messageType = null ;
313         String JavaDoc logLevel = null ;
314
315         if (cbSyncContact.getState()) {
316             syncContact = SYNC_TWOWAY ;
317         } else {
318             syncContact = SYNC_NONE ;
319         }
320
321         if (cbSyncCalendar.getState()) {
322             syncCalendar = SYNC_TWOWAY ;
323         } else {
324             syncCalendar = SYNC_NONE ;
325         }
326
327         if (cbMsgXML.getState()) {
328             messageType = MESSAGE_XML;
329         } else if (cbMsgWBXML.getState ()) {
330             messageType = MESSAGE_WBXML;
331         }
332
333         if (cbLogNone.getState()) {
334             logLevel= LOG_NONE;
335         } else if (cbLogInfo.getState ()) {
336             logLevel= LOG_INFO;
337         } else if (cbLogDebug.getState()) {
338             logLevel= LOG_DEBUG;
339         }
340
341         tmpHashtable.put(PARAM_SYNCMLURL , tf1.getText () ) ;
342         tmpHashtable.put(PARAM_USERNAME , tf2.getText () ) ;
343         tmpHashtable.put(PARAM_PASSWORD , tf3.getText () ) ;
344         tmpHashtable.put(PARAM_SOURCEURICONTACT , tf4.getText () ) ;
345         tmpHashtable.put(PARAM_SOURCEURICALENDAR , tf5.getText () ) ;
346         tmpHashtable.put(PARAM_DEVICEID , tf6.getText () ) ;
347         tmpHashtable.put(PARAM_SYNCCONTACT , syncContact ) ;
348         tmpHashtable.put(PARAM_SYNCCALENDAR , syncCalendar ) ;
349         tmpHashtable.put(PARAM_MESSAGETYPE , messageType ) ;
350         tmpHashtable.put(PARAM_LOGLEVEL , logLevel ) ;
351
352         return tmpHashtable;
353     }
354
355
356     //--------------------------------------------------------- Private methods
357

358 }
Popular Tags