1 18 package sync4j.syncclient.ipod.panels; 19 20 import java.util.Hashtable ; 21 import java.io.File ; 22 23 import java.awt.Color ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 27 import javax.swing.JDialog ; 28 import javax.swing.JPanel ; 29 import javax.swing.JButton ; 30 import javax.swing.ButtonGroup ; 31 import javax.swing.JComboBox ; 32 import javax.swing.JCheckBox ; 33 import javax.swing.JRadioButton ; 34 import javax.swing.JLabel ; 35 import javax.swing.UIManager ; 36 import javax.swing.border.*; 37 import javax.swing.SwingConstants ; 38 39 import sync4j.syncclient.ipod.MainWindow; 40 import sync4j.syncclient.ipod.utils.*; 41 42 48 public class SyncSetPanel extends JDialog implements ActionListener , Constants { 49 50 private Hashtable htFields = new Hashtable (); 52 private MainWindow mainWindow ; 53 private boolean modal = false ; 54 55 private JButton btRemoteSet; 56 private JCheckBox cbContacts ; 57 private JCheckBox cbCalendars; 58 private JCheckBox cbNotes ; 59 private JPanel jpOver ; 60 private JPanel jpUp ; 61 private JPanel jpDown ; 62 private JButton btOk ; 63 private JButton btCancel ; 64 private JLabel jLabel ; 65 private JLabel jLabel2 ; 66 private JComboBox jcDriver ; 67 private JRadioButton jrNoneLog ; 68 private JRadioButton jrInfoLog ; 69 private JRadioButton jrDebugLog ; 70 71 private Hashtable htContactValues = null; 72 private Hashtable htCalendarValues = null; 73 private Hashtable htNoteValues = null; 74 private Hashtable htSyncmlValues = null; 75 76 78 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 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 () ; 106 cbContacts = new JCheckBox (); 107 cbCalendars = new JCheckBox (); 108 cbNotes = new JCheckBox (); 109 btRemoteSet = new JButton () ; 110 jpUp = new JPanel () ; 111 jpDown = new JPanel () ; 112 btOk = new JButton () ; 113 btCancel = new JButton () ; 114 jLabel = new JLabel () ; 115 jLabel2 = new JLabel () ; 116 jrNoneLog = new JRadioButton (); 117 jrInfoLog = new JRadioButton (); 118 jrDebugLog = new JRadioButton (); 119 120 try { 121 UIManager.setLookAndFeel(lookAndFeel); 122 } catch(Exception e) { 123 e.printStackTrace(); 124 } 125 126 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 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 (204,204,204), 1, true), 152 Language.getMessage(Language.LABEL_TITLE_SYNCSETWINDOW), 153 1, 154 0, 155 font, 156 new Color (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 () { 169 public void actionPerformed(ActionEvent 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 () { 183 public void actionPerformed(ActionEvent 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 () { 197 public void actionPerformed(ActionEvent 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 (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 (204,204,204), 1, true), 223 Language.getMessage(Language.LABEL_SYNCSET_OTHER), 224 1, 225 0, 226 font, 227 new Color (0,51,204)) 228 ); 229 230 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 (File.listRoots()); 240 jcDriver.setBounds(110,15,100,23); 241 jcDriver.setEditable(false); 242 jcDriver.setSelectedIndex(0); 243 jcDriver.addActionListener(new ActionListener () { 244 public void actionPerformed(ActionEvent evt) { 245 jcDriverActionPerformed(evt); 246 } 247 }); 248 jpDown.add(jcDriver); 249 250 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 () { 265 public void actionPerformed(ActionEvent 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 () { 277 public void actionPerformed(ActionEvent 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 () { 289 public void actionPerformed(ActionEvent evt) { 290 jrDebugLogActionPerformed(); 291 } 292 }); 293 jpDown.add(jrDebugLog); 294 295 ButtonGroup group = new ButtonGroup (); 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 e) { 375 JComboBox cb = (JComboBox )e.getSource(); 376 String driverSel = ((File )cb.getSelectedItem()).getPath(); 377 htFields.put(PARAM_SYNCSOURCEDRIVE, driverSel); 378 } 379 380 public void actionPerformed(ActionEvent 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 398 private void setSyncConfigStored() { 399 400 String contactSyncMode = (String )htContactValues.get(PARAM_SYNCMODE) ; 401 String calendarSyncMode = (String )htCalendarValues.get(PARAM_SYNCMODE); 402 String noteSyncMode = (String )htNoteValues.get(PARAM_SYNCMODE) ; 403 String sourceDrive = (String )htContactValues.get(PARAM_SYNCSOURCEDRIVE); 404 String logLevel = (String )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 (sourceDrive)); 441 } else { 442 jcDriver.setSelectedIndex(0); 443 String driverDefault = ((File )jcDriver.getSelectedItem()).getPath(); 444 htFields.put(PARAM_SYNCSOURCEDRIVE, driverDefault); 445 } 446 } 447 448 } 449 | Popular Tags |