1 18 19 package sync4j.syncclient.demo; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Button ; 23 import java.awt.Checkbox ; 24 import java.awt.CheckboxGroup ; 25 import java.awt.GridLayout ; 26 import java.awt.Label ; 27 import java.awt.Panel ; 28 import java.awt.TextField ; 29 30 import java.awt.event.ActionEvent ; 31 import java.awt.event.ActionListener ; 32 33 import java.util.Hashtable ; 34 35 42 public class Configuration 43 extends Panel 44 implements ActionListener , 45 ConfigurationParameters { 46 47 49 private final static String SYNC_NONE = "none" ; 50 private final static String SYNC_TWOWAY = "two-way" ; 51 52 54 private MainWindow mw = null ; 58 59 private TextField tf1 = null ; 60 private TextField tf2 = null ; 61 private TextField tf3 = null ; 62 private TextField tf4 = null ; 63 private TextField tf5 = null ; 64 private TextField tf6 = null ; 65 66 private Checkbox cbSyncContact = null ; 70 private Checkbox cbSyncCalendar = null ; 71 72 private CheckboxGroup cbgMessageType = null ; 76 private CheckboxGroup cbgLogLevel = null ; 77 private Checkbox cbMsgXML = null ; 78 private Checkbox cbMsgWBXML = null ; 79 private Checkbox cbLogNone = null ; 80 private Checkbox cbLogInfo = null ; 81 private Checkbox cbLogDebug = null ; 82 83 private Language ln = new Language() ; 84 85 87 92 public Configuration(MainWindow mw) { 93 94 Panel configPanel = null ; 95 Panel buttonPanel = null ; 96 Panel messagePanel = null ; 97 Panel logPanel = null ; 98 99 Button butOk = null ; 100 Button butCancel = null ; 101 102 Label lb1 = null ; 103 Label lb2 = null ; 104 Label lb3 = null ; 105 Label lb4 = null ; 106 Label lb5 = null ; 107 Label lb6 = null ; 108 Label lb7 = null ; 109 Label lb8 = null ; 110 Label lb10 = null ; 111 Label lb11 = null ; 112 113 this.mw = mw; 114 115 setLayout(new BorderLayout ()); 116 117 configPanel = new Panel (); 118 configPanel.setLayout (new GridLayout (12, 2)); 119 120 messagePanel = new Panel (); 121 messagePanel.setLayout(new GridLayout (1, 2)); 122 123 logPanel = new Panel (); 124 logPanel.setLayout (new GridLayout (1, 3)); 125 126 lb1 = new Label (ln.getString ("sync_server_url" ) ) ; 127 lb2 = new Label (ln.getString ("username" ) ) ; 128 lb3 = new Label (ln.getString ("password" ) ) ; 129 lb4 = new Label (ln.getString ("remote_address_book" ) ) ; 130 lb5 = new Label (ln.getString ("remote_calendar" ) ) ; 131 lb6 = new Label (ln.getString ("synchronizing_address_book" ) ) ; 132 lb7 = new Label (ln.getString ("synchronizing_calendar" ) ) ; 133 lb8 = new Label (ln.getString ("device_id" ) ) ; 134 lb10 = new Label (ln.getString ("message_type" ) ) ; 135 lb11 = new Label (ln.getString ("log_level" ) ) ; 136 137 tf1 = new TextField () ; 138 tf2 = new TextField () ; 139 tf3 = new TextField () ; 140 tf3.setEchoChar('*'); 141 tf4 = new TextField () ; 142 tf5 = new TextField () ; 143 tf6 = new TextField () ; 144 145 cbSyncContact = new Checkbox () ; 146 cbSyncCalendar = new Checkbox () ; 147 148 cbgMessageType = new CheckboxGroup () ; 149 cbgLogLevel = new CheckboxGroup () ; 150 151 cbMsgXML = new Checkbox (ln.getString ("xml" ) , 152 cbgMessageType , 153 true ); 154 155 cbMsgWBXML = new Checkbox (ln.getString ("wbxml" ) , 156 cbgMessageType , 157 false ); 158 159 cbLogNone = new Checkbox (ln.getString ("none" ) , 160 cbgLogLevel , 161 false ); 162 163 cbLogInfo = new Checkbox (ln.getString ("info" ) , 164 cbgLogLevel , 165 true ); 166 167 cbLogDebug = new Checkbox (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 (ln.getString ("ok" ) ) ; 203 butOk.setActionCommand ("ok" ) ; 204 butOk.addActionListener (this ) ; 205 206 butCancel = new Button (ln.getString ("cancel" ) ) ; 207 butCancel.setActionCommand ("cancel" ) ; 208 butCancel.addActionListener (this ) ; 209 210 buttonPanel = new Panel (); 211 buttonPanel.setLayout (new GridLayout (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 225 public void actionPerformed(ActionEvent 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 237 246 protected void setAllFields(Hashtable values , 247 Hashtable xmlContactValues , 248 Hashtable xmlCalendarValues ) { 249 250 String syncContact = null ; 251 String syncCalendar = null ; 252 String messageType = null ; 253 String logLevel = null ; 254 255 tf1.setText ((String ) values.get (PARAM_SYNCMLURL) ) ; 256 tf2.setText ((String ) values.get (PARAM_USERNAME) ) ; 257 tf3.setText ((String ) values.get (PARAM_PASSWORD) ) ; 258 tf4.setText ((String ) xmlContactValues.get 259 (PARAM_SOURCEURI) ) ; 260 tf5.setText ((String ) xmlCalendarValues.get 261 (PARAM_SOURCEURI) ) ; 262 tf6.setText ((String ) values.get (PARAM_DEVICEID) ) ; 263 264 syncContact = (String ) xmlContactValues.get 265 (PARAM_SYNCMODE ) ; 266 syncCalendar = (String ) xmlCalendarValues.get 267 (PARAM_SYNCMODE ) ; 268 messageType = (String ) values.get (PARAM_MESSAGETYPE ) ; 269 logLevel = (String ) 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 306 protected Hashtable getFields() { 307 308 Hashtable tmpHashtable = new Hashtable (); 309 310 String syncContact = null ; 311 String syncCalendar = null ; 312 String messageType = null ; 313 String 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 358 } | Popular Tags |