1 import java.awt.*; 2 import java.awt.event.*; 3 import java.awt.image.ImageObserver ; 4 import java.io.*; 5 import java.util.ArrayList ; 6 import java.util.Enumeration ; 7 import java.util.ListResourceBundle ; 8 import java.util.Properties ; 9 import javax.swing.*; 10 import javax.swing.border.TitledBorder ; 11 import javax.swing.event.*; 12 import javax.accessibility.Accessible ; 13 import org.jivesoftware.smack.*; 14 import org.jivesoftware.smack.filter.*; 15 import org.jivesoftware.smack.packet.*; 16 17 19 public final class OptionsDialog2 extends JDialog implements Accessible , ImageObserver , MenuContainer, RootPaneContainer, Serializable, SwingConstants,WindowConstants{ 20 21 public final static int GAP=10; 22 public final static int TEXTFIELD_SIZE=15; 23 public static final String PREFIX="opt_"; 24 25 private static final String [] CATEGORIES={"general","actions","lang","inactivity","laf","layout","colours","new message","new chat","contact online","account settings"}; 26 private static final int ACCOUNT_SETTINGS_INDEX=10; 27 28 final static private String [] DOUBLECLICK_OPTIONS={"default","message","chat"}; 29 final private static String [] LEFT_RIGHT={"left","right"}; 30 final static private String [] CLOSE_OPTIONS={"hide","quit"}; 31 final static private String [] LAF_OPTIONS={"metal","native"}; 32 final static private String [] LAF_DISPLAY={"Metal",System.getProperty("os.name")}; 33 34 private final Box listbox=new Box(BoxLayout.X_AXIS); 35 private final JList catList=new JList(CATEGORIES); 36 private final JScrollPane catListSP=new JScrollPane(catList); 37 38 private final static ArrayList C1=new ArrayList (3); 39 private final static ArrayList C2=new ArrayList (2); 40 private final static ArrayList C3=new ArrayList (1); 41 private final static ArrayList C4=new ArrayList (3); 42 private final static ArrayList C5=new ArrayList (1); 43 private final static ArrayList C6=new ArrayList (2); 44 private final static ArrayList C7=new ArrayList (4); 45 private final static ArrayList C8=new ArrayList (2); 46 private final static ArrayList C9=new ArrayList (2); 47 private final static ArrayList C10=new ArrayList (2); 48 private final static ArrayList [] optionGroups={C1,C2,C3,C4,C5,C6,C7,C8,C9,C10}; 49 50 private final JPanel panel=new JPanel(new SpringLayout()); 51 private final TitledBorder titleBorder=new TitledBorder (""); 52 53 final static public JFileChooser fileChooser=new JFileChooser(); 54 final private ExampleFileFilter filter=new ExampleFileFilter(); 55 56 final private JLabel jidLbl=new JLabel(); 58 final private JLabel resourceLbl=new JLabel(); 59 final private JTextField resource=new JTextField(TEXTFIELD_SIZE); 60 final private JCheckBox ssl=new JCheckBox(); 61 final private JLabel passwordLbl=new JLabel(); 62 final JPasswordField password=new JPasswordField(TEXTFIELD_SIZE); 63 final private JCheckBox rememeberPassword=new JCheckBox(); 64 final private JPanel changePasswordBtnPanel=new JPanel(new FlowLayout(FlowLayout.RIGHT,0,0)); 65 final private JButton changePasswordBtn=new JButton(); 66 final private JPanel deleteAccountBtnPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,GAP)); 67 final private JButton deleteAccountBtn=new JButton(); 68 final private JButton changePassphraseBtn=new JButton(); 69 final private JPanel btnPanel=new JPanel(new FlowLayout(FlowLayout.RIGHT,GAP,GAP)); 71 final private JButton resetBtn=new JButton(Lang.gs("reset"),Icons.RESET); 72 final private JButton saveBtn=new JButton(Lang.gs("save"),Icons.SAVE); 73 final JButton cancelBtn=new JButton(Lang.gs("cancel"),Icons.CANCEL); 74 75 final private BtnClick click=new BtnClick(); 76 final private Renderer renderer=new Renderer(); 77 final OptionsDialog2 dialog=this; 78 private final static Properties prop=new Properties (); 79 public boolean needToSaveAccountSettings=false; 80 81 public OptionsDialog2(){ 82 super(WhisperIM.MainWindow,Lang.gs("menu_preferences"),false); 83 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 84 Container cp=getContentPane(); 85 cp.setLayout(new BorderLayout(GAP,GAP)); 86 C1.add(new Option("warn_unencrypted",Option.CHECKBOX)); 88 C1.add(new Option("emoticons",Option.CHECKBOX)); 89 C1.add(new Option("remember_window_size",Option.CHECKBOX)); 90 C2.add(new Option("double_click",DOUBLECLICK_OPTIONS)); 91 C2.add(new Option("close_action",CLOSE_OPTIONS)); 92 C3.add(new Option("lang",Lang.availableLanguageCodes)); 93 C4.add(new Option("idle_time",new SpinnerNumberModel(1,1,60,1))); 94 C4.add(new Option("auto_away",Option.CHECKBOX)); 95 C4.add(new Option("clear_keypair",Option.CHECKBOX)); 96 C5.add(new Option("laf",LAF_OPTIONS,LAF_DISPLAY)); 97 C6.add(new Option("contact_list_location",LEFT_RIGHT)); 98 C6.add(new Option("muc_list_location",LEFT_RIGHT)); 99 C7.add(new Option("text_colour",Option.COLOUR)); 100 C7.add(new Option("background_colour",Option.COLOUR)); 101 C7.add(new Option("text_size",new SpinnerNumberModel(1,1,12,1))); 102 C7.add(new Option("text_font",Option.TEXT)); 103 C8.add(new Option("alert_new_message",Option.CHECKBOX)); 104 C8.add(new Option("sound_alert_new_message",Option.SOUND)); 105 C9.add(new Option("alert_new_chat",Option.CHECKBOX)); 106 C9.add(new Option("sound_alert_new_chat",Option.SOUND)); 107 C10.add(new Option("alert_online",Option.CHECKBOX)); 108 C10.add(new Option("sound_alert_online",Option.SOUND)); 109 catList.setCellRenderer(renderer); 111 catList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 112 catList.setSelectedIndex(ACCOUNT_SETTINGS_INDEX); doPanel(); 114 catList.setLayoutOrientation(JList.VERTICAL); 115 catList.setVisibleRowCount(CATEGORIES.length); 116 catList.addListSelectionListener(new CatListener()); 117 GUI.setScrollBars(catListSP); 118 listbox.add(Box.createHorizontalStrut(GAP)); 119 listbox.add(catListSP); 120 cp.add(listbox,BorderLayout.WEST); 121 122 panel.setBorder(titleBorder); 123 titleBorder.setTitleJustification(TitledBorder.CENTER); 124 cp.add(panel,BorderLayout.CENTER); 125 126 changePassphraseBtn.addActionListener(click); 127 changePasswordBtn.addActionListener(click); 128 129 resetBtn.addActionListener(click); 130 saveBtn.addActionListener(click); 131 cancelBtn.addActionListener(click); 132 resetBtn.setMnemonic(Lang.s2k("reset_mn")); 133 saveBtn.setMnemonic(Lang.s2k("save_mn")); 134 cancelBtn.setMnemonic(Lang.s2k("cancel_mn")); 135 resetBtn.setToolTipText(Lang.gs("reset_tt")); 136 saveBtn.setToolTipText(Lang.gs("od_save_tt")); 137 cancelBtn.setToolTipText(Lang.gs("od_cancel_tt")); 138 btnPanel.add(resetBtn); 139 btnPanel.add(saveBtn); 140 btnPanel.add(cancelBtn); 141 cp.add(btnPanel,BorderLayout.SOUTH); 142 143 final javax.sound.sampled.AudioFileFormat.Type audioformats[]=javax.sound.sampled.AudioSystem.getAudioFileTypes(); 144 for(int i=0;i<audioformats.length;i++){ 145 filter.addExtension(audioformats[i].getExtension()); 146 } 147 filter.setDescription(Lang.gs("opt_sound files")); 148 fileChooser.setFileFilter(filter); 149 150 deleteAccountBtn.setVisible(false); getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(WhisperIM.HELP_KEY,0),"help"); getRootPane().getActionMap().put("help",new HelpAction(this,"options.html")); 154 155 getRootPane().setDefaultButton(saveBtn); 156 doSet(null); 157 pack(); 158 catList.setSelectedIndex(0); 159 addKeyListener(new KeyAction()); 161 addMouseListener(new MouseAction()); 162 } 163 164 public void show(){ 165 setLocationRelativeTo(WhisperIM.MainWindow); 166 password.setEditable(true); 167 cancelBtn.setEnabled(true); 168 super.show(); 169 } 170 171 172 public void doPanel(){ 173 getGlassPane().setVisible(true); 174 setCursor(GUI.WAIT); 175 panel.removeAll(); 176 int c=catList.getSelectedIndex(); 177 titleBorder.setTitle(Lang.gs(PREFIX+CATEGORIES[c])); 178 if(c==ACCOUNT_SETTINGS_INDEX){ 179 doAccountSettingsPanel(); 180 return; 181 } 182 panel.setLayout(new GridLayout(optionGroups[c].size()+1,1,0,0)); 183 for(int i=0; i<optionGroups[c].size() ;i++){ 184 panel.add( ((Option) optionGroups[c].get(i)).getComponent()); 185 } 186 panel.add(Box.createGlue()); 187 panel.validate(); 188 panel.repaint(); 189 setCursor(GUI.NORMAL); 190 getGlassPane().setVisible(false); 191 } 192 193 private void doAccountSettingsPanel(){ 194 panel.setLayout(new SpringLayout()); 195 final JPanel jabberPanel=new JPanel(new GridLayout(6,1,0,0)); 196 final TitledBorder jabberPanelBorder=new TitledBorder ("Jabber"); 197 final Box otherBox=new Box(BoxLayout.Y_AXIS); 198 jabberPanel.setBorder(jabberPanelBorder); 199 jabberPanel.add(jidLbl); 200 resourceLbl.setText(Lang.gs("jabber_resource")); 201 resource.setToolTipText(Lang.gs("jabber_resource_tt")); 202 final JPanel resourcePanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,0)); 203 resourcePanel.add(resourceLbl); 204 resourcePanel.add(resource); 205 jabberPanel.add(resourcePanel); 206 ssl.setText(Lang.gs("jabber_ssl")); 207 ssl.setToolTipText(Lang.gs("jabber_ssl_tt")); 208 jabberPanel.add(ssl); 209 passwordLbl.setText(Lang.gs("jabber_password")); 210 password.setToolTipText(Lang.gs("jabber_password_tt")); 211 final JPanel passwordPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,0)); 212 passwordPanel.add(passwordLbl); 213 passwordPanel.add(password); 214 jabberPanel.add(passwordPanel); 215 rememeberPassword.setText(Lang.gs("remember password")); 216 rememeberPassword.setToolTipText(Lang.gs("remember password_tt")); 217 jabberPanel.add(rememeberPassword); 218 changePasswordBtn.setText(Lang.gs("change password")); 219 changePasswordBtn.setToolTipText(Lang.gs("change password_tt")); 220 changePasswordBtnPanel.add(changePasswordBtn); 221 jabberPanel.add(changePasswordBtnPanel); 222 panel.add(jabberPanel); 223 final JPanel changePassphraseBtnPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,GAP)); 225 deleteAccountBtn.setText(Lang.gs("delete account")); 226 changePassphraseBtn.setText(Lang.gs("change passphrase")); 227 changePassphraseBtn.setToolTipText(Lang.gs("change passphrase_tt")); 228 229 changePassphraseBtnPanel.add(changePassphraseBtn); 230 otherBox.add(changePassphraseBtnPanel); 231 deleteAccountBtn.setToolTipText(Lang.gs("delete account_tt")); 232 deleteAccountBtn.addActionListener(click); 233 deleteAccountBtnPanel.add(deleteAccountBtn); 234 otherBox.add(deleteAccountBtnPanel); 235 otherBox.add(otherBox.createGlue()); 236 panel.add(otherBox); 237 SpringUtilities.makeCompactGrid(panel,2,1,0,0,0,0); 238 panel.validate(); 239 panel.repaint(); 240 setCursor(GUI.NORMAL); 241 getGlassPane().setVisible(false); 242 } 243 244 245 public void doSet(Object o){ 246 Enumeration e=WhisperIM.UserPref.propertyNames(); 247 String k; 248 while(e.hasMoreElements()){ 249 k=(String ) e.nextElement(); 250 prop.setProperty(k,WhisperIM.UserPref.getProperty(k)); 251 } 252 if(prop.getProperty("lang").equals("auto")){ 253 prop.setProperty("lang",Lang.gs("language_code")); 254 } 255 jidLbl.setText(WhisperIM.accountSettings.JabberUserName+"@"+WhisperIM.accountSettings.JabberServer); 256 resource.setText(WhisperIM.accountSettings.JabberResource); 257 password.setText(WhisperIM.accountSettings.JabberPassword); 258 ssl.setSelected(WhisperIM.accountSettings.JabberSSL); 259 rememeberPassword.setSelected(WhisperIM.accountSettings.JabberRememberPassword); 260 } 261 262 private void setLang(){ 263 setTitle(Lang.gs("menu_preferences")); 264 resetBtn.setText(Lang.gs("reset")); 265 saveBtn.setText(Lang.gs("save")); 266 cancelBtn.setText(Lang.gs("cancel")); 267 resetBtn.setMnemonic(Lang.s2k("reset_mn")); 268 saveBtn.setMnemonic(Lang.s2k("save_mn")); 269 cancelBtn.setMnemonic(Lang.s2k("cancel_mn")); 270 resetBtn.setToolTipText(Lang.gs("reset_tt")); 271 saveBtn.setToolTipText(Lang.gs("od_save_tt")); 272 cancelBtn.setToolTipText(Lang.gs("od_cancel_tt")); 273 filter.setDescription(Lang.gs("opt_sound files")); 274 catList.repaint(); 275 doPanel(); 276 } 277 278 private boolean s2b(String key){ 279 if(key.equals("true")){ 280 return true; 281 } 282 return false; 283 } 284 285 public void doCancel(){ 286 dispose(); 287 doSet(null); 288 } 289 290 public void doReset(){ 291 DefaultUserPref def=new DefaultUserPref(); 292 Enumeration e=def.propertyNames(); 293 String k; 294 while(e.hasMoreElements()){ 295 k=(String ) e.nextElement(); 296 prop.setProperty(k,def.getProperty(k)); 297 } 298 if(prop.getProperty("lang").equals("auto")){ 299 prop.setProperty("lang",Lang.gs("language_code")); 300 } 301 resource.setText(WhisperIM.accountSettings.JabberResource); 302 if(!needToSaveAccountSettings){ 303 password.setText(WhisperIM.accountSettings.JabberPassword); 304 } 305 ssl.setSelected(WhisperIM.accountSettings.JabberSSL); 306 rememeberPassword.setSelected(WhisperIM.accountSettings.JabberRememberPassword); 307 doPanel(); 308 GUI.showInfo(this,"menu_preferences","options reset"); 309 } 310 311 public void doSave(){ 312 setCursor(GUI.WAIT); 313 WhisperIM.UserPref.setProperty("lang",prop.getProperty("lang")); 315 if(!prop.getProperty("lang").equals(Lang.gs("language_code"))){ 316 GUI.loadLang(); 318 WhisperIM.MainWindow.setLang(); 319 setLang(); 320 } 321 if(!prop.getProperty("contact_list_location").equals(WhisperIM.UserPref.getProperty("contact_list_location"))){ 323 if(prop.getProperty("contact_list_location").equals("left")){ 324 WhisperIM.MainWindow.contactListOnLeft(); 325 } 326 else{ 327 WhisperIM.MainWindow.contactListOnRight(); 328 } 329 } 330 boolean needchangelaf=(!WhisperIM.UserPref.getProperty("laf").equals(prop.getProperty("laf"))); 332 Enumeration pn=WhisperIM.UserPref.propertyNames(); 334 String k; 335 while(pn.hasMoreElements()){ 336 k=(String ) pn.nextElement(); 337 WhisperIM.UserPref.setProperty(k,prop.getProperty(k)); 338 } 339 Idle.setTimeout(); 341 try{ 344 WhisperIM.UserPref.store(new FileOutputStream(new File(WhisperIM.userDir,WhisperIM.USER_PREF_FILE_NAME),false),"Whisper preferences"); 345 } 346 catch(Exception spe){ 347 setCursor(GUI.NORMAL); 348 GUI.showError(this,"od_save_tt","cannot save",spe.getMessage()); 349 return; 350 } 351 if(!resource.getText().equals(WhisperIM.accountSettings.JabberResource)){ 353 needToSaveAccountSettings=true; 354 } 355 if(ssl.isSelected()!=WhisperIM.accountSettings.JabberSSL){ 356 needToSaveAccountSettings=true; 357 } 358 if(rememeberPassword.isSelected()!=WhisperIM.accountSettings.JabberRememberPassword){ 359 needToSaveAccountSettings=true; 360 } 361 if(!(new String (password.getPassword())).equals(WhisperIM.accountSettings.JabberPassword)){ 362 needToSaveAccountSettings=true; 363 } 364 if(needToSaveAccountSettings){ 365 try{ 366 WhisperIM.accountSettings.JabberPassword=new String (password.getPassword()); 367 WhisperIM.accountSettings.JabberResource=resource.getText(); 368 WhisperIM.accountSettings.JabberRememberPassword=rememeberPassword.isSelected(); 369 WhisperIM.accountSettings.JabberSSL=ssl.isSelected(); 370 BackUp.backUp(new File(WhisperIM.userDir,AccountSettings.FILENAME)); 372 try{ 373 WhisperIM.accountSettings.Save(); 374 } 375 catch(Exception asse){ 376 try{ 378 BackUp.restore(new File(WhisperIM.userDir,AccountSettings.FILENAME)); 379 } 380 catch(Exception bue){ 381 System.err.println("Could not restore account settings"); 382 bue.printStackTrace(); 383 } 384 throw asse; 385 } 386 needToSaveAccountSettings=false; 387 } 388 catch(Exception e){ 389 GUI.showError(this,"save",null,e.getMessage()); 390 } 391 } 392 if(needchangelaf){ 394 try{ if(WhisperIM.UserPref.getProperty("laf").equals("metal")){ 396 UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel()); 398 } 399 else{ 400 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 401 } 402 WhisperIM.About.dispose(); 404 WhisperIM.About=new JAboutDialog(); 405 if(WhisperIM.Help_Window!=null){ 406 WhisperIM.Help_Window.dispose(); 407 WhisperIM.Help_Window=null; 408 } 409 SwingUtilities.updateComponentTreeUI(WhisperIM.MainWindow.getContentPane()); 410 SwingUtilities.updateComponentTreeUI(this.getContentPane()); 411 SwingUtilities.updateComponentTreeUI(fileChooser); 412 SwingUtilities.updateComponentTreeUI(WhisperIM.MainWindow.contactListPanel.groupPopup); 413 SwingUtilities.updateComponentTreeUI(WhisperIM.MainWindow.contactListPanel.userPopup); 414 SwingUtilities.updateComponentTreeUI(WhisperIM.MainWindow.contactListPanel.servicePopup); 415 SwingUtilities.updateComponentTreeUI(WhisperIM.MainWindow.menuBar); 416 if(WhisperIM.MainWindow.discoWindow!=null){ 417 WhisperIM.MainWindow.discoWindow.dispose(); 418 WhisperIM.MainWindow.discoWindow=null; 419 } 420 if(WhisperIM.MainWindow.myProfileWindow!=null){ 421 WhisperIM.MainWindow.myProfileWindow.dispose(); 422 WhisperIM.MainWindow.myProfileWindow=null; 423 } 424 if(WhisperIM.MainWindow.connectionDialog!=null){ 425 WhisperIM.MainWindow.connectionDialog.dispose(); 426 WhisperIM.MainWindow.connectionDialog=new ConnectionDialog(); 427 } 428 WhisperIM.currentLaf=WhisperIM.UserPref.getProperty("laf"); 429 } 430 catch(Exception lafe){ 431 GUI.showError(this,"options",null,lafe.getMessage()); 432 lafe.printStackTrace(); 433 } 434 } 435 setCursor(GUI.NORMAL); 436 GUI.showInfo(this,"menu_preferences","options saved"); 437 dispose(); 438 } 439 440 private String b2s(boolean b){ 441 if(b){ 442 return("true"); 443 } 444 else{ 445 return("false"); 446 } 447 } 448 449 private String colour2String(Color c){ 450 return "#"+s2(Integer.toHexString(c.getRed()))+s2(Integer.toHexString(c.getGreen()))+s2(Integer.toHexString(c.getBlue())); 451 } 452 453 private String s2(String number){ 454 if(number.length()>1){ 455 return number; 456 } 457 else{ 458 return "0"+number; 459 } 460 } 461 462 private boolean isConnected(String s){ 463 if(!WhisperIM.MainWindow.Conn.isConnected()){ 464 GUI.showWarning(this,s,"need to be connected"); 465 return false; 466 } 467 return true; 468 } 469 470 final class Option{ 471 public static final int CHECKBOX=0; 472 public static final int COMBOBOX=1; 473 public static final int TEXT=2; 474 public static final int NUMBER=3; 475 public static final int RAW_COMBOBOX=4; 476 public static final int COLOUR=5; 477 public static final int SOUND=6; 478 private final String name; 479 private final int type; 480 private String [] data; 481 private String [] display; 482 private SpinnerNumberModel snm; 483 484 public Option(String name,int type){ 485 this.name=name; 486 this.type=type; 487 } 488 489 public Option(String name,String [] data){ 490 this(name,COMBOBOX); 491 this.data=data; 492 } 493 494 public Option(String name,String [] data, String [] display){ 495 this(name,RAW_COMBOBOX); 496 this.data=data; 497 this.display=display; 498 } 499 500 public Option(String name, SpinnerNumberModel snm){ 501 this(name,NUMBER); 502 this.snm=snm; 503 } 504 505 public JComponent getComponent(){ 506 switch(type){ 507 case CHECKBOX: 508 JCheckBox cb=new JCheckBox(Lang.gs(PREFIX+name)); 509 cb.setSelected(s2b(prop.getProperty(name))); 510 cb.setToolTipText(Lang.gs(PREFIX+name+"_tt")); 511 cb.addActionListener(new ChangeListener(name,cb)); 512 return(cb); 513 case COMBOBOX: 514 JComboBox cmb=new JComboBox(data); 515 cmb.setSelectedItem(prop.getProperty(name)); 516 cmb.setEditable(false); 517 cmb.setRenderer(renderer); 518 cmb.addActionListener(new ChangeListener(name,cmb)); 519 return makePanel(cmb); 520 case RAW_COMBOBOX: 521 JComboBox cmb2=new JComboBox(data); 522 cmb2.setSelectedItem(prop.getProperty(name)); 523 cmb2.setEditable(false); 524 cmb2.setRenderer(new RawComboRenderer(data,display)); 525 cmb2.addActionListener(new ChangeListener(name,cmb2)); 526 return makePanel(cmb2); 527 case NUMBER: 528 JSpinner sp=new JSpinner(snm); 529 sp.setValue(new Integer (prop.getProperty(name))); 530 sp.addChangeListener(new SpinnerChangeListener(name,sp)); 531 return makePanel(sp); 532 case TEXT: 533 JTextField tf=new JTextField(TEXTFIELD_SIZE); 534 tf.setText(prop.getProperty(name)); 535 tf.addActionListener(new ChangeListener(name,tf)); 536 return makePanel(tf); 537 case COLOUR: 538 JButton b=new JButton(" "); 539 b.setBackground(Color.decode(prop.getProperty(name))); 540 b.addActionListener(new ColourChangeListener(name,b)); 541 return makePanel(b); 542 case SOUND: 543 return new SoundPanel(dialog,prop,name); 544 default: return new JLabel(); 545 } 546 } 547 548 private JPanel makePanel(JComponent c){ 549 JLabel l=new JLabel(Lang.gs(PREFIX+name)+":"); 550 JPanel p=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,GAP)); 551 c.setToolTipText(Lang.gs(PREFIX+name+"_tt")); 552 l.setToolTipText(Lang.gs(PREFIX+name+"_tt")); 553 p.add(l); 554 p.add(c); 555 return p; 556 } 557 } 558 559 560 final class BtnClick implements ActionListener{ 561 public void actionPerformed(ActionEvent ae){ 562 String b=ae.getActionCommand(); 564 if(b.equals(cancelBtn.getText())){ 566 doCancel(); 567 return; 568 } 569 if(b.equals(resetBtn.getText())){ 570 doReset(); 571 return; 572 } 573 if(b.equals(saveBtn.getText())){ 574 doSave(); 575 return; 576 } 577 if(b.equals(changePasswordBtn.getText())){ 578 if(!isConnected("change password")){ 579 return; 580 } 581 (new ChangeJabberPasswordDialog()).show(); 582 return; 583 } 584 if(b.equals(changePassphraseBtn.getText())){ 585 (new ChangePassphraseDialog()).show(); 586 return; 587 } 588 } 589 } 590 591 final class Renderer extends JLabel implements ListCellRenderer { 592 593 public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus){ 594 setText(Lang.gs(PREFIX+((String ) value))); 595 if(isSelected){ 596 setBackground(list.getSelectionBackground()); 597 setForeground(list.getSelectionForeground()); 598 } 599 else { 600 setBackground(list.getBackground()); 601 setForeground(list.getForeground()); 602 } 603 setEnabled(list.isEnabled()); 604 setFont(list.getFont()); 605 setOpaque(true); 606 return this; 607 } 608 } 609 610 final class RawComboRenderer extends JLabel implements ListCellRenderer { 611 private final String [] data; 612 private final String [] display; 613 614 public RawComboRenderer(String [] data,String [] display){ 615 this.data=data; 616 this.display=display; 617 } 618 public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus){ 619 if(index!=-1){ 620 setText(display[index]); 621 } 622 else{ 623 String v=(String ) value; 624 for(int i=0;i<display.length;i++){ 625 if(data[i].equals(v)){ 626 setText(display[i]); 627 break; 628 } 629 } 630 } 631 if(isSelected){ 632 setBackground(list.getSelectionBackground()); 633 setForeground(list.getSelectionForeground()); 634 } 635 else { 636 setBackground(list.getBackground()); 637 setForeground(list.getForeground()); 638 } 639 setEnabled(list.isEnabled()); 640 setFont(list.getFont()); 641 setOpaque(true); 642 return this; 643 } 644 } 645 646 final class CatListener implements ListSelectionListener{ 647 public void valueChanged(ListSelectionEvent e){ 648 doPanel(); 649 } 650 } 651 652 final class SpinnerChangeListener implements javax.swing.event.ChangeListener { 653 private final String key; 654 private final JSpinner sp; 655 656 public SpinnerChangeListener(String key, JSpinner sp){ 657 this.key=key; 658 this.sp=sp; 659 } 660 public void stateChanged(ChangeEvent e){ 661 prop.setProperty(key,( (Integer ) sp.getValue()).toString()); 662 } 663 } 664 665 final class ChangeListener implements ActionListener{ 666 private final String key; 667 private final JComponent c; 668 public ChangeListener(String key, JComponent c){ 669 this.key=key; 670 this.c=c; 671 } 672 public void actionPerformed(ActionEvent ae){ 673 if(c instanceof JComboBox){ 674 JComboBox cmb=(JComboBox) c; 675 prop.setProperty(key,(String ) cmb.getSelectedItem()); 676 return; 677 } 678 if(c instanceof JCheckBox){ 679 JCheckBox cb=(JCheckBox) c; 680 prop.setProperty(key,b2s(cb.isSelected())); 681 return; 682 } 683 if(c instanceof JTextField){ 684 JTextField tf=(JTextField) c; 685 prop.setProperty(key,tf.getText()); 686 return; 687 } 688 } 689 } 690 691 final class ColourChangeListener implements ActionListener{ 692 private final String key; 693 private final JButton b; 694 public ColourChangeListener(String key, JButton b){ 695 this.key=key; 696 this.b=b; 697 } 698 public void actionPerformed(ActionEvent ae){ 699 Color c=JColorChooser.showDialog(dialog,Lang.gs(PREFIX+key),b.getBackground()); 700 if(c!=null){ 701 b.setBackground(c); 702 prop.setProperty(key,colour2String(c)); 703 } 704 } 705 } 706 }
| Popular Tags
|