KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > zirc > gui > OptionDialog


1 package zirc.gui ;
2
3 import java.io.* ;
4 import java.util.* ;
5 import java.awt.* ;
6 import java.awt.event.* ;
7 import javax.swing.* ;
8 import javax.swing.border.* ;
9 import javax.swing.event.* ;
10 import zirc.base.* ;
11 import zirc.xml.* ;
12 import javax.swing.tree.DefaultMutableTreeNode JavaDoc ;
13
14 //zIrc, irc client.
15
// Copyright (C) 2004 CoolBytes(Stephane claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com
16
//
17
// This program is free software; you can redistribute it and/or
18
// modify it under the terms of the GNU General Public License
19
// as published by the Free Software Foundation; either version 2
20
// of the License, or (at your option) any later version.
21
//
22
// This program is distributed in the hope that it will be useful,
23
// but WITHOUT ANY WARRANTY; without even the implied warranty of
24
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
// GNU General Public License for more details.
26

27 /**
28  * <p>Title: OptionDialog</p>
29  * <p>Description: jdialog des options</p>
30  * <p>Copyright: Copyright (c) 2004</p>
31  * <p>Company: CoolBytes(Stephane Claret, Andre Aymon, Alban Zumofen) coolbytes@hotmail.com</p>
32  * @version 1.0
33  */

34
35 public class OptionDialog extends JDialog
36 {
37   private Locale language ;
38   private String JavaDoc defServText ;
39   private String JavaDoc selServText ;
40   private static ArrayList onConnectCommand = new ArrayList() ;
41   private XmlConfig xmlConf = new XmlConfig() ;
42   private OptionTree oTree ;
43   private String JavaDoc selectedNode ;
44   private MainFrame fenetre ;
45   private IRCconnexion ircConnexion ;
46   private String JavaDoc[][] list ;
47   private ArrayList al ;
48   private String JavaDoc selectedName, selectedDescription, selectedServer, defaultServer,
49       selectedServerPort, user_nick, user_email, user_name, user_QuitMSG, user_PartMSG ;
50   private DefaultListModel lm ;
51   private final File serverList = new File("fichiers/servers.ini") ;
52   private JSplitPane jSplitPane1 = new JSplitPane() ;
53   private JPanel jPanel1 = new JPanel() ;
54   private JPanel userOptionPanel = new JPanel() ;
55   private BorderLayout borderLayout1 = new BorderLayout() ;
56   private JPanel jPanel2 = new JPanel() ;
57   private JButton jbOptionDialogOk = new JButton() ;
58   private JButton jbOptionDialogCancel = new JButton() ;
59   private GridLayout gridLayout2 = new GridLayout() ;
60   private JPanel jPanel3 = new JPanel() ;
61   private JPanel jPanel4 = new JPanel() ;
62   private JPanel jPanel5 = new JPanel() ;
63   private JPanel jPanel6 = new JPanel() ;
64   private JPanel jPanel7 = new JPanel() ;
65   private JPanel jPanel8 = new JPanel() ;
66   private JPanel jPanel9 = new JPanel() ;
67   private JPanel jPanel10 = new JPanel() ;
68   private JTextField jtName = new JTextField() ;
69   private JTextField jtEmail = new JTextField() ;
70   private JTextField jtNick = new JTextField() ;
71   private JTextField jtReserve = new JTextField() ;
72   private JLabel jLabel1 = new JLabel() ;
73   private JLabel jLabel2 = new JLabel() ;
74   private JLabel jLabel3 = new JLabel() ;
75   private JLabel jLabel4 = new JLabel() ;
76   private JPanel serverOptionPanel = new JPanel() ;
77   private JList jlServer = new JList() ;
78   private JScrollPane jScrollPane1 = new JScrollPane() ;
79   private JButton jbOptionDialogEdit = new JButton() ;
80   private BorderLayout borderLayout2 = new BorderLayout() ;
81   JButton jbOptionDialogDefault = new JButton() ;
82   JTextArea jtServerInfos = new JTextArea() ;
83   FlowLayout flowLayout2 = new FlowLayout() ;
84   ServerEditDialog eDialog ;
85   private JPanel onConnectPanel = new JPanel() ;
86   private BorderLayout borderLayout3 = new BorderLayout() ;
87   private JPanel jPanel11 = new JPanel() ;
88   private JPanel jPanel12 = new JPanel() ;
89   private JScrollPane jScrollPane2 = new JScrollPane() ;
90   private BorderLayout borderLayout4 = new BorderLayout() ;
91   private JTextArea jtaOnConnect = new JTextArea() ;
92   private JTextArea jTextArea2 = new JTextArea() ;
93   private BorderLayout borderLayout5 = new BorderLayout() ;
94   private BorderLayout borderLayout6 = new BorderLayout() ;
95   private JPanel soundOptionPanel = new JPanel() ;
96   private JRadioButton jrSounds = new JRadioButton() ;
97   JPanel msgOptionPanel = new JPanel() ;
98   JTextField jtQuitMSG = new JTextField() ;
99   JLabel jLabel6 = new JLabel() ;
100   private Border border1 ;
101
102   public OptionDialog(Frame owner, IRCconnexion ircConnexion, MainFrame _fenetre, Locale _language)
103   {
104     super(owner) ;
105     this.ircConnexion = ircConnexion ;
106     language = _language ;
107     setLanguage(language) ;
108     eDialog = new ServerEditDialog(this, language) ;
109     this.fenetre = _fenetre ;
110     try
111     {
112       jbInit() ;
113     }
114     catch (Exception JavaDoc e)
115     {
116       e.printStackTrace() ;
117     }
118   }
119
120   private void jbInit() throws Exception JavaDoc
121   {
122     jtaOnConnect.setBorder(null) ;
123     oTree = new OptionTree(xmlConf) ;
124     border1 = BorderFactory.createLineBorder(Color.gray) ;
125     this.setSize(new Dimension(517, 362)) ;
126     this.addWindowFocusListener(new java.awt.event.WindowFocusListener JavaDoc()
127     {
128       public void windowGainedFocus(WindowEvent e)
129       {
130       }
131
132       public void windowLostFocus(WindowEvent e)
133       {
134
135       }
136     }) ;
137     this.addWindowFocusListener(new java.awt.event.WindowFocusListener JavaDoc()
138     {
139       public void windowGainedFocus(WindowEvent e)
140       {
141         this_windowGainedFocus(e) ;
142       }
143
144       public void windowLostFocus(WindowEvent e)
145       {
146       }
147     }) ;
148     this.getContentPane().setLayout(borderLayout1) ;
149     this.setModal(true) ;
150     this.setResizable(false) ;
151     this.setTitle("Options") ;
152     jSplitPane1.setOrientation(JSplitPane.HORIZONTAL_SPLIT) ;
153     jSplitPane1.setBorder(null) ;
154     jSplitPane1.setMaximumSize(new Dimension(250, 2147483647)) ;
155     jSplitPane1.setPreferredSize(new Dimension(78, 18)) ;
156     jSplitPane1.setToolTipText("") ;
157     jSplitPane1.setDividerSize(6) ;
158     jSplitPane1.setTopComponent(null) ;
159     oTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener JavaDoc()
160     {
161       public void valueChanged(TreeSelectionEvent e)
162       {
163         oTree_valueChanged(e) ;
164       }
165     }) ;
166     userOptionPanel.setLayout(gridLayout2) ;
167     jPanel2.setBorder(border1) ;
168     jPanel2.setPreferredSize(new Dimension(120, 40)) ;
169     jPanel2.setLayout(null) ;
170     jbOptionDialogOk.setBounds(new Rectangle(161, 6, 30, 25)) ;
171     jbOptionDialogOk.setBorder(border1) ;
172     jbOptionDialogOk.setActionCommand("Ok") ;
173     jbOptionDialogOk.setBorderPainted(true) ;
174     jbOptionDialogOk.setText("Ok") ;
175     jbOptionDialogOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
176     {
177       public void actionPerformed(ActionEvent e)
178       {
179         jbOptionDialogOk_actionPerformed(e) ;
180       }
181     }) ;
182     jbOptionDialogCancel.setBounds(new Rectangle(295, 6, 59, 25)) ;
183     jbOptionDialogCancel.setBorder(border1) ;
184     jbOptionDialogCancel.setActionCommand("Annuler") ;
185     jbOptionDialogCancel.setText("Annuler") ;
186     jbOptionDialogCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
187     {
188       public void actionPerformed(ActionEvent e)
189       {
190         jbOptionDialogCancel_actionPerformed(e) ;
191       }
192     }) ;
193     gridLayout2.setColumns(2) ;
194     gridLayout2.setRows(4) ;
195     jtName.setBorder(border1) ;
196     jtName.setPreferredSize(new Dimension(120, 21)) ;
197     jtName.setText("") ;
198     jtName.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
199     {
200       public void keyReleased(KeyEvent e)
201       {
202         jtName_keyReleased(e) ;
203       }
204     }) ;
205     jtEmail.setText("") ;
206     jtEmail.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
207     {
208       public void keyReleased(KeyEvent e)
209       {
210         jtEmail_keyReleased(e) ;
211       }
212     }) ;
213     jtEmail.setBorder(border1) ;
214     jtEmail.setPreferredSize(new Dimension(120, 21)) ;
215     jtNick.setText("") ;
216     jtNick.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
217     {
218       public void keyReleased(KeyEvent e)
219       {
220         jtNick_keyReleased(e) ;
221       }
222     }) ;
223     jtNick.setBorder(border1) ;
224     jtNick.setPreferredSize(new Dimension(120, 21)) ;
225     jtReserve.setText("") ;
226     jtReserve.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
227     {
228       public void keyReleased(KeyEvent e)
229       {
230         jtReserve_keyReleased(e) ;
231       }
232     }) ;
233     jtReserve.setBorder(border1) ;
234     jtReserve.setPreferredSize(new Dimension(120, 21)) ;
235     jLabel1.setText("Nom:") ;
236     jLabel2.setText("Email:") ;
237     jLabel3.setText("Nick:") ;
238     jLabel4.setText("user reserve") ;
239     serverOptionPanel.setLayout(borderLayout2) ;
240     jPanel1.setLayout(borderLayout6) ;
241     jbOptionDialogEdit.setBorder(border1) ;
242     jbOptionDialogEdit.setText("Editer") ;
243     jbOptionDialogEdit.addActionListener(new java.awt.event.ActionListener JavaDoc()
244     {
245       public void actionPerformed(ActionEvent e)
246       {
247         jbOptionDialogEdit_actionPerformed(e) ;
248       }
249     }) ;
250     jbOptionDialogDefault.setBounds(new Rectangle(196, 6, 95, 25)) ;
251     jbOptionDialogDefault.setBorder(border1) ;
252     jbOptionDialogDefault.setText("Sauver par defaut") ;
253     jbOptionDialogDefault.addActionListener(new java.awt.event.ActionListener JavaDoc()
254     {
255       public void actionPerformed(ActionEvent e)
256       {
257         jbOptionDialogDefault_actionPerformed(e) ;
258       }
259     }) ;
260     jtServerInfos.setFont(new java.awt.Font JavaDoc("SansSerif", 0, 12)) ;
261     jtServerInfos.setBorder(null) ;
262     jtServerInfos.setPreferredSize(new Dimension(250, 34)) ;
263     jtServerInfos.setEditable(false) ;
264     onConnectPanel.setLayout(borderLayout3) ;
265     jPanel12.setLayout(borderLayout4) ;
266     jTextArea2.setBackground(Color.lightGray) ;
267     jTextArea2.setFont(new java.awt.Font JavaDoc("SansSerif", 0, 12)) ;
268     jTextArea2.setPreferredSize(new Dimension(70, 100)) ;
269     jTextArea2.setEditable(false) ;
270     jTextArea2.setText(
271         "Exemple:\nlist >10 \r\njoin #prog") ;
272     jTextArea2.setLineWrap(true) ;
273     jTextArea2.setWrapStyleWord(true) ;
274     jPanel11.setLayout(borderLayout5) ;
275     jScrollPane1.setBorder(null) ;
276     jScrollPane1.setPreferredSize(new Dimension(276, 220)) ;
277     jtaOnConnect.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
278     {
279       public void keyReleased(KeyEvent e)
280       {
281         jtaOnConnect_keyReleased(e) ;
282       }
283     }) ;
284     jrSounds.setText("Activer les sons") ;
285
286     jtQuitMSG.setText("jtQuitMSG") ;
287     jtQuitMSG.setBounds(new Rectangle(169, 84, 117, 24)) ;
288     jtQuitMSG.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
289     {
290       public void keyReleased(KeyEvent e)
291       {
292         jtQuitMSG_keyReleased(e) ;
293       }
294     }) ;
295     msgOptionPanel.setLayout(null) ;
296     jLabel6.setBounds(new Rectangle(64, 86, 82, 19)) ;
297     jLabel6.setText("QUIT message") ;
298     jLabel6.setHorizontalTextPosition(SwingConstants.CENTER) ;
299     jLabel6.setHorizontalAlignment(SwingConstants.LEFT) ;
300     jPanel11.setBorder(null) ;
301     jScrollPane2.setBorder(border1) ;
302     oTree.setBorder(border1) ;
303     oTree.setPreferredSize(new Dimension(90, 18));
304     this.getContentPane().add(jSplitPane1, BorderLayout.CENTER) ;
305     this.getContentPane().add(jPanel2, BorderLayout.SOUTH) ;
306     jPanel2.add(jbOptionDialogOk, null) ;
307     jPanel2.add(jbOptionDialogDefault, null) ;
308     jPanel2.add(jbOptionDialogCancel, null) ;
309     userOptionPanel.add(jPanel3, null) ;
310     userOptionPanel.add(jPanel10, null) ;
311     jPanel10.add(jtName, null) ;
312     userOptionPanel.add(jPanel9, null) ;
313     userOptionPanel.add(jPanel8, null) ;
314     userOptionPanel.add(jPanel7, null) ;
315     userOptionPanel.add(jPanel4, null) ;
316     userOptionPanel.add(jPanel5, null) ;
317     userOptionPanel.add(jPanel6, null) ;
318     jPanel8.add(jtEmail, null) ;
319     jPanel4.add(jtNick, null) ;
320     jPanel6.add(jtReserve, null) ;
321     jPanel3.add(jLabel1, null) ;
322     jPanel9.add(jLabel2, null) ;
323     jPanel7.add(jLabel3, null) ;
324     jPanel5.add(jLabel4, null) ;
325     serverOptionPanel.add(jScrollPane1, BorderLayout.NORTH) ;
326     serverOptionPanel.add(jbOptionDialogEdit, BorderLayout.CENTER) ;
327     serverOptionPanel.add(jtServerInfos, BorderLayout.SOUTH) ;
328     jScrollPane1.getViewport().add(jlServer, null) ;
329     onConnectPanel.add(jPanel11, BorderLayout.NORTH) ;
330     jPanel11.add(jTextArea2, BorderLayout.CENTER) ;
331     onConnectPanel.add(jPanel12, BorderLayout.CENTER) ;
332     jPanel12.add(jScrollPane2, BorderLayout.CENTER) ;
333     jScrollPane2.getViewport().add(jtaOnConnect, null) ;
334     soundOptionPanel.add(jrSounds, null) ;
335     msgOptionPanel.add(jLabel6, null) ;
336     msgOptionPanel.add(jtQuitMSG, null) ;
337     jSplitPane1.setDividerLocation(140) ;
338     jSplitPane1.setRightComponent(jPanel1) ;
339     jSplitPane1.setLeftComponent(oTree) ;
340     jtServerInfos.setRows(2) ;
341     loadConfig() ;
342   }
343
344   private void loadConfig()
345   {
346     //vide l'array des commandes on connect
347
clearOnConnectCommand() ;
348     jtaOnConnect.setText("") ;
349
350     //
351
//on charge a partir du fichier config.xml
352
//
353

354     user_name = xmlConf.getUserName() ;
355     jtName.setText(user_name) ;
356     this.user_nick = xmlConf.getUserNick() ;
357     if (user_nick.length() == 0)
358     {
359       user_nick = "" ;
360     }
361     jtNick.setText(user_nick) ;
362     this.user_email = xmlConf.getUserEmail() ;
363     jtEmail.setText(user_email) ;
364     this.defaultServer = xmlConf.getServer() ;
365     jtServerInfos.setText(defServText + defaultServer) ;
366     this.selectedServerPort = xmlConf.getPorts() ;
367     this.onConnectCommand = xmlConf.getOnConnectActions() ;
368     jtaOnConnect.setText(this.onConnectCommand.get(0).toString()) ;
369     this.user_PartMSG = xmlConf.getUserPartMSG() ;
370     this.user_QuitMSG = xmlConf.getUserQuitMSG() ;
371     jtQuitMSG.setText(user_QuitMSG) ;
372     if (xmlConf.getSonIsEnabled().equals("vrai"))
373     {
374       jrSounds.setSelected(true) ;
375     }
376     else
377     {
378       jrSounds.setSelected(false) ;
379     }
380
381     //
382
//on charge la liste des serveurs, encore en .ini pour le moment
383
//
384
al = new ArrayList() ;
385     BufferedReader in2 = null ;
386     String JavaDoc line ;
387
388     try
389     {
390       in2 = new BufferedReader(new FileReader(serverList)) ;
391       //on remplit l'arraylist
392
while ((line = in2.readLine()) != null)
393       {
394         al.add(line) ;
395       }
396
397       //on repmlit le tableau avec l'arraylist
398
list = new String JavaDoc[al.size()][4] ;
399       for (int i = 0 ; i < list.length ; i++)
400       {
401         StringTokenizer str = new StringTokenizer(al.get(i).toString(), ":") ;
402         for (int j = 0 ; j < list[0].length ; j++)
403         {
404           list[i][j] = str.nextElement().toString() ;
405         }
406       }
407     }
408     catch (FileNotFoundException ex)
409     {
410       ex.printStackTrace() ;
411     }
412     catch (IOException ex1)
413     {
414       ex1.printStackTrace() ;
415     }
416     finally
417     {
418       try
419       {
420         in2.close() ;
421       }
422       catch (IOException ex1)
423       {
424         ex1.printStackTrace() ;
425       }
426     }
427
428     lm = new DefaultListModel() ;
429     //on remplit la liste
430
for (int i = 0 ; i < list.length ; i++)
431     {
432       lm.addElement(list[i][0] + " " + list[i][1]) ;
433     }
434     jlServer.setBorder(null) ;
435     jlServer.setModel(lm) ;
436     jlServer.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) ;
437     jlServer.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc()
438     {
439       public void valueChanged(ListSelectionEvent e)
440       {
441         jlServer_valueChanged(e) ;
442       }
443     }) ;
444   }
445
446   void jbOptionDialogCancel_actionPerformed(ActionEvent e)
447   {
448     this.dispose() ;
449   }
450
451   void jbOptionDialogOk_actionPerformed(ActionEvent e)
452   {
453     this.dispose() ;
454   }
455
456   //lorsque l'on veut editer la liste des serveurs, on ouvre une nouvelle fenetre
457
void jbOptionDialogEdit_actionPerformed(ActionEvent e)
458   {
459     eDialog.setLocation((int)this.getBounds().getX() + 40, (int)this.getBounds().getY() + 40) ;
460     eDialog.loadList() ;
461     eDialog.show() ;
462   }
463
464   //au focus gained on reload la liste des serveurs
465
void this_windowGainedFocus(WindowEvent e)
466   {
467     loadConfig() ;
468   }
469
470   void jbOptionDialogDefault_actionPerformed(ActionEvent e)
471   {
472
473     try
474     {
475       defaultServer = list[jlServer.getSelectedIndex()][2] ; //jlServer.getSelectedValue().toString() ;
476
}
477     catch (NullPointerException JavaDoc ex)
478     {}
479     catch (ArrayIndexOutOfBoundsException JavaDoc ex)
480     {}
481     jtServerInfos.setText(defServText + defaultServer) ;
482
483     //
484
//on prepare pour sauver dans le xml
485
//
486
if (user_name.length() == 0)
487     {
488       user_name = MessageBox.show(this, "Erreur", "Saisir un nom non nul!") ;
489     }
490     xmlConf.setUserName(this.user_name) ;
491
492     if (user_email.length() == 0)
493     {
494       user_email = MessageBox.show(this, "Erreur", "Saisir un email non nul!") ;
495     }
496     xmlConf.setUserEmail(this.user_email) ;
497
498     if (user_nick.length() == 0)
499     {
500       user_nick = MessageBox.show(this, "Erreur", "Saisir un nick non nul!") ;
501     }
502     xmlConf.setUserNick(this.user_nick) ;
503
504     if (user_PartMSG.length() == 0)
505     {
506       user_PartMSG = MessageBox.show(this, "Erreur", "Saisir un partMessage non nul!") ;
507     }
508     xmlConf.setUserPartMSG(user_PartMSG) ;
509
510     if (user_QuitMSG.length() == 0)
511     {
512       user_QuitMSG = MessageBox.show(this, "Erreur", "Saisir un quitMessage non nul!") ;
513     }
514     xmlConf.setUserQuitMSG(jtQuitMSG.getText()) ;
515
516     xmlConf.setPorts(this.selectedServerPort) ;
517     xmlConf.setServer(this.defaultServer) ;
518
519     if (jrSounds.isSelected())
520     {
521       xmlConf.setSonsActives("vrai") ;
522     }
523     else
524     {
525       xmlConf.setSonsActives("faux") ;
526     }
527     xmlConf.setOnConnectActions(jtaOnConnect.getText()) ;
528     //on sauve
529
xmlConf.saveXmlConfig() ;
530   }
531
532   //affecte les variables serveur en fontion du choix de la liste
533
void jlServer_valueChanged(ListSelectionEvent e)
534   {
535     if (!e.getValueIsAdjusting())
536     {
537       try
538       {
539         selectedName = list[jlServer.getSelectedIndex()][0] ;
540         selectedDescription = list[jlServer.getSelectedIndex()][1] ;
541         selectedServer = list[jlServer.getSelectedIndex()][2] ;
542         selectedServerPort = list[jlServer.getSelectedIndex()][3] ;
543       }
544       catch (ArrayIndexOutOfBoundsException JavaDoc ex)
545       {}
546     }
547
548     jtServerInfos.setText(defServText + defaultServer + "\n" + selServText +
549                           selectedServer) ;
550   }
551
552   //vide l'array des commande on connect
553
private static void clearOnConnectCommand()
554   {
555     onConnectCommand.clear() ;
556   }
557
558   /**
559    * Retourne un boolean qui indique si l'option son est active.
560    *
561    * @return boolean
562    */

563   public boolean isSoundEnabled()
564   {
565     return jrSounds.isSelected() ;
566   }
567
568 //getter
569
public static ArrayList getOnConnectCommand()
570   {
571     return onConnectCommand ;
572   }
573
574   public String JavaDoc getUser_server()
575   {
576     String JavaDoc server = selectedServer ;
577     try
578     {
579       if (!selectedServer.equals(""))
580       {
581         return selectedServer ;
582       }
583     }
584     catch (NullPointerException JavaDoc ex)
585     {
586       server = defaultServer ;
587     }
588     finally
589     {
590       return server ;
591     }
592   }
593
594   public String JavaDoc getUser_port()
595   {
596     return selectedServerPort ;
597   }
598
599   public String JavaDoc getUser_name()
600   {
601     return jtName.getText() ;
602   }
603
604   public String JavaDoc getUser_email()
605   {
606     return jtEmail.getText() ;
607   }
608
609   public String JavaDoc getUser_nick()
610   {
611     return jtNick.getText() ;
612   }
613
614   public String JavaDoc getUserPartMSG()
615   {
616     return this.user_PartMSG ;
617   }
618
619   public String JavaDoc getUserQuitMSG()
620   {
621     return this.user_QuitMSG ;
622   }
623
624 //setter
625

626   public static void setOnConnectCommand(String JavaDoc line)
627   {
628     onConnectCommand.add(line) ;
629   }
630
631   public void setUser_server(String JavaDoc _userServer)
632   {
633     selectedServer = _userServer ;
634     jtServerInfos.setText(defServText + selectedServer) ;
635   }
636
637   public void setUser_port(String JavaDoc _userPort)
638   {
639     selectedServerPort = _userPort ;
640   }
641
642   public void setUser_name(String JavaDoc _userName)
643   {
644     user_name = _userName ;
645   }
646
647   public void setUser_email(String JavaDoc _userEmail)
648   {
649     user_email = _userEmail ;
650   }
651
652   public void setUser_nick(String JavaDoc _userNick)
653   {
654     user_nick = _userNick ;
655   }
656
657   //definit le look and feel
658
public void setLAF(String JavaDoc laf) throws UnsupportedLookAndFeelException, IllegalAccessException JavaDoc, InstantiationException JavaDoc,
659       ClassNotFoundException JavaDoc, NullPointerException JavaDoc
660   {
661     UIManager.setLookAndFeel(laf) ;
662
663     eDialog.setLAF(laf) ;
664
665     SwingUtilities.updateComponentTreeUI(this) ;
666     SwingUtilities.updateComponentTreeUI(userOptionPanel) ;
667     SwingUtilities.updateComponentTreeUI(serverOptionPanel) ;
668     SwingUtilities.updateComponentTreeUI(onConnectPanel) ;
669     SwingUtilities.updateComponentTreeUI(soundOptionPanel) ;
670   }
671
672 //on surveille le changement d'option pour afficher le panel correct
673
void oTree_valueChanged(TreeSelectionEvent e)
674   {
675     ResourceBundle messages = ResourceBundle.getBundle("OptionDialog", language) ;
676     selectedNode = oTree.getLastSelectedPathComponent().toString() ;
677
678     if (selectedNode.equals(messages.getString("nodeutilisateur")))
679     {
680       invalidate() ;
681       jPanel1.removeAll() ;
682       jPanel1.add(userOptionPanel) ;
683       validate() ;
684       repaint() ;
685     }
686
687     if (selectedNode.equals(messages.getString("nodeserveurs")))
688     {
689       invalidate() ;
690       jPanel1.removeAll() ;
691       jPanel1.add(serverOptionPanel) ;
692       validate() ;
693       repaint() ;
694     }
695
696     if (selectedNode.equals(messages.getString("nodeaction")))
697     {
698       invalidate() ;
699       jPanel1.removeAll() ;
700       jPanel1.add(onConnectPanel) ;
701       validate() ;
702       repaint() ;
703     }
704     if (selectedNode.equals(messages.getString("nodesons")))
705     {
706       invalidate() ;
707       jPanel1.removeAll() ;
708       jPanel1.add(soundOptionPanel) ;
709       validate() ;
710       repaint() ;
711     }
712
713     if (selectedNode.equals(messages.getString("nodemessages")))
714     {
715       invalidate() ;
716       jPanel1.removeAll() ;
717       jPanel1.add(msgOptionPanel) ;
718       validate() ;
719       repaint() ;
720     }
721
722   }
723
724   void jtName_keyReleased(KeyEvent e)
725   {
726     user_name = jtName.getText() ;
727   }
728
729   void jtEmail_keyReleased(KeyEvent e)
730   {
731     user_email = jtEmail.getText() ;
732   }
733
734   void jtNick_keyReleased(KeyEvent e)
735   {
736     user_nick = jtNick.getText() ;
737   }
738
739   void jtReserve_keyReleased(KeyEvent e)
740   {
741
742   }
743
744   void jtaOnConnect_keyReleased(KeyEvent e)
745   {
746     onConnectCommand.clear() ;
747     setOnConnectCommand(jtaOnConnect.getText()) ;
748   }
749
750   void jtQuitMSG_keyReleased(KeyEvent e)
751   {
752     user_QuitMSG = jtQuitMSG.getText() ;
753   }
754
755   public void setLanguage(Locale lang)
756   {
757     try
758     {
759       language = lang ;
760       ResourceBundle messages = ResourceBundle.getBundle("OptionDialog", lang) ;
761       jLabel1.setText(messages.getString("nom")) ;
762       jbOptionDialogCancel.setText(messages.getString("btannuler")) ;
763       jbOptionDialogEdit.setText(messages.getString("btedit")) ;
764       jbOptionDialogDefault.setText(messages.getString("btdefaut")) ;
765       jrSounds.setText(messages.getString("sons")) ;
766       selServText = messages.getString("selserveur") ;
767       defServText = messages.getString("defserveur") ;
768
769       //le optionTree
770
DefaultMutableTreeNode JavaDoc o = (DefaultMutableTreeNode JavaDoc)oTree.getModel().getChild(oTree.getModel().getRoot(), 0) ;
771       o.setUserObject(messages.getString("nodeutilisateur")) ;
772       o = (DefaultMutableTreeNode JavaDoc)oTree.getModel().getChild(oTree.getModel().getRoot(), 1) ;
773       o.setUserObject(messages.getString("nodeserveurs")) ;
774       o = (DefaultMutableTreeNode JavaDoc)oTree.getModel().getChild(oTree.getModel().getRoot(), 2) ;
775       o.setUserObject(messages.getString("nodeaction")) ;
776       o = (DefaultMutableTreeNode JavaDoc)oTree.getModel().getChild(oTree.getModel().getRoot(), 3) ;
777       o.setUserObject(messages.getString("nodesons")) ;
778       o = (DefaultMutableTreeNode JavaDoc)oTree.getModel().getChild(oTree.getModel().getRoot(), 4) ;
779       o.setUserObject(messages.getString("nodemessages")) ;
780
781       //la dialog des serveurs
782
eDialog.setLanguage(lang) ;
783     }
784     catch (NullPointerException JavaDoc ex)
785     {}
786
787   }
788
789 }
790
Popular Tags