KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > OptionsDialog


1 import java.awt.*;
2 import java.awt.event.*;
3 import java.awt.image.ImageObserver JavaDoc;
4 import java.io.*;
5 import java.util.ListResourceBundle JavaDoc;
6 import java.util.Properties JavaDoc;
7 import javax.swing.*;
8 import javax.swing.border.*;
9 import javax.accessibility.Accessible JavaDoc;
10 import org.jivesoftware.smack.*;
11 import org.jivesoftware.smack.filter.*;
12 import org.jivesoftware.smack.packet.*;
13
14 /** Dialog for user preferences.*/
15 public final class OptionsDialog extends JDialog implements Accessible JavaDoc, ImageObserver JavaDoc, MenuContainer, RootPaneContainer, Serializable, SwingConstants,WindowConstants{
16     
17     private final static int GAP=5;
18     private final static int TEXTFIELD_SIZE=15;
19         
20     final JTabbedPane tabs=new JTabbedPane();
21         
22         final private Box generalBox=new Box(BoxLayout.Y_AXIS);
23         final private JPanel generalPanel=new JPanel(new SpringLayout());
24             final private JLabel langLbl=new JLabel(Lang.gs("language"));
25             final private JComboBox lang=new JComboBox(Lang.availableLanguageNames);
26             final private JCheckBox emoticons=new JCheckBox(Lang.gs("emoticons"));
27             final static private String JavaDoc[] DOUBLECLICK_OPTIONS={Lang.gs("default double click"),Lang.gs("compose message"),Lang.gs("chat with them")};
28             final private JLabel doubleClickLbl=new JLabel(Lang.gs("when doubleclick"));
29             final private JComboBox doubleClick=new JComboBox(DOUBLECLICK_OPTIONS);
30             final private JCheckBox warn=new JCheckBox(Lang.gs("warn nonencrypted"));
31             final private JCheckBox rememberSize=new JCheckBox(Lang.gs("remember size"));
32             final static private String JavaDoc[] CLOSE_OPTIONS={Lang.gs("hide window"),Lang.gs("quit wim")};
33             final private JLabel closeLbl=new JLabel(Lang.gs("close action"));
34             final private JComboBox close=new JComboBox(CLOSE_OPTIONS);
35             final private JCheckBox awayWhenHidden=new JCheckBox(Lang.gs("away when hide"));
36             final private JPanel idlePanel=new JPanel(new GridLayout(3,1,GAP,GAP));
37             final private TitledBorder idleBorder=new TitledBorder(Lang.gs("inactivity"));
38                 final private JLabel idleLbl1=new JLabel(Lang.gs("inactive after"));
39                 final private JSpinner idleTime=new JSpinner(new SpinnerNumberModel(1,1,60,1));
40                 final private JLabel idleLbl2=new JLabel(Lang.gs("minutes"));
41                 final private JCheckBox autoAway=new JCheckBox(Lang.gs("set to away"));
42                 final private JCheckBox clearKeyPair=new JCheckBox(Lang.gs("clear keypair"));
43             
44         final private JPanel appearancePanel=new JPanel(new GridLayout(3,1,GAP,GAP));
45             final private JPanel lafPanel=new JPanel(new GridLayout(2,1,0,0));
46             final private TitledBorder lafBorder=new TitledBorder(Lang.gs("laf"));
47                 final private ButtonGroup lafGroup=new ButtonGroup();
48                 final private JRadioButton metalRB=new JRadioButton("Metal");
49                 final private JRadioButton nativeRB=new JRadioButton(System.getProperties().getProperty("os.name"));
50             final private JPanel alignPanel=new JPanel(new SpringLayout());
51                 final private JLabel contactsAlignLbl=new JLabel(Lang.gs("show contacts on"));
52                 final private static String JavaDoc[] LEFT_RIGHT={Lang.gs("left"),Lang.gs("right")};
53                 final private JComboBox contactsAlign=new JComboBox(LEFT_RIGHT);
54                 final private JLabel roomMembersLbl=new JLabel(Lang.gs("show room members on"));
55                 final private JComboBox roomMembers=new JComboBox(LEFT_RIGHT);
56             final private JPanel coloursPanel=new JPanel(new SpringLayout());
57             final private TitledBorder coloursBorder=new TitledBorder(Lang.gs("messages"));
58                 final private JLabel textColourLbl=new JLabel(Lang.gs("text colour"));
59                 final private JButton textColour=new JButton(" ");
60                 final private JLabel backgroundLbl=new JLabel(Lang.gs("background"));
61                 final private JButton background=new JButton(" ");
62                 final private JLabel textSizeLbl=new JLabel(Lang.gs("text size"));
63                 final private JSpinner textSize=new JSpinner(new SpinnerNumberModel(1,1,12,1));
64                 final private JLabel textFontLbl=new JLabel(Lang.gs("text font"));
65                 final private JTextField textFont=new JTextField(7);
66                 
67         final private JPanel alertsPanel=new JPanel(new GridLayout(3,1,GAP,GAP*2));
68                 final private static String JavaDoc[] SOUND_OPTIONS={Lang.gs("default sound"),Lang.gs("no sound"),Lang.gs("custom sound")};
69                 final private SoundListener sl=new SoundListener();
70                 final private JPanel newMessageAlertPanel=new JPanel(new GridLayout(2,1,0,0));
71                 final private TitledBorder newMessageBorder=new TitledBorder(Lang.gs("new message"));
72                     final private JCheckBox newMessageAlert=new JCheckBox(Lang.gs("show window"));
73                     final private JPanel newMessageSoundPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,0));
74                         final private JComboBox newMessageSound=new JComboBox(SOUND_OPTIONS);
75                         final private JTextField newMessageCustomSound=new JTextField(TEXTFIELD_SIZE);
76                         final private JButton newMessageBrowseBtn=new JButton("",Icons.BROWSE);
77                 final private JPanel newChatAlertPanel=new JPanel(new GridLayout(2,1,0,0));
78                 final private TitledBorder newChatBorder=new TitledBorder(Lang.gs("new chat"));
79                     final private JCheckBox newChatAlert=new JCheckBox(Lang.gs("show window"));
80                     final private JPanel newChatSoundPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,0));
81                         final private JComboBox newChatSound=new JComboBox(SOUND_OPTIONS);
82                         final private JTextField newChatCustomSound=new JTextField(TEXTFIELD_SIZE);
83                         final private JButton newChatBrowseBtn=new JButton("",Icons.BROWSE);
84                 final private JPanel contactOnlineAlertPanel=new JPanel(new GridLayout(2,1,0,0));
85                 final private TitledBorder contactOnlineBorder=new TitledBorder(Lang.gs("contact online"));
86                     final private JCheckBox contactOnlineAlert=new JCheckBox(Lang.gs("show window"));
87                     final private JPanel contactOnlineSoundPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,0));
88                         final private JComboBox contactOnlineSound=new JComboBox(SOUND_OPTIONS);
89                         final private JTextField contactOnlineCustomSound=new JTextField(TEXTFIELD_SIZE);
90                         final private JButton contactOnlineBrowseBtn=new JButton("",Icons.BROWSE);
91                 final private JFileChooser fileChooser=new JFileChooser();
92                 final private ExampleFileFilter filter=new ExampleFileFilter();
93     
94         final private JPanel accountSettingsPanel=new JPanel(new SpringLayout());
95             final private JPanel jabberPanel=new JPanel(new GridLayout(6,1,GAP,GAP));
96             final private TitledBorder jabberPanelBorder=new TitledBorder("Jabber");
97                 final private JLabel jidLbl=new JLabel();
98                 final private JLabel resourceLbl=new JLabel(Lang.gs("jabber_resource"));
99                 final private JTextField resource=new JTextField(TEXTFIELD_SIZE);
100                 final private JCheckBox ssl=new JCheckBox(Lang.gs("jabber_ssl"));
101                 final private JLabel passwordLbl=new JLabel(Lang.gs("jabber_password"));
102                 final JPasswordField password=new JPasswordField(TEXTFIELD_SIZE);
103                 final private JCheckBox rememeberPassword=new JCheckBox(Lang.gs("remember password"));
104                 final private JPanel changePasswordBtnPanel=new JPanel(new FlowLayout(FlowLayout.RIGHT,0,0));
105                     final private JButton changePasswordBtn=new JButton(Lang.gs("change password"));
106             final private Box otherBox=new Box(BoxLayout.Y_AXIS);
107                 final private JPanel deleteAccountBtnPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,GAP));
108                     final private JButton deleteAccountBtn=new JButton(Lang.gs("delete account"));
109                 final private JPanel changePassphraseBtnPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,GAP));
110                     final private JButton changePassphraseBtn=new JButton(Lang.gs("change passphrase"));
111     
112     final private JPanel btnPanel=new JPanel(new FlowLayout(FlowLayout.RIGHT,GAP,GAP));
113         final private JButton resetBtn=new JButton(Lang.gs("reset"),Icons.RESET);
114         final private JButton saveBtn=new JButton(Lang.gs("save"),Icons.SAVE);
115         final JButton cancelBtn=new JButton(Lang.gs("cancel"),Icons.CANCEL);
116     
117     final BtnClick click=new BtnClick();
118     
119     final OptionsDialog dialog=this;
120     
121     public boolean needToSaveAccountSettings=false;
122     
123     public OptionsDialog(){
124         super(WhisperIM.MainWindow,Lang.gs("menu_preferences"),false);
125         setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
126         Container cp=getContentPane();
127         cp.setLayout(new BorderLayout(GAP,GAP));
128         
129         deleteAccountBtn.setVisible(false);//FUTURE FEATURE (maybe)
130

131         lang.setMaximumSize(lang.getPreferredSize());
132         generalPanel.add(GUI.panel(langLbl,lang,GAP));
133         emoticons.setToolTipText(Lang.gs("emoticons_tt"));
134         generalPanel.add(emoticons);
135         generalPanel.add(doubleClickLbl);
136         generalPanel.add(GUI.panel(doubleClick,new JLabel(),GAP));
137         generalPanel.add(warn);
138         rememberSize.setToolTipText(Lang.gs("remember size_tt"));
139         generalPanel.add(rememberSize);
140         generalPanel.add(GUI.panel(closeLbl,close,GAP));
141         //generalPanel.add(awayWhenHidden);
142
SpringUtilities.makeCompactGrid(generalPanel,7,1,0,0,GAP,GAP);
143         idlePanel.setBorder(idleBorder);
144         final JPanel p=new JPanel();
145         p.add(idleLbl1);
146         p.add(idleTime);
147         p.add(idleLbl2);
148         idlePanel.add(p);
149         idlePanel.add(autoAway);
150         idlePanel.add(clearKeyPair);
151         generalBox.add(generalPanel);
152         generalBox.add(idlePanel);
153         generalBox.add(generalBox.createGlue());
154         
155         lafPanel.setBorder(lafBorder);
156         lafGroup.add(metalRB);
157         lafGroup.add(nativeRB);
158         lafPanel.add(metalRB);
159         lafPanel.add(nativeRB);
160         appearancePanel.add(lafPanel);
161         alignPanel.add(GUI.panel(contactsAlignLbl,contactsAlign,GAP));
162         alignPanel.add(GUI.panel(roomMembersLbl,roomMembers,GAP));
163         SpringUtilities.makeCompactGrid(alignPanel,2,1,0,0,0,0);
164         appearancePanel.add(alignPanel);
165         coloursPanel.setBorder(coloursBorder);
166         coloursPanel.add(textColourLbl);
167         coloursPanel.add(textColour);
168         coloursPanel.add(textSizeLbl);
169         coloursPanel.add(textSize);
170         coloursPanel.add(backgroundLbl);
171         coloursPanel.add(background);
172         coloursPanel.add(textFontLbl);
173         coloursPanel.add(textFont);
174         textColour.setActionCommand("textColour");
175         background.setActionCommand("background");
176         textColour.addActionListener(click);
177         background.addActionListener(click);
178         background.setMaximumSize(background.getPreferredSize());
179         textColour.setMaximumSize(textColour.getPreferredSize());
180         textFont.setMaximumSize(textFont.getPreferredSize());
181         textSize.setMaximumSize(textSize.getPreferredSize());
182         SpringUtilities.makeCompactGrid(coloursPanel,2,4,GAP,GAP,GAP,GAP);
183         appearancePanel.add(coloursPanel);
184         
185         newMessageAlertPanel.setBorder(newMessageBorder);
186         newMessageAlertPanel.add(newMessageAlert);
187         newMessageSound.setMaximumSize(newMessageSound.getPreferredSize());
188         newMessageSound.setActionCommand("newMessage");
189         newMessageSound.addActionListener(sl);
190         newMessageCustomSound.setHorizontalAlignment(JTextField.TRAILING);
191         newMessageCustomSound.setEditable(false);
192         newMessageBrowseBtn.setEnabled(false);
193         newMessageBrowseBtn.setActionCommand("newMessageBrowse");
194         newMessageBrowseBtn.setToolTipText(Lang.gs("browse_tt"));
195         newMessageBrowseBtn.addActionListener(click);
196         newMessageBrowseBtn.setMargin(new Insets(0,0,0,0));
197         newMessageSoundPanel.add(newMessageSound);
198         newMessageSoundPanel.add(newMessageCustomSound);
199         newMessageSoundPanel.add(newMessageBrowseBtn);
200         newMessageAlertPanel.add(newMessageSoundPanel);
201         alertsPanel.add(newMessageAlertPanel);
202         
203         newChatAlertPanel.setBorder(newChatBorder);
204         newChatAlertPanel.add(newChatAlert);
205         newChatSound.setMaximumSize(newChatSound.getPreferredSize());
206         newChatSound.setActionCommand("newChat");
207         newChatSound.addActionListener(sl);
208         newChatCustomSound.setHorizontalAlignment(JTextField.TRAILING);
209         newChatCustomSound.setEditable(false);
210         newChatBrowseBtn.setEnabled(false);
211         newChatBrowseBtn.setActionCommand("newChatBrowse");
212         newChatBrowseBtn.setToolTipText(Lang.gs("browse_tt"));
213         newChatBrowseBtn.addActionListener(click);
214         newChatBrowseBtn.setMargin(new Insets(0,0,0,0));
215         newChatSoundPanel.add(newChatSound);
216         newChatSoundPanel.add(newChatCustomSound);
217         newChatSoundPanel.add(newChatBrowseBtn);
218         newChatAlertPanel.add(newChatSoundPanel);
219         alertsPanel.add(newChatAlertPanel);
220         
221         contactOnlineAlertPanel.setBorder(contactOnlineBorder);
222         contactOnlineAlertPanel.add(contactOnlineAlert);
223         contactOnlineSound.setMaximumSize(contactOnlineSound.getPreferredSize());
224         contactOnlineSound.setActionCommand("contactOnline");
225         contactOnlineSound.addActionListener(sl);
226         contactOnlineCustomSound.setHorizontalAlignment(JTextField.TRAILING);
227         contactOnlineCustomSound.setEditable(false);
228         contactOnlineBrowseBtn.setEnabled(false);
229         contactOnlineBrowseBtn.setActionCommand("contactOnlineBrowse");
230         contactOnlineBrowseBtn.setToolTipText(Lang.gs("browse_tt"));
231         contactOnlineBrowseBtn.addActionListener(click);
232         contactOnlineBrowseBtn.setMargin(new Insets(0,0,0,0));
233         contactOnlineSoundPanel.add(contactOnlineSound);
234         contactOnlineSoundPanel.add(contactOnlineCustomSound);
235         contactOnlineSoundPanel.add(contactOnlineBrowseBtn);
236         contactOnlineAlertPanel.add(contactOnlineSoundPanel);
237         alertsPanel.add(contactOnlineAlertPanel);
238         final javax.sound.sampled.AudioFileFormat.Type audioformats[]=javax.sound.sampled.AudioSystem.getAudioFileTypes();
239         for(int i=0;i<audioformats.length;i++){
240             filter.addExtension(audioformats[i].getExtension());
241         }
242         filter.setDescription(Lang.gs("sound files"));
243         fileChooser.setFileFilter(filter);
244         
245         jabberPanel.setBorder(jabberPanelBorder);
246         jabberPanel.add(jidLbl);
247         resource.setToolTipText(Lang.gs("jabber_resource_tt"));
248         final JPanel resourcePanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,0));
249         resourcePanel.add(resourceLbl);
250         resourcePanel.add(resource);
251         jabberPanel.add(resourcePanel);
252         ssl.setToolTipText(Lang.gs("jabber_ssl_tt"));
253         jabberPanel.add(ssl);
254         password.setToolTipText(Lang.gs("jabber_password_tt"));
255         final JPanel passwordPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,GAP,0));
256         passwordPanel.add(passwordLbl);
257         passwordPanel.add(password);
258         jabberPanel.add(passwordPanel);
259         rememeberPassword.setToolTipText(Lang.gs("remember password_tt"));
260         jabberPanel.add(rememeberPassword);
261         changePasswordBtn.setToolTipText(Lang.gs("change password_tt"));
262         changePasswordBtn.addActionListener(click);
263         changePasswordBtnPanel.add(changePasswordBtn);
264         jabberPanel.add(changePasswordBtnPanel);
265         accountSettingsPanel.add(jabberPanel);
266         //otherBox
267
changePassphraseBtn.setToolTipText(Lang.gs("change passphrase_tt"));
268         changePassphraseBtn.addActionListener(click);
269         changePassphraseBtnPanel.add(changePassphraseBtn);
270         otherBox.add(changePassphraseBtnPanel);
271         deleteAccountBtn.setToolTipText(Lang.gs("delete account_tt"));
272         deleteAccountBtn.addActionListener(click);
273         deleteAccountBtnPanel.add(deleteAccountBtn);
274         otherBox.add(deleteAccountBtnPanel);
275         otherBox.add(otherBox.createGlue());
276         accountSettingsPanel.add(otherBox);
277         SpringUtilities.makeCompactGrid(accountSettingsPanel,2,1,0,0,0,0);
278         
279         tabs.addTab(Lang.gs("general"),Icons.PREFERENCES,generalBox);
280         tabs.addTab(Lang.gs("appearance"),Icons.APPEARANCE,appearancePanel);
281         tabs.addTab(Lang.gs("alerts"),Icons.ALERTS,alertsPanel);
282         tabs.addTab(Lang.gs("account settings"),Icons.ACCOUNT_SETTINGS,accountSettingsPanel);
283         cp.add(tabs,BorderLayout.CENTER);
284         
285         resetBtn.addActionListener(click);
286         saveBtn.addActionListener(click);
287         cancelBtn.addActionListener(click);
288         resetBtn.setMnemonic(Lang.s2k("reset_mn"));
289         saveBtn.setMnemonic(Lang.s2k("save_mn"));
290         cancelBtn.setMnemonic(Lang.s2k("cancel_mn"));
291         resetBtn.setToolTipText(Lang.gs("reset_tt"));
292         saveBtn.setToolTipText(Lang.gs("od_save_tt"));
293         cancelBtn.setToolTipText(Lang.gs("od_cancel_tt"));
294         
295         btnPanel.add(resetBtn);
296         btnPanel.add(saveBtn);
297         btnPanel.add(cancelBtn);
298         cp.add(btnPanel,BorderLayout.SOUTH);
299         //help key
300
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(WhisperIM.HELP_KEY,0),"help"); //put in help key for action help
301
getRootPane().getActionMap().put("help",new HelpAction(this,"options.html"));
302         
303         getRootPane().setDefaultButton(saveBtn);
304         doSet(null);
305         pack();
306         // listners for idle
307
addKeyListener(new KeyAction());
308         addMouseListener(new MouseAction());
309     }
310     
311     public void show(){
312         setLocationRelativeTo(WhisperIM.MainWindow);
313         password.setEditable(true);
314         cancelBtn.setEnabled(true);
315         super.show();
316     }
317     
318     
319     /** Sets the GUI to display the preferences.
320     * Pass null to set to the current user preferences.*/

