KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > ipod > panels > SyncSetPanel


1 /**
2  * Copyright (C) 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 package sync4j.syncclient.ipod.panels;
19
20 import java.util.Hashtable JavaDoc;
21 import java.io.File JavaDoc;
22
23 import java.awt.Color JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26
27 import javax.swing.JDialog JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.JButton JavaDoc;
30 import javax.swing.ButtonGroup JavaDoc;
31 import javax.swing.JComboBox JavaDoc;
32 import javax.swing.JCheckBox JavaDoc;
33 import javax.swing.JRadioButton JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35 import javax.swing.UIManager JavaDoc;
36 import javax.swing.border.*;
37 import javax.swing.SwingConstants JavaDoc;
38
39 import sync4j.syncclient.ipod.MainWindow;
40 import sync4j.syncclient.ipod.utils.*;
41
42 /**
43  * The Synchronization settings window.
44  *
45  * @author Luigia Fassina @ Funambol
46  * @version $Id: SyncSetPanel.java,v 1.4 2005/04/04 16:14:45 luigiafassina Exp $
47  */

48 public class SyncSetPanel extends JDialog JavaDoc implements ActionListener JavaDoc, Constants JavaDoc {
49
50     // ------------------------------------------- Private Data
51
private Hashtable JavaDoc htFields = new Hashtable JavaDoc();
52     private MainWindow mainWindow ;
53     private boolean modal = false ;
54
55     private JButton JavaDoc btRemoteSet;
56     private JCheckBox JavaDoc cbContacts ;
57     private JCheckBox JavaDoc cbCalendars;
58     private JCheckBox JavaDoc cbNotes ;
59     private JPanel JavaDoc jpOver ;
60     private JPanel JavaDoc jpUp ;
61     private JPanel JavaDoc jpDown ;
62     private JButton JavaDoc btOk ;
63     private JButton JavaDoc btCancel ;
64     private JLabel JavaDoc jLabel ;
65     private JLabel JavaDoc jLabel2 ;
66     private JComboBox JavaDoc jcDriver ;
67     private JRadioButton JavaDoc jrNoneLog ;
68     private JRadioButton JavaDoc jrInfoLog ;
69     private JRadioButton JavaDoc jrDebugLog ;
70
71     private Hashtable JavaDoc htContactValues = null;
72     private Hashtable JavaDoc htCalendarValues = null;
73     private Hashtable JavaDoc htNoteValues = null;
74     private Hashtable JavaDoc htSyncmlValues = null;
75
76     // ------------------------------------------ Public Methods
77

78     /** Creates new form JDialog */
79     public SyncSetPanel(MainWindow mainWindow, boolean modal) {
80         super(mainWindow, modal);
81         this.mainWindow = mainWindow;
82         this.modal = modal ;
83
84         htContactValues = mainWindow.getXmlContactValues() ;
85         htCalendarValues = mainWindow.getXmlCalendarValues();
86         htNoteValues = mainWindow.getXmlNoteValues() ;
87         htSyncmlValues = mainWindow.getSyncmlValues() ;
88
89         initComponents();
90         setSyncConfigStored();
91     }
92
93     /**
94      * This method is called from within the constructor to
95      * initialize the form.
96      */

97     private void initComponents() {
98         int xcb = 10 ;
99         int wcb = 80 ;
100         int hcb = 23 ;
101         int ybt = 235;
102         int wbt = 88 ;
103         int hbt = 24 ;
104
105         jpOver = new JPanel JavaDoc() ;
106         cbContacts = new JCheckBox JavaDoc();
107         cbCalendars = new JCheckBox JavaDoc();
108         cbNotes = new JCheckBox JavaDoc();
109         btRemoteSet = new JButton JavaDoc() ;
110         jpUp = new JPanel JavaDoc() ;
111         jpDown = new JPanel JavaDoc() ;
112         btOk = new JButton JavaDoc() ;
113         btCancel = new JButton JavaDoc() ;
114         jLabel = new JLabel JavaDoc() ;
115         jLabel2 = new JLabel JavaDoc() ;
116         jrNoneLog = new JRadioButton JavaDoc();
117         jrInfoLog = new JRadioButton JavaDoc();
118         jrDebugLog = new JRadioButton JavaDoc();
119
120         try {
121             UIManager.setLookAndFeel(lookAndFeel);
122         } catch(Exception JavaDoc e) {
123             e.printStackTrace();
124         }
125
126         //
127
// Set up the window.
128
//
129
getContentPane().setLayout(null);
130         setTitle(Language.getMessage(Language.LABEL_TITLE_SYNCSETWINDOW));
131         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
132         setSize(310,310);
133         setLocationRelativeTo(null);
134         setFont(font);
135         setName("syncSetDialog");
136         setResizable(false);
137
138         jpOver.setLayout(null);
139         jpOver.setBackground(Color.WHITE);
140         jpOver.setForeground(Color.WHITE);
141         jpOver.setBounds(0, 0, 310, 310);
142         getContentPane().add(jpOver);
143
144         //
145
// Internal panel for Synchronization Settings
146
//
147
jpUp.setLayout(null);
148         jpUp.setBounds(8, 16, 290, 129);
149         jpUp.setBackground(Color.WHITE);
150         jpUp.setBorder(new TitledBorder(
151                             new LineBorder(new Color JavaDoc(204,204,204), 1, true),
152                             Language.getMessage(Language.LABEL_TITLE_SYNCSETWINDOW),
153                             1,
154                             0,
155                             font,
156                             new Color JavaDoc(0,51,204))
157         );
158         jpUp.setName("syncSet");
159
160         cbContacts.setText(Language.getMessage(Language.LABEL_SYNCSET_CONTACTS));
161         cbContacts.setName("cbContacts");
162         cbContacts.setFont(font);
163         cbContacts.setBackground(Color.WHITE);
164         cbContacts.setBounds(xcb, 22, wcb, hcb);
165         cbContacts.setSelected(true);
166         cbContacts.setVerticalAlignment(SwingConstants.CENTER);
167         cbContacts.requestFocusInWindow();
168         cbContacts.addActionListener(new ActionListener JavaDoc() {
169             public void actionPerformed(ActionEvent JavaDoc evt) {
170                 cbContactsActionPerformed();
171             }
172         });
173         jpUp.add(cbContacts);
174
175         cbCalendars.setText(Language.getMessage(Language.LABEL_SYNCSET_CALENDARS));
176         cbCalendars.setName("cbCalendars");
177         cbCalendars.setFont(font);
178         cbCalendars.setBackground(Color.WHITE);
179         cbCalendars.setBounds(xcb, 45, wcb, hcb);
180         cbCalendars.setSelected(true);
181         cbCalendars.setVerticalAlignment(SwingConstants.CENTER);
182         cbCalendars.addActionListener(new ActionListener JavaDoc() {
183             public void actionPerformed(ActionEvent JavaDoc evt) {
184                 cbCalendarsActionPerformed();
185             }
186         });
187         jpUp.add(cbCalendars);
188
189         cbNotes.setText(Language.getMessage(Language.LABEL_SYNCSET_NOTES));
190         cbNotes.setName("cbNotes");
191         cbNotes.setFont(font);
192         cbNotes.setBackground(Color.WHITE);
193         cbNotes.setBounds(xcb, 67, wcb, hcb);
194         cbNotes.setSelected(false);
195         cbNotes.setVerticalAlignment(SwingConstants.CENTER);
196         cbNotes.addActionListener(new ActionListener JavaDoc() {
197             public void actionPerformed(ActionEvent JavaDoc evt) {
198                 cbNotesActionPerformed();
199             }
200         });
201         cbNotes.setVisible(false);
202         jpUp.add(cbNotes);
203
204         btRemoteSet.setActionCommand("REMOTESET");
205         btRemoteSet.setName("btRemoteSet");
206         btRemoteSet.setFont(font);
207         btRemoteSet.setBounds(176, 45, wbt, hbt);
208         btRemoteSet.setText(Language.getMessage(Language.BT_REMOTE_SET));
209         btRemoteSet.setHorizontalTextPosition(SwingConstants.LEFT);
210         btRemoteSet.setVerticalAlignment(SwingConstants.CENTER);
211         btRemoteSet.setMargin(new java.awt.Insets JavaDoc(2, 1, 2, 1));
212         btRemoteSet.addActionListener(this);
213
214         jpUp.add(btRemoteSet);
215
216         jpOver.add(jpUp);
217
218         jpDown.setLayout(null);
219         jpDown.setBackground(Color.WHITE);
220         jpDown.setBounds(8, 149, 290, 80);
221         jpDown.setBorder(new TitledBorder(
222                             new LineBorder(new Color JavaDoc(204,204,204), 1, true),
223                             Language.getMessage(Language.LABEL_SYNCSET_OTHER),
224                             1,
225                             0,
226                             font,
227                             new Color JavaDoc(0,51,204))
228         );
229
230         //
231
// List of drivers: select that of the IPod
232
//
233
jLabel.setText(Language.getMessage(Language.LABEL_SYNCSET_DRIVE));
234         jLabel.setFont(font);
235         jLabel.setVerticalAlignment(SwingConstants.CENTER);
236         jLabel.setBounds(10, 15, 90, 23);
237         jpDown.add(jLabel);
238
239         jcDriver = new JComboBox JavaDoc(File.listRoots());
240         jcDriver.setBounds(110,15,100,23);
241         jcDriver.setEditable(false);
242         jcDriver.setSelectedIndex(0);
243         jcDriver.addActionListener(new ActionListener JavaDoc() {
244             public void actionPerformed(ActionEvent JavaDoc evt) {
245                 jcDriverActionPerformed(evt);
246             }
247         });
248         jpDown.add(jcDriver);
249
250         //
251
// Radio button for logging level
252
//
253
jLabel2.setText(Language.getMessage(Language.LABEL_SYNCSET_LOGLEVEL));
254         jLabel2.setFont(font);
255         jLabel2.setVerticalAlignment(SwingConstants.CENTER);
256         jLabel2.setBounds(10, 45, 90, 23);
257         jpDown.add(jLabel2);
258
259         jrNoneLog.setSelected(true);
260         jrNoneLog.setText(Language.getMessage(Language.LABEL_SYNCSET_LOGNONE));
261         jrNoneLog.setFont(font);
262         jrNoneLog.setBackground(Color.WHITE);
263         jrNoneLog.setBounds(105,45,55,20);
264         jrNoneLog.addActionListener(new ActionListener JavaDoc() {
265             public void actionPerformed(ActionEvent JavaDoc evt) {
266                 jrNoneLogActionPerformed();
267             }
268         });
269         jpDown.add(jrNoneLog);
270
271         jrInfoLog.setSelected(false);
272         jrInfoLog.setText(Language.getMessage(Language.LABEL_SYNCSET_LOGINFO));
273         jrInfoLog.setFont(font);
274         jrInfoLog.setBackground(Color.WHITE);
275         jrInfoLog.setBounds(165,45,50,20);
276         jrInfoLog.addActionListener(new ActionListener JavaDoc() {
277             public void actionPerformed(ActionEvent JavaDoc evt) {
278                 jrInfoLogActionPerformed();
279             }
280         });
281         jpDown.add(jrInfoLog);
282
283         jrDebugLog.setSelected(false);
284         jrDebugLog.setText(Language.getMessage(Language.LABEL_SYNCSET_LOGDEBUG));
285         jrDebugLog.setFont(font);
286         jrDebugLog.setBackground(Color.WHITE);
287         jrDebugLog.setBounds(215,45,60,20);
288         jrDebugLog.addActionListener(new ActionListener JavaDoc() {
289             public void actionPerformed(ActionEvent JavaDoc evt) {
290                 jrDebugLogActionPerformed();
291             }
292         });
293         jpDown.add(jrDebugLog);
294
295         //
296
//Group the radio buttons.
297
//
298
ButtonGroup JavaDoc group = new ButtonGroup JavaDoc();
299         group.add(jrNoneLog);
300         group.add(jrInfoLog);
301         group.add(jrDebugLog);
302
303         jpOver.add(jpDown);
304
305         btOk.setText(Language.getMessage(Language.BT_OK));
306         btOk.setActionCommand("OK");
307         btOk.setName("btOk");
308         btOk.setFont(font);
309         btOk.setBounds(112, ybt, wbt, hbt);
310         btOk.addActionListener(this);
311
312         jpOver.add(btOk);
313
314         btCancel.setText(Language.getMessage(Language.BT_CANCEL));
315         btCancel.setActionCommand("CANCEL");
316         btCancel.setName("btCancel");
317         btCancel.setBounds(210, ybt, wbt, hbt);
318         btCancel.setFont(font);
319         btCancel.addActionListener(this);
320         jpOver.add(btCancel);
321
322         cbContacts.setNextFocusableComponent(cbCalendars);
323         cbCalendars.setNextFocusableComponent(cbNotes) ;
324         cbNotes.setNextFocusableComponent(jcDriver) ;
325         jcDriver.setNextFocusableComponent(jrNoneLog) ;
326         jrNoneLog.setNextFocusableComponent(jrInfoLog) ;
327         jrInfoLog.setNextFocusableComponent(jrDebugLog) ;
328         jrDebugLog.setNextFocusableComponent(btRemoteSet);
329         btRemoteSet.setNextFocusableComponent(btOk) ;
330         btOk.setNextFocusableComponent(btCancel) ;
331         btCancel.setNextFocusableComponent(cbContacts) ;
332     }
333
334     private void cbContactsActionPerformed() {
335         if (cbContacts.isSelected()) {
336             htFields.put(PARAM_SYNCCONTACT, SYNC_TWOWAY);
337         } else {
338             htFields.put(PARAM_SYNCCONTACT, SYNC_NONE);
339         }
340     }
341
342     private void cbCalendarsActionPerformed() {
343         if (cbCalendars.isSelected()) {
344             htFields.put(PARAM_SYNCCALENDAR, SYNC_TWOWAY);
345         } else {
346             htFields.put(PARAM_SYNCCALENDAR, SYNC_NONE);
347         }
348     }
349
350     private void cbNotesActionPerformed() {
351         if (cbNotes.isSelected()) {
352             htFields.put(PARAM_SYNCNOTE, SYNC_TWOWAY);
353         } else {
354             htFields.put(PARAM_SYNCNOTE, SYNC_NONE);
355         }
356     }
357
358     private void jrNoneLogActionPerformed() {
359         if (jrNoneLog.isSelected()) {
360             htFields.put(PARAM_LOGLEVEL, LOG_NONE);
361         }
362     }
363     private void jrInfoLogActionPerformed() {
364         if (jrInfoLog.isSelected()) {
365             htFields.put(PARAM_LOGLEVEL, LOG_INFO);
366         }
367     }
368     private void jrDebugLogActionPerformed() {
369         if (jrDebugLog.isSelected()) {
370             htFields.put(PARAM_LOGLEVEL, LOG_DEBUG);
371         }
372     }
373
374     public void jcDriverActionPerformed(ActionEvent JavaDoc e) {
375         JComboBox JavaDoc cb = (JComboBox JavaDoc)e.getSource();
376         String JavaDoc driverSel = ((File JavaDoc)cb.getSelectedItem()).getPath();
377         htFields.put(PARAM_SYNCSOURCEDRIVE, driverSel);
378     }
379
380     public void actionPerformed(ActionEvent JavaDoc evt) {
381         if (evt.getActionCommand().equals("OK")) {
382             mainWindow.writeSyncSettings(htFields);
383             removeAll();
384             setVisible(false);
385         } else if (evt.getActionCommand().equals("CANCEL")) {
386             removeAll();
387             setVisible(false);
388         } else if (evt.getActionCommand().equals("REMOTESET")) {
389             RemoteSetPanel esp = new RemoteSetPanel(mainWindow,modal);
390             esp.show();
391         }
392     }
393
394     /**
395      * Sets the fields with some of the values contained
396      * in the specified Hashtables.
397      */

398     private void setSyncConfigStored() {
399
400         String JavaDoc contactSyncMode = (String JavaDoc)htContactValues.get(PARAM_SYNCMODE) ;
401         String JavaDoc calendarSyncMode = (String JavaDoc)htCalendarValues.get(PARAM_SYNCMODE);
402         String JavaDoc noteSyncMode = (String JavaDoc)htNoteValues.get(PARAM_SYNCMODE) ;
403         String JavaDoc sourceDrive = (String JavaDoc)htContactValues.get(PARAM_SYNCSOURCEDRIVE);
404         String JavaDoc logLevel = (String JavaDoc)htSyncmlValues.get(PARAM_LOGLEVEL);
405
406         htFields.put(PARAM_SYNCCONTACT , contactSyncMode );
407         htFields.put(PARAM_SYNCCALENDAR, calendarSyncMode);
408         htFields.put(PARAM_SYNCNOTE , noteSyncMode );
409
410         htFields.put(PARAM_LOGLEVEL , logLevel );
411
412         if (SYNC_TWOWAY.equals(contactSyncMode)) {
413             cbContacts.setSelected(true);
414         } else {
415             cbContacts.setSelected(false);
416         }
417
418         if (SYNC_TWOWAY.equals(calendarSyncMode)) {
419             cbCalendars.setSelected(true);
420         } else {
421             cbCalendars.setSelected(false);
422         }
423
424         if (SYNC_TWOWAY.equals(noteSyncMode)) {
425             cbNotes.setSelected(true);
426         } else {
427             cbNotes.setSelected(false);
428         }
429
430         if(logLevel.equals(LOG_NONE)) {
431             jrNoneLog.setSelected(true);
432         } else if(logLevel.equals(LOG_INFO)) {
433             jrInfoLog.setSelected(true);
434         } else if(logLevel.equals(LOG_DEBUG)) {
435             jrDebugLog.setSelected(true);
436         }
437
438         if (sourceDrive != null) {
439             htFields.put(PARAM_SYNCSOURCEDRIVE, sourceDrive);
440             jcDriver.setSelectedItem(new File JavaDoc(sourceDrive));
441         } else {
442             jcDriver.setSelectedIndex(0);
443             String JavaDoc driverDefault = ((File JavaDoc)jcDriver.getSelectedItem()).getPath();
444             htFields.put(PARAM_SYNCSOURCEDRIVE, driverDefault);
445         }
446     }
447
448 }
449
Popular Tags