321     public void doSet(Properties JavaDoc p){
322         if(p==null){
323             p=WhisperIM.UserPref;
324         }
325         // general
326
for(int i=0; i<Lang.availableLanguageNames.length;i++){
327             if(Lang.gs("language_code").equals(Lang.availableLanguageCodes[i])){
328                 lang.setSelectedIndex(i);
329                 break;
330             }
331         }
332         emoticons.setSelected(s2b("emoticons"));
333         if(p.getProperty("double_click").equals("default")){
334             doubleClick.setSelectedIndex(0);
335         }
336         else{
337             if(p.getProperty("double_click").equals("message")){
338                 doubleClick.setSelectedIndex(1);
339             }
340             else{
341                 doubleClick.setSelectedIndex(2);
342             }
343         }
344         warn.setSelected(s2b("warn_unencrypted"));
345         rememberSize.setSelected(s2b("remember_window_size"));
346         if(p.getProperty("close_action").equals("hide")){
347             close.setSelectedIndex(0);
348         }
349         else{
350             close.setSelectedIndex(1);
351         }
352         //awayWhenHidden.setSelected(s2b("away_when_hidden"));
353
// idle time
354
try{
355             idleTime.setValue(new Integer JavaDoc(p.getProperty("idle_time")));
356         }
357         catch(Exception JavaDoc ite){
358             idleTime.setValue(new Integer JavaDoc(10));
359         }
360         autoAway.setSelected(s2b("auto_away"));
361         clearKeyPair.setSelected(s2b("clear_keypair"));
362         // appearancePanel
363
if(p.getProperty("laf").equals("native")){
364             nativeRB.setSelected(true);
365         }
366         else{
367             metalRB.setSelected(true);
368         }
369         
370         if(p.getProperty("contact_list_location").equals("left")){
371             contactsAlign.setSelectedIndex(0);
372         }
373         else{
374             contactsAlign.setSelectedIndex(1);
375         }
376         
377         if(p.getProperty("muc_list_location").equals("left")){
378             roomMembers.setSelectedIndex(0);
379         }
380         else{
381             roomMembers.setSelectedIndex(1);
382         }
383         // text colour
384
try{
385             textColour.setBackground(Color.decode(p.getProperty("text_colour")));
386         }
387         catch(Exception JavaDoc e1){
388             textColour.setBackground(Color.BLACK);
389         }
390         // background colour
391
try{
392             background.setBackground(Color.decode(p.getProperty("background_colour")));
393         }
394         catch(Exception JavaDoc e2){
395             background.setBackground(Color.WHITE);
396         }
397         // font
398
textFont.setText(p.getProperty("text_font"));
399         // text size
400
try{
401             textSize.setValue(new Integer JavaDoc(p.getProperty("text_size")));
402         }
403         catch(Exception JavaDoc e3){
404             textSize.setValue(new Integer JavaDoc(3));
405         }
406         //alertsPanel
407
newMessageAlert.setSelected(s2b("alert_new_message"));
408         if(p.getProperty("sound_alert_new_message").equals("default")){
409             newMessageSound.setSelectedIndex(0);
410             newMessageBrowseBtn.setEnabled(false);
411             newMessageCustomSound.setText("");
412             newMessageCustomSound.setEditable(false);
413         }
414         else{
415             if(p.getProperty("sound_alert_new_message").equals("none")){
416                 newMessageSound.setSelectedIndex(1);
417                 newMessageBrowseBtn.setEnabled(false);
418                 newMessageCustomSound.setText("");
419                 newMessageCustomSound.setEditable(false);
420             }
421             else{
422                 newMessageSound.setSelectedIndex(2);
423                 newMessageBrowseBtn.setEnabled(true);
424                 newMessageCustomSound.setEditable(true);
425                 newMessageCustomSound.setText(p.getProperty("sound_alert_new_message"));
426             }
427         }
428         
429         newChatAlert.setSelected(s2b("alert_new_chat"));
430         if(p.getProperty("sound_alert_new_chat").equals("default")){
431             newChatSound.setSelectedIndex(0);
432             newChatBrowseBtn.setEnabled(false);
433             newChatCustomSound.setText("");
434             newChatCustomSound.setEditable(false);
435         }
436         else{
437             if(p.getProperty("sound_alert_new_chat").equals("none")){
438                 newChatSound.setSelectedIndex(1);
439                 newChatBrowseBtn.setEnabled(false);
440                 newChatCustomSound.setText("");
441                 newChatCustomSound.setEditable(false);
442             }
443             else{
444                 newChatSound.setSelectedIndex(2);
445                 newChatBrowseBtn.setEnabled(true);
446                 newChatCustomSound.setEditable(true);
447                 newChatCustomSound.setText(p.getProperty("sound_alert_new_message"));
448             }
449         }
450         
451         contactOnlineAlert.setSelected(s2b("alert_online"));
452         if(p.getProperty("sound_alert_online").equals("default")){
453             contactOnlineSound.setSelectedIndex(0);
454             contactOnlineBrowseBtn.setEnabled(false);
455             contactOnlineCustomSound.setText("");
456             contactOnlineCustomSound.setEditable(false);
457         }
458         else{
459             if(p.getProperty("sound_alert_online").equals("none")){
460                 contactOnlineSound.setSelectedIndex(1);
461                 contactOnlineBrowseBtn.setEnabled(false);
462                 contactOnlineCustomSound.setText("");
463                 contactOnlineCustomSound.setEditable(false);
464             }
465             else{
466                 contactOnlineSound.setSelectedIndex(2);
467                 contactOnlineBrowseBtn.setEnabled(true);
468                 contactOnlineCustomSound.setEditable(true);
469                 contactOnlineCustomSound.setText(p.getProperty("sound_alert_new_message"));
470             }
471         }
472         //accountSettingsPanel
473
jidLbl.setText(WhisperIM.accountSettings.JabberUserName+"@"+WhisperIM.accountSettings.JabberServer);
474         resource.setText(WhisperIM.accountSettings.JabberResource);
475         password.setText(WhisperIM.accountSettings.JabberPassword);
476         ssl.setSelected(WhisperIM.accountSettings.JabberSSL);
477         rememeberPassword.setSelected(WhisperIM.accountSettings.JabberRememberPassword);
478     }
479     
480     private boolean s2b(String JavaDoc key){
481         if(WhisperIM.UserPref.getProperty(key).equals("true")){
482             return true;
483         }
484         return false;
485     }
486     
487     public void doCancel(){
488         dispose();
489         doSet(null);
490     }
491     
492     public void doReset(){
493         doSet(new DefaultUserPref());
494         resource.setText(WhisperIM.accountSettings.JabberResource);
495         if(!needToSaveAccountSettings){
496             password.setText(WhisperIM.accountSettings.JabberPassword);
497         }
498         ssl.setSelected(WhisperIM.accountSettings.JabberSSL);
499         rememeberPassword.setSelected(WhisperIM.accountSettings.JabberRememberPassword);
500         GUI.showInfo(this,"menu_preferences","options reset");
501     }
502     
503     public void doSave(){
504         setCursor(GUI.WAIT);
505         boolean needrecreate=false;
506         // gui to preferences
507
// generalPanel
508
if(!Lang.availableLanguageCodes[lang.getSelectedIndex()].equals(Lang.gs("language_code"))){
509             // change language
510
WhisperIM.lang=ListResourceBundle.getBundle("Lang",new java.util.Locale JavaDoc(Lang.availableLanguageCodes[lang.getSelectedIndex()]));
511             WhisperIM.MainWindow.setLang();
512             needrecreate=true;
513         }
514         WhisperIM.UserPref.setProperty("lang",Lang.availableLanguageCodes[lang.getSelectedIndex()]);
515         WhisperIM.UserPref.setProperty("emoticons",b2s(emoticons.isSelected()) );
516         int dc=doubleClick.getSelectedIndex();
517         if(dc==0){
518             WhisperIM.UserPref.setProperty("double_click","default");
519         }
520         else{
521             if(dc==1){
522                 WhisperIM.UserPref.setProperty("double_click","message");
523             }
524             else{
525                 WhisperIM.UserPref.setProperty("double_click","chat");
526             }
527         }
528         WhisperIM.UserPref.setProperty("warn_unencrypted",b2s(warn.isSelected()) );
529         WhisperIM.UserPref.setProperty("remember_window_size",b2s(rememberSize.isSelected()) );
530         if(close.getSelectedIndex()==0){
531             WhisperIM.UserPref.setProperty("close_action","hide");
532         }
533         else{
534             WhisperIM.UserPref.setProperty("close_action","quit");
535         }
536         //WhisperIM.UserPref.setProperty("away_when_hidden",b2s(awayWhenHidden.isSelected()));
537
WhisperIM.UserPref.setProperty("idle_time",( (Integer JavaDoc) idleTime.getValue()).toString());
538         WhisperIM.UserPref.setProperty("auto_away",b2s(autoAway.isSelected()));
539         WhisperIM.UserPref.setProperty("clear_keypair",b2s(clearKeyPair.isSelected()));
540         Idle.setTimeout();
541         // appearancePanel
542
boolean needchangelaf=false;
543         if(nativeRB.isSelected()){
544             if(WhisperIM.UserPref.getProperty("laf").equals("metal")){
545                 needchangelaf=true;
546             }
547             WhisperIM.UserPref.setProperty("laf","native");
548         }
549         else{
550             if(WhisperIM.UserPref.getProperty("laf").equals("native")){
551                 needchangelaf=true;
552             }
553             WhisperIM.UserPref.setProperty("laf","metal");
554         }
555         
556         if(contactsAlign.getSelectedIndex()==0){
557             if(WhisperIM.UserPref.getProperty("contact_list_location").equals("right")){
558                 WhisperIM.MainWindow.contactListOnLeft();
559             }
560             WhisperIM.UserPref.setProperty("contact_list_location","left");
561         }
562         else{
563             if(WhisperIM.UserPref.getProperty("contact_list_location").equals("left")){
564                 WhisperIM.MainWindow.contactListOnRight();
565             }
566             WhisperIM.UserPref.setProperty("contact_list_location","right");
567         }
568         
569         if(roomMembers.getSelectedIndex()==0){
570             WhisperIM.UserPref.setProperty("muc_list_location","left");
571         }
572         else{
573             WhisperIM.UserPref.setProperty("muc_list_location","right");
574         }
575         //message appearance
576
WhisperIM.UserPref.setProperty("text_colour",colour2String(textColour.getBackground()));
577         WhisperIM.UserPref.setProperty("text_font",textFont.getText().trim());
578         WhisperIM.UserPref.setProperty("text_size",( (Integer JavaDoc) textSize.getValue()).toString());
579         WhisperIM.UserPref.setProperty("background_colour",colour2String(background.getBackground()));
580         //alertsPanel
581
WhisperIM.UserPref.setProperty("alert_online",b2s(contactOnlineAlert.isSelected()));
582         WhisperIM.UserPref.setProperty("alert_new_message",b2s(newMessageAlert.isSelected()));
583         WhisperIM.UserPref.setProperty("alert_new_chat",b2s(newChatAlert.isSelected()));
584         String JavaDoc tmp="default";
585         if(newMessageSound.getSelectedIndex()==0){
586             tmp="default";
587         }
588         if(newMessageSound.getSelectedIndex()==1){
589             tmp="none";
590         }
591         if(newMessageSound.getSelectedIndex()==2){
592             tmp=newMessageCustomSound.getText();
593         }
594         WhisperIM.UserPref.setProperty("sound_alert_new_message",tmp);
595         
596         if(newChatSound.getSelectedIndex()==0){
597             tmp="default";
598         }
599         if(newChatSound.getSelectedIndex()==1){
600             tmp="none";
601         }
602         if(newChatSound.getSelectedIndex()==2){
603             tmp=newChatCustomSound.getText();
604         }
605         WhisperIM.UserPref.setProperty("sound_alert_new_chat",tmp);
606         
607         if(contactOnlineSound.getSelectedIndex()==0){
608             tmp="default";
609         }
610         if(contactOnlineSound.getSelectedIndex()==1){
611             tmp="none";
612         }
613         if(contactOnlineSound.getSelectedIndex()==2){
614             tmp=contactOnlineCustomSound.getText();
615         }
616         WhisperIM.UserPref.setProperty("sound_alert_online",tmp);
617         //now save
618
// preferences first
619
try{
620             WhisperIM.UserPref.store(new FileOutputStream(new File(WhisperIM.userDir,WhisperIM.USER_PREF_FILE_NAME),false),"Whisper preferences");
621         }
622         catch(Exception JavaDoc spe){
623             setCursor(GUI.NORMAL);
624             GUI.showError(this,"od_save_tt","cannot save",spe.getMessage());
625             return;
626         }
627         // account settings if required
628
if(!resource.getText().equals(WhisperIM.accountSettings.JabberResource)){
629             needToSaveAccountSettings=true;
630         }
631         if(ssl.isSelected()!=WhisperIM.accountSettings.JabberSSL){
632             needToSaveAccountSettings=true;
633         }
634         if(rememeberPassword.isSelected()!=WhisperIM.accountSettings.JabberRememberPassword){
635             needToSaveAccountSettings=true;
636         }
637         if(!(new String JavaDoc (password.getPassword())).equals(WhisperIM.accountSettings.JabberPassword)){
638             needToSaveAccountSettings=true;
639         }
640         if(needToSaveAccountSettings){
641             try{
642                 WhisperIM.accountSettings.JabberPassword=new String JavaDoc(password.getPassword());
643                 WhisperIM.accountSettings.JabberResource=resource.getText();
644                 WhisperIM.accountSettings.JabberRememberPassword=rememeberPassword.isSelected();
645                 WhisperIM.accountSettings.JabberSSL=ssl.isSelected();
646                 //back up first
647
BackUp.backUp(new File(WhisperIM.userDir,AccountSettings.FILENAME));
648                 try{
649                     WhisperIM.accountSettings.Save();
650                 }
651                 catch(Exception JavaDoc asse){
652                     // try to restore - fingers crossed
653
try{
654                         BackUp.restore(new File(WhisperIM.userDir,AccountSettings.FILENAME));
655                     }
656                     catch(Exception JavaDoc bue){
657                         System.err.println("Could not restore account settings");
658                         bue.printStackTrace();
659                     }
660                     throw asse;
661                 }
662                 needToSaveAccountSettings=false;
663             }
664             catch(Exception JavaDoc e){
665                 GUI.showError(this,"save",null,e.getMessage());
666             }
667         }
668         //done
669
if(needchangelaf){
670             try{//change the look and feel
671
needrecreate=true;
672                 if(WhisperIM.UserPref.getProperty("laf").equals("metal")){
673                     //UIManager.put("ClassLoader", getClass().getClassLoader());
674
UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel());
675                 }
676                 else{
677                     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
678                 }
679                 // update
680
WhisperIM.About.dispose();
681                 WhisperIM.About=new JAboutDialog();
682                 if(WhisperIM.Help_Window!=null){
683                     WhisperIM.Help_Window.dispose();
684                     WhisperIM.Help_Window=new HelpWindow();
685                 }
686                 SwingUtilities.updateComponentTreeUI(WhisperIM.MainWindow.getContentPane());
687                 SwingUtilities.updateComponentTreeUI(WhisperIM.MainWindow.menuBar);
688                 if(WhisperIM.MainWindow.discoWindow!=null){
689                     WhisperIM.MainWindow.discoWindow.dispose();
690                     WhisperIM.MainWindow.discoWindow=new DISCOWindow();
691                 }
692                 if(WhisperIM.MainWindow.myProfileWindow!=null){
693                     WhisperIM.MainWindow.myProfileWindow.dispose();
694                     SwingUtilities.updateComponentTreeUI(WhisperIM.MainWindow.myProfileWindow.getContentPane());
695                 }
696                 if(WhisperIM.MainWindow.connectionDialog!=null){
697                     WhisperIM.MainWindow.connectionDialog.dispose();
698                     WhisperIM.MainWindow.connectionDialog=new ConnectionDialog();
699                 }
700                 WhisperIM.currentLaf=WhisperIM.UserPref.getProperty("laf");
701             }
702             catch(Exception JavaDoc lafe){
703                 GUI.showError(this,"options",null,lafe.getMessage());
704                 lafe.printStackTrace();
705             }
706         }
707         setCursor(GUI.NORMAL);
708         GUI.showInfo(this,"menu_preferences","options saved");
709         dispose();
710         if(needrecreate){
711             WhisperIM.MainWindow.optionsDialog=null;
712             needrecreate=false;
713         }
714     }
715     
716     private String JavaDoc b2s(boolean b){
717         if(b){
718             return("true");
719         }
720         else{
721             return("false");
722         }
723     }
724     
725     private String JavaDoc colour2String(Color c){
726         return "#"+s2(Integer.toHexString(c.getRed()))+s2(Integer.toHexString(c.getGreen()))+s2(Integer.toHexString(c.getBlue()));
727     }
728     
729     private String JavaDoc s2(String JavaDoc number){
730         if(number.length()>1){
731             return number;
732         }
733         else{
734             return "0"+number;
735         }
736     }
737     
738     private boolean isConnected(String JavaDoc s){
739         if(!WhisperIM.MainWindow.Conn.isConnected()){
740             GUI.showWarning(this,s,"need to be connected");
741             return false;
742         }
743         return true;
744     }
745     
746     final class BtnClick implements ActionListener{
747         public void actionPerformed(ActionEvent ae){
748             //get button
749
String JavaDoc b=ae.getActionCommand();
750             // call method depending on button clicked
751
if(b.equals(cancelBtn.getText())){
752                 doCancel();
753                 return;
754             }
755             if(b.equals(resetBtn.getText())){
756                 doReset();
757                 return;
758             }
759             if(b.equals(saveBtn.getText())){
760                 doSave();
761                 return;
762             }
763             if(b.equals("newMessageBrowse")){
764                 if(fileChooser.showOpenDialog(dialog)==JFileChooser.APPROVE_OPTION){
765                     newMessageCustomSound.setText(fileChooser.getSelectedFile().getPath());
766                 }
767                 return;
768             }
769             if(b.equals("newChatBrowse")){
770                 if(fileChooser.showOpenDialog(dialog)==JFileChooser.APPROVE_OPTION){
771                     newChatCustomSound.setText(fileChooser.getSelectedFile().getPath());
772                 }
773                 return;
774             }
775             if(b.equals("contactOnlineBrowse")){
776                 if(fileChooser.showOpenDialog(dialog)==JFileChooser.APPROVE_OPTION){
777                     contactOnlineCustomSound.setText(fileChooser.getSelectedFile().getPath());
778                 }
779                 return;
780             }
781             if(b.equals(changePasswordBtn.getText())){
782                 if(!isConnected("change password")){
783                     return;
784                 }
785                 (new ChangeJabberPasswordDialog()).show();
786                 return;
787             }
788             if(b.equals(changePassphraseBtn.getText())){
789                 (new ChangePassphraseDialog()).show();
790                 return;
791             }
792             if(b.equals("textColour")){
793                 Color c=JColorChooser.showDialog(dialog,Lang.gs("text colour"),textColour.getBackground());
794                 if(c!=null){
795                     textColour.setBackground(c);
796                 }
797                 return;
798             }
799             if(b.equals("background")){
800                 Color c=JColorChooser.showDialog(dialog,Lang.gs("background"),background.getBackground());
801                 if(c!=null){
802                     background.setBackground(c);
803                 }
804                 return;
805             }
806         }
807     }
808     
809     final class SoundListener implements ActionListener{
810         public void actionPerformed(ActionEvent ae){
811             String JavaDoc a=ae.getActionCommand();
812             if(a.equals("newMessage")){
813                 if(newMessageSound.getSelectedIndex()==2){
814                     newMessageBrowseBtn.setEnabled(true);
815                     newMessageCustomSound.setEditable(true);
816                     newMessageCustomSound.requestFocus();
817                     return;
818                 }
819                 else{
820                     newMessageBrowseBtn.setEnabled(false);
821                     newMessageCustomSound.setText("");
822                     newMessageCustomSound.setEditable(false);
823                     return;
824                 }
825             }
826             if(a.equals("newChat")){
827                 if(newChatSound.getSelectedIndex()==2){
828                     newChatBrowseBtn.setEnabled(true);
829                     newChatCustomSound.setEditable(true);
830                     newChatCustomSound.requestFocus();
831                     return;
832                 }
833                 else{
834                     newChatBrowseBtn.setEnabled(false);
835                     newChatCustomSound.setText("");
836                     newChatCustomSound.setEditable(false);
837                     return;
838                 }
839             }
840             if(a.equals("contactOnline")){
841                 if(contactOnlineSound.getSelectedIndex()==2){
842                     contactOnlineBrowseBtn.setEnabled(true);
843                     contactOnlineCustomSound.setEditable(true);
844                     contactOnlineCustomSound.requestFocus();
845                     return;
846                 }
847                 else{
848                     contactOnlineBrowseBtn.setEnabled(false);
849                     contactOnlineCustomSound.setText("");
850                     contactOnlineCustomSound.setEditable(false);
851                     return;
852                 }
853             }
854             
855         }
856     }
857 }
Popular Tags