KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > directory > jxplorer > AdvancedOptions


1 package com.ca.directory.jxplorer;
2
3 import com.ca.commons.cbutil.*;
4 import com.ca.directory.jxplorer.search.SearchGUI;
5 import com.ca.directory.jxplorer.tree.SmartTree;
6
7 import javax.swing.*;
8 import java.awt.*;
9 import java.awt.event.ActionEvent JavaDoc;
10 import java.awt.event.ActionListener JavaDoc;
11 import java.util.logging.Level JavaDoc;
12 import java.util.logging.Logger JavaDoc;
13
14 /**
15  * Sets up an advanced options dialog box that is accessable through the Options drop down menu.
16  * It has five tabbed panes: the first is for the look and feel, the second is for log levels,
17  * the third is for the log method, the fourth is for LDAP limit & timeout and the last is for the URL handling.
18  * When the user clicks the 'Apply' button all of the changes are saved in the property file and reflected in JX.
19  *
20  * @author Trudi.
21  */

22 public class AdvancedOptions extends JDialog
23 {
24     private CBButton btnApply, btnReset, btnCancel, btnHelp;
25     private JTextField ldapLimit, ldapTimeout;
26     private JComboBox urlCombo, logLevelCombo, logMethodCombo, cachePwdCombo;
27     private CBPanel display;
28     private JTabbedPane tabbedPane;
29     private JRadioButton[] lookAndFeel;
30     private String JavaDoc[] lookAndFeelVal;
31
32 // private final String[] logLevelVal = new String[]{CBIntText.get("Errors Only"), CBIntText.get("Basic"), CBIntText.get("Tree Operations"), CBIntText.get("Extensive"), CBIntText.get("All"), CBIntText.get("All + BER Trace")};
33
private final String JavaDoc[] logLevelVal = new String JavaDoc[]{CBIntText.get("Severe"), CBIntText.get("Warning"), CBIntText.get("Info"), CBIntText.get("Fine"), CBIntText.get("Finest"), CBIntText.get("All + BER Trace")};
34
35     // XXX WARNING - functionality is keyed on the order of elements in the following string array
36
private final String JavaDoc[] logMethodVal = new String JavaDoc[]{CBIntText.get("None"), CBIntText.get("Console"), CBIntText.get("File"), CBIntText.get("Console & File")};
37
38     private MainMenu mainMenu;
39     private final JXplorer jx;
40     private String JavaDoc dirImage;
41
42     // Utility constants for look and feel stuff..
43
private static final int WINDOWS = 0;
44     private static final int JAVA = 1;
45     protected static final int MOTIF = 2;
46     protected static final int MAC = 3;
47
48     private static Logger JavaDoc log = Logger.getLogger(AdvancedOptions.class.getName());
49
50     // Look and feels...
51
public static final String JavaDoc WINDOWS_LF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
52     public static final String JavaDoc JAVA_LF = "javax.swing.plaf.metal.MetalLookAndFeel";
53     public static final String JavaDoc MOTIF_LF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
54     public static final String JavaDoc MAC_LF = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
55
56     /**
57      * Sets up the panel, adds the tabbed pane and the buttons to it.
58      *
59      * @param jxplorer a JXplorer object to update changes with the log level, log method & LDAP values.
60      * @param mainMenu a MainMenu object to update the gui when the L&F is changed.
61      */

62     public AdvancedOptions(JXplorer jxplorer, MainMenu mainMenu)
63     {
64         super(jxplorer);
65         setModal(true);
66
67         this.mainMenu = mainMenu;
68         jx = jxplorer;
69
70         dirImage = JXplorer.getProperty("dir.images");
71
72         setTitle(CBIntText.get("JXplorer Advanced Options"));
73
74         display = new CBPanel();
75
76         btnApply = new CBButton(CBIntText.get("Apply"), CBIntText.get("Click here to apply the changes"));
77         btnApply.addActionListener(new ActionListener JavaDoc()
78         {
79             public void actionPerformed(ActionEvent JavaDoc e)
80             {
81                 apply();
82             }
83         });
84
85         btnReset = new CBButton(CBIntText.get("Reset"),
86                 CBIntText.get("Click here to reset the options"));
87         btnReset.addActionListener(new ActionListener JavaDoc()
88         {
89             public void actionPerformed(ActionEvent JavaDoc e)
90             {
91                 reset();
92             }
93         });
94
95         btnCancel = new CBButton(CBIntText.get("Cancel"),
96                 CBIntText.get("Click here to exit Advanced Options"));
97         btnCancel.addActionListener(new ActionListener JavaDoc()
98         {
99             public void actionPerformed(ActionEvent JavaDoc e)
100             {
101                 quit();
102             }
103         });
104
105         // Creates a new help button with a listener that will open JX help at appropriate location...
106
btnHelp = new CBButton(CBIntText.get("Help"), CBIntText.get("Click here for help"));
107         CBHelpSystem.useDefaultHelp(btnHelp, HelpIDs.CONFIG_ADVANCED);
108
109         //TE: better way to implement keystroke listening...
110
display.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ENTER"), "enter");
111         display.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "escape");
112         display.getActionMap().put("enter", new MyAction(CBAction.ENTER));
113         display.getActionMap().put("escape", new MyAction(CBAction.ESCAPE));
114
115         tabbedPane = new JTabbedPane();
116
117         //Set up the L&F tab...
118
lookAndFeelTab();
119
120         // Set up the ldap levels tab...
121
ldapLevels();
122
123         // Set up the log level tab...
124
logLevel();
125
126         // Set up the log method tab...
127
logMethod();
128
129         // Set up the URL tab..
130
urlTab();
131         // Set up the password options tab...
132
pwdTab();
133
134         JPanel buttonPanel = new JPanel();
135
136         buttonPanel.add(btnApply);
137         buttonPanel.add(btnReset);
138         buttonPanel.add(btnCancel);
139         buttonPanel.add(btnHelp);
140         display.addln(tabbedPane);
141         display.addln(buttonPanel);
142
143         setSize(300, 280);
144
145         getContentPane().add(display);
146     }
147
148     /**
149      * Apparently it is better to use key bindings rather than adding a KeyListener...
150      * "for reacting in a special way to particular keys, you usually should use key
151      * bindings instead of a key listener".
152      * This class lets the user set the key as an int. If a key is pressed and it
153      * matches the assigned int, a check is done for if it is an escape or enter key.
154      * (27 or 10). If escape, the quit method is called. If enter, the apply
155      * method is called.
156      * Bug 4646.
157      *
158      * @author Trudi.
159      */

160     private class MyAction extends CBAction
161     {
162         /**
163          * Calls super constructor.
164          *
165          * @param key
166          */

167         public MyAction(int key)
168         {
169             super(key);
170         }
171
172         /**
173          * quit is called if the Esc key pressed,
174          * apply is called if Enter key is pressed.
175          *
176          * @param e never used.
177          */

178         public void actionPerformed(ActionEvent JavaDoc e)
179         {
180             if (getKey() == ESCAPE)
181                 quit();
182             else if (getKey() == ENTER)
183                 apply();
184         }
185     }
186
187     /**
188      * Sets up the L&F radio buttons.
189      */

190     private void lookAndFeelTab()
191     {
192         lookAndFeel = new JRadioButton[]{
193             new JRadioButton(CBIntText.get("Windows Look and Feel")),
194             new JRadioButton(CBIntText.get("Java Look and Feel")),
195             new JRadioButton(CBIntText.get("Motif Look and Feel")),
196             new JRadioButton(CBIntText.get("Mac Look and Feel"))};
197
198         String JavaDoc[] toolTip = new String JavaDoc[]{
199             CBIntText.get("Sets the look and feel to: Windows"),
200             CBIntText.get("Sets the look and feel to: Java"),
201             CBIntText.get("Sets the look and feel to: Motif"),
202             CBIntText.get("Sets the look and feel to: Apple Mac/OSX")};
203
204         ButtonGroup lookAndFeelButtonGroup = new ButtonGroup();
205         CBPanel lookAndFeelPanel = new CBPanel();
206
207         lookAndFeelPanel.addln(new JLabel(CBIntText.get("Select a New Look & Feel: ")));
208
209         // White space...
210
lookAndFeelPanel.addln(new JLabel(" "));
211
212         if (JXplorer.isWindows())
213             addLookAndFeelOption(lookAndFeelButtonGroup, WINDOWS, lookAndFeelPanel, toolTip);
214         else
215             lookAndFeel[WINDOWS].setSelected(false);
216
217         addLookAndFeelOption(lookAndFeelButtonGroup, JAVA, lookAndFeelPanel, toolTip);
218         addLookAndFeelOption(lookAndFeelButtonGroup, MOTIF, lookAndFeelPanel, toolTip);
219
220         if (JXplorer.isMac())
221             addLookAndFeelOption(lookAndFeelButtonGroup, MAC, lookAndFeelPanel, toolTip);
222         else
223             lookAndFeel[MAC].setSelected(false);
224
225         getLookAndFeel();
226
227         tabbedPane.addTab(CBIntText.get("Look & Feel"), new ImageIcon(dirImage + "look_feel.gif"), lookAndFeelPanel, CBIntText.get("Change the 'look and feel' of JXplorer, that is, adopt a similar appearance to another application."));
228     }
229
230     /**
231      * Adds a look and feel item to the panel.
232      *
233      * @param lookAndFeelButtonGroup the group to add it to.
234      * @param i the position to add it.
235      * @param lookAndFeelPanel the panel to add it too.
236      * @param toolTip the tooltip for the item.
237      */

238     private void addLookAndFeelOption(ButtonGroup lookAndFeelButtonGroup, int i, CBPanel lookAndFeelPanel, String JavaDoc[] toolTip)
239     {
240         lookAndFeelButtonGroup.add(lookAndFeel[i]);
241         lookAndFeelPanel.addln(lookAndFeel[i]);
242         lookAndFeel[i].setToolTipText(toolTip[i]);
243     }
244
245     /**
246      * Gets the L&F from the property file and set the appropriate combo box item.
247      */

248     private void getLookAndFeel()
249     {
250         lookAndFeelVal = new String JavaDoc[]{"com.sun.java.swing.plaf.windows.WindowsLookAndFeel",
251                                       "javax.swing.plaf.metal.MetalLookAndFeel",
252                                       "com.sun.java.swing.plaf.motif.MotifLookAndFeel",
253                                       "com.sun.java.swing.plaf.mac.MacLookAndFeel"};
254
255         for (int i = 0; i < 4; i++)
256         {
257             if (String.valueOf(lookAndFeelVal[i]).equalsIgnoreCase(JXplorer.getProperty("gui.lookandfeel")))
258                 lookAndFeel[i].setSelected(true);
259         }
260     }
261
262     /**
263      * Sets up the log method radio buttons.
264      */

265     private void logMethod()
266     {
267         CBPanel logMethodPanel = new CBPanel();
268
269         logMethodPanel.addln(new JLabel(CBIntText.get("Select a New Log Method: ")));
270
271         // White space...
272
logMethodPanel.addln(new JLabel(" "));
273
274         logMethodCombo = new JComboBox(logMethodVal);
275         logMethodCombo.setToolTipText(CBIntText.get("Set the log method in JXplorer."));
276
277         logMethodPanel.addln(logMethodCombo);
278
279         // White space...
280
logMethodPanel.addln(new JLabel(" "));
281
282         getLogMethod();
283
284         tabbedPane.addTab(CBIntText.get("Log Method"), new ImageIcon(dirImage + "log_method.gif"), logMethodPanel, CBIntText.get("Set the method of logging you want, for example, to a file."));
285     }
286
287     /**
288      * Gets the log method from the property file and sets the appropriate radio button.
289      */

290     private void getLogMethod()
291     {
292         String JavaDoc logHandlers = (JXplorer.getProperty("handlers")); // java logging standard property
293

294         if (logHandlers.indexOf("ConsoleHandler") > 0 && logHandlers.indexOf("FileHandler") > 0)
295             logMethodCombo.setSelectedItem(logMethodVal[3]);
296         else if (logHandlers.indexOf("FileHandler") > 0)
297             logMethodCombo.setSelectedItem(logMethodVal[2]);
298         else if (logHandlers.indexOf("ConsoleHandler") > 0)
299             logMethodCombo.setSelectedItem(logMethodVal[1]);
300         else
301             logMethodCombo.setSelectedItem(logMethodVal[0]);
302     }
303
304     /**
305      * Sets up the log level radio buttons.
306      */

307     private void logLevel()
308     {
309         CBPanel logLevelPanel = new CBPanel();
310
311         logLevelPanel.addln(new JLabel(CBIntText.get("Select a New Log Level: ")));
312         logLevelPanel.addln(new JLabel(" "));
313
314         logLevelCombo = new JComboBox(logLevelVal);
315         logLevelCombo.setToolTipText(CBIntText.get("Set the logging level in JXplorer."));
316         logLevelPanel.addln(logLevelCombo);
317         logLevelPanel.addln(new JLabel(" "));
318
319         getLogLevel();
320
321         tabbedPane.addTab(CBIntText.get("Log Level"),
322                 new ImageIcon(dirImage + "log_level.gif"), logLevelPanel,
323                 CBIntText.get("Set the level of logging you want, for example, errors only."));
324     }
325
326     /**
327      * Gets the log level from the property file and sets the appropriate combo box item.
328      */

329     private void getLogLevel()
330     {
331         // Get the log level from the property file...
332
Level JavaDoc logLevel;
333         try
334         {
335             logLevel = Level.parse(JXplorer.getProperty(".level"));
336         }
337         catch (Exception JavaDoc e) // IllegalArgumentException, or possibly a null pointer exception
338
{
339             logLevel = Level.WARNING; // default
340
}
341
342         if (logLevel.equals(Level.SEVERE))
343             logLevelCombo.setSelectedItem(logLevelVal[0]); // Errors Only option.
344
else if (logLevel.equals(Level.WARNING))
345             logLevelCombo.setSelectedItem(logLevelVal[1]); // Basic option.
346
else if (logLevel.equals(Level.INFO))
347             logLevelCombo.setSelectedItem(logLevelVal[2]); // Tree Operations option.
348
else if (logLevel.equals(Level.FINE))
349             logLevelCombo.setSelectedItem(logLevelVal[3]); // Extensive option.
350
else if (logLevel.equals(Level.FINEST))
351             logLevelCombo.setSelectedItem(logLevelVal[4]); // All option.
352
else if (logLevel.equals(Level.ALL))
353             logLevelCombo.setSelectedItem(logLevelVal[5]); // All + BER Trace option.
354
else
355             logLevelCombo.setSelectedItem(logLevelVal[1]);// Default option.
356
}
357
358     /**
359      * Sets up the LDAP Levels tab. Adds the text fields & labels to the panel.
360      */

361     private void ldapLevels()
362     {
363         ldapLimit = new JTextField();
364         ldapTimeout = new JTextField();
365
366         getLdapLevels();
367
368         CBPanel ldapLevelsPanel = new CBPanel();
369
370         ldapLevelsPanel.addln(new JLabel(CBIntText.get("Set LDAP Options: ")));
371         ldapLevelsPanel.addln(new JLabel(" ")); //TE: white space.
372
ldapLevelsPanel.add(new JLabel(CBIntText.get("LDAP Limit: ")));
373         ldapLevelsPanel.add(ldapLimit);
374         ldapLevelsPanel.newLine();
375         ldapLevelsPanel.addln(new JLabel(" ")); //TE: white space.
376
ldapLevelsPanel.add(new JLabel(CBIntText.get("LDAP Timeout: ")));
377         ldapLevelsPanel.add(ldapTimeout);
378
379         tabbedPane.addTab(CBIntText.get("Search Limits"),
380                 new ImageIcon(dirImage + "find.gif"), ldapLevelsPanel,
381                 CBIntText.get("Set the search levels, that is, the number of entries returned from a search and the timeout."));
382     }
383
384     /**
385      * Gets the ldap limit and timeout values from the property file and sets the text fields with these values.
386      */

387     private void getLdapLevels()
388     {
389         // Gets the values from the property file...
390
String JavaDoc limit = JXplorer.getProperty("option.ldap.limit");
391         String JavaDoc timeout = JXplorer.getProperty("option.ldap.timeout");
392
393         ldapLimit.setText(limit);
394         ldapLimit.setToolTipText(CBIntText.get("Enter the new limit level."));
395         ldapTimeout.setText(timeout);
396         ldapTimeout.setToolTipText(CBIntText.get("Enter the new timeout level."));
397     }
398
399     /**
400      * Sets up the URL tab with a combo box.
401      */

402     private void urlTab()
403     {
404         String JavaDoc[] url = new String JavaDoc[]{CBIntText.get("JXplorer"), CBIntText.get("Launch")};
405
406         CBPanel urlPanel = new CBPanel();
407         urlCombo = new JComboBox(url);
408
409         getURLHandling();
410
411         urlPanel.addln(new JLabel(CBIntText.get("Select URL handling: ")));
412         urlPanel.addln(new JLabel(" "));
413         urlPanel.addln(urlCombo);
414         urlPanel.addln(new JLabel(" "));
415         urlPanel.addln(new JLabel(CBIntText.get("Note: Launch is for Windows only.")));
416
417         tabbedPane.addTab(CBIntText.get("URL"), new ImageIcon(dirImage + "url.gif"), urlPanel, CBIntText.get("Select how you would like the URLs handled in JXplorer."));
418     }
419
420     /**
421      * Gets the url handling type (either JXplorer or Launch -
422      * if something else, it defaults to JXplorer)
423      * from the property file and sets the url combo box.
424      */

425     private void getURLHandling()
426     {
427         // Gets the value from the property file...
428
String JavaDoc urlHandling = JXplorer.getProperty("option.url.handling");
429
430         int index = 0;
431
432         if (urlHandling != null)
433             if (urlHandling.equalsIgnoreCase("Launch"))
434                 index = 1;
435
436         urlCombo.setSelectedIndex(index);
437     }
438
439     /**
440      * Sets up the Password option tab.
441      */

442     private void pwdTab()
443     {
444         String JavaDoc[] cache = new String JavaDoc[] {CBIntText.get("Yes"),CBIntText.get("No")};
445
446         CBPanel urlPanel = new CBPanel();
447         cachePwdCombo = new JComboBox(cache);
448
449         getPasswordCachingOption();
450
451         urlPanel.addln(new JLabel(CBIntText.get("Cache passwords: ")));
452         urlPanel.addln(new JLabel(" "));
453         urlPanel.addln(cachePwdCombo);
454         urlPanel.addln(new JLabel(" "));
455         urlPanel.addln(new JLabel(CBIntText.get(" ")));
456
457         tabbedPane.addTab(CBIntText.get("Cache Passwords"), new ImageIcon(dirImage + "cachePwds.gif"), urlPanel, CBIntText.get("Select Yes if you want passwords cached in JXplorer."));
458     }
459
460    /**
461     * Gets the password caching option from the property
462     * file and sets the cachePwd combo box.
463     */

464     private void getPasswordCachingOption()
465     {
466         // Gets the value from the property file...
467
String JavaDoc pwdCaching = JXplorer.getProperty("jxplorer.cache.passwords");
468
469         int index = 0;
470
471         if(pwdCaching!=null)
472             if(pwdCaching.equalsIgnoreCase("false"))
473                 index = 1;
474
475         cachePwdCombo.setSelectedIndex(index);
476     }
477
478    /**
479      * Calls the appropriate save methods then exits.
480      */

481     private void apply()
482     {
483         checkLookAndFeel();
484         checkLogMethod();
485         checkLogLevel();
486         checkLdapLevels();
487         checkUrlHandling();
488         checkCachePwds();
489
490         quit();
491     }
492
493     /**
494      * Checks if the L&F has been changed. If so updates
495      * the property file and sets the L&F as requested.
496      */

497     private void checkLookAndFeel()
498     {
499         // Used for exception info...
500
JRadioButton rb = null; //TE: used for exception info.
501

502         String JavaDoc currentLF = JXplorer.getProperty("gui.lookandfeel");
503
504         try
505         {
506             if ((lookAndFeel[WINDOWS].isSelected()) == true)
507             {
508                 // Don't change it unless we have to...
509
if(currentLF.equalsIgnoreCase(WINDOWS_LF))
510                     return;
511
512                 rb = setNewLookAndFeel(WINDOWS_LF, WINDOWS);
513             }
514             else if ((lookAndFeel[JAVA].isSelected()) == true)
515             {
516                 // Don't change it unless we have to...
517
if(currentLF.equalsIgnoreCase(JAVA_LF))
518                     return;
519
520                 rb = setNewLookAndFeel(JAVA_LF, JAVA);
521             }
522             else if ((lookAndFeel[MOTIF].isSelected()) == true)
523             {
524                 // Don't change it unless we have to...
525
if(currentLF.equalsIgnoreCase(MOTIF_LF))
526                     return;
527
528                 rb = setNewLookAndFeel(MOTIF_LF, MOTIF);
529             }
530             else if ((lookAndFeel[MAC].isSelected()) == true)
531             {
532                 // Don't change it unless we have to...
533
if(currentLF.equalsIgnoreCase(MAC_LF))
534                     return;
535
536                 rb = setNewLookAndFeel(MAC_LF, MAC);
537             }
538         }
539         catch (UnsupportedLookAndFeelException exc) // It can throw an exception if you try to set windows on a non-windows box.
540
{
541             rb.setEnabled(false);
542             log.warning("Unsupported LookAndFeel: " + rb.getText());
543         }
544         catch (Exception JavaDoc exc) // Shouldn't happen, but this is a pretty bizarre operation so just in case...
545
{
546             rb.setEnabled(false);
547             exc.printStackTrace();
548             log.warning("Could not load LookAndFeel: " + rb.getText());
549             exc.printStackTrace();
550         }
551
552         // Sets the cursor to an hour-glass...
553
getOwner().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
554
555         updateLookAndFeel();
556
557         if (mainMenu.getConnection != null)
558             SwingUtilities.updateComponentTreeUI(mainMenu.getConnection);
559
560         // Sets the cursor back to normal...
561
getOwner().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
562
563         // Force a refresh of the attribute display...so that the fields don't disappear (bug 367)...
564
(jx.getAttributeDisplay()).refreshEditors();
565     }
566
567     /**
568      * Sets the look and feel and registers it in the property file.
569      * @param lf the look and feel (package name).
570      * @param pos the position of the lf in the radio buttons.
571      * @return the selected radio button.
572      * @throws ClassNotFoundException
573      * @throws InstantiationException
574      * @throws IllegalAccessException
575      * @throws UnsupportedLookAndFeelException
576      */

577     private JRadioButton setNewLookAndFeel(String JavaDoc lf, int pos)
578             throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc, IllegalAccessException JavaDoc, UnsupportedLookAndFeelException
579     {
580         // If this fails we know which L&F made it fail...
581
JRadioButton rb = lookAndFeel[pos];
582         UIManager.setLookAndFeel(lf);
583
584         // Updates the 'gui.lookandfeel' value in the dxconfig property file with the windows L&F...
585
JXplorer.setProperty("gui.lookandfeel", lf);
586         return rb;
587     }
588
589     /**
590      * There must be a better way of doing this but here it is anyway...
591      * This method tries to make sure that the whole of JXplorer actually gets
592      * the new Look and Feel. It should work by just using...
593      * <br>'SwingUtilities.updateComponentTreeUI(getOwner());',<br>
594      * but some components are forgotten about - such as this window, the search
595      * gui and the popup tree tool. So this method manually tells them to update.
596      * But thats not all - each tree has its own copy of the search gui & the popup
597      * tree tool...so each tree needs to be told to update these components.
598      * In all there are eight calls to the updateComponentTreeUI...phew.
599      */

600     private void updateLookAndFeel()
601     {
602         if ((getOwner() instanceof JXplorer) == false)
603         {
604             SwingUtilities.updateComponentTreeUI(getOwner());
605             return;
606         }
607
608         JXplorer jx = (JXplorer) getOwner();
609
610 //TE XXXXXXXXXX this produces bug 2578..........
611
// Update the bulk of JXplorer with the new L&F...
612
SwingUtilities.updateComponentTreeUI(jx);
613
614         // Make sure this window gets the new L&F too...
615
SwingUtilities.updateComponentTreeUI(this);
616
617         // Get the trees...
618
SmartTree explore = jx.getTree();
619         SmartTree search = jx.getSearchTree();
620         SmartTree schema = jx.getSchemaTree();
621
622         // To stop the truncation of tree nodes esp in Java L&F...what a joke....
623
SwingUtilities.updateComponentTreeUI(explore);
624         SwingUtilities.updateComponentTreeUI(search);
625         SwingUtilities.updateComponentTreeUI(schema);
626
627         // Make sure each tree's popup menu gets the new L&F...
628
SwingUtilities.updateComponentTreeUI(explore.getPopupTool());
629         SwingUtilities.updateComponentTreeUI(search.getPopupTool());
630         SwingUtilities.updateComponentTreeUI(schema.getPopupTool());
631
632         // Make sure each tree's search dialog gets the new L&F...
633
SearchGUI sExplore = explore.getSearchGUI();
634         SearchGUI sSearch = search.getSearchGUI();
635         SearchGUI sSchema = schema.getSearchGUI();
636
637         if (sExplore != null)
638             SwingUtilities.updateComponentTreeUI(sExplore);
639         if (sSearch != null)
640             SwingUtilities.updateComponentTreeUI(sSearch);
641         if (sSchema != null)
642             SwingUtilities.updateComponentTreeUI(sSchema);
643     }
644
645     /**
646      * Checks if the log method has been changed.
647      * If so updates the property file and sets
648      * the log method as requested.
649      */

650     private void checkLogMethod()
651     {
652         try
653         {
654             int logMethod = logMethodCombo.getSelectedIndex();
655
656             String JavaDoc original = JXplorer.getProperty("handlers");
657
658             switch (logMethod)
659             {
660                 case 0:
661                     JXplorer.setProperty("handlers", "");
662                     break;
663                 case 1:
664                     JXplorer.setProperty("handlers", "java.util.logging.ConsoleHandler");
665                     break;
666                 case 2:
667                     JXplorer.setProperty("handlers", "java.util.logging.FileHandler");
668                     break;
669                 case 3:
670                     JXplorer.setProperty("handlers", "java.util.logging.ConsoleHandler,java.util.logging.FileHandler");
671                     break;
672                 default:
673                     JXplorer.setProperty("handlers", "java.util.logging.ConsoleHandler,java.util.logging.FileHandler");
674             }
675
676             if (original.equals(JXplorer.getProperty("handlers")) == false)
677             {
678                 JXplorer.writePropertyFile();
679                 JXplorer.setupLogger();
680             }
681
682
683             //TODO implement Full GUI for java logging of JX packages - may have to wait for Sun to fix the broken logging system :-)
684
}
685         catch (Exception JavaDoc e)
686         {
687             return; // Should never happen. TODO: log properly
688
}
689
690     }
691
692     /**
693      * Checks if the log level has been changed.
694      * If so updates the property file and sets
695      * the log level as requested.
696      */

697     private void checkLogLevel()
698     {
699         String JavaDoc original = JXplorer.getProperty(".level");
700
701         switch (logLevelCombo.getSelectedIndex())
702         {
703             case 0:
704                 {
705                     JXplorer.setProperty(".level", "SEVERE");
706                     JXplorer.setProperty("com.ca.level", "SEVERE");
707                     break;
708                 } //TE: Errors Only option.
709
case 1:
710                 {
711                     JXplorer.setProperty(".level", "WARNING");
712                     JXplorer.setProperty("com.ca.level", "WARNING");
713                     break;
714                 } //TE: Basic option.
715
case 2:
716                 {
717                     JXplorer.setProperty(".level", "INFO");
718                     JXplorer.setProperty("com.ca.level", "INFO");
719                     break;
720                 } //TE: Tree Operations option.
721
case 3:
722                 {
723                     JXplorer.setProperty(".level", "FINE");
724                     JXplorer.setProperty("com.ca.level", "FINE");
725                     break;
726                 } //TE: Extensive option.
727
case 4:
728                 {
729                     JXplorer.setProperty(".level", "FINEST");
730                     JXplorer.setProperty("com.ca.level", "FINEST");
731                     break;
732                 } //TE: All option.
733
case 5:
734                 {
735                     JXplorer.setProperty(".level", "ALL");
736                     JXplorer.setProperty("com.ca.level", "ALL");
737                     break;
738                 } //TE: All + BER Trace option.
739
default:
740                 {
741                     JXplorer.setProperty(".level", "WARNING");
742                     JXplorer.setProperty("com.ca.level", "WARNING");
743                     break;
744                 } //TE: Errors Only option.
745
}
746
747         if (original.equals(JXplorer.getProperty(".handlers")) == false)
748         {
749             JXplorer.writePropertyFile();
750             JXplorer.setupLogger();
751         }
752
753         // Set the values for immediate use...
754
jx.checkSpecialLoggingActions();
755     }
756
757     /**
758      * Checks if the ldap levels have been changed by getting the values from the text areas.
759      * Sets the changes in the property file and in searchBroker.
760      */

761     private void checkLdapLevels()
762     {
763         String JavaDoc limit = ldapLimit.getText();
764         String JavaDoc timeout = ldapTimeout.getText();
765
766         try
767         {
768             // Make sure the values are of integer type...
769
Integer.valueOf(limit);
770             Integer.valueOf(timeout);
771         }
772         catch (NumberFormatException JavaDoc e)
773         {
774             CBUtility.error("Both Ldap Limit & Ldap timeout must be of Integer type.\n" + e);
775             getLdapLevels();
776         }
777
778         // Set the values in the property file...
779
JXplorer.setProperty("option.ldap.limit", limit);
780         JXplorer.setProperty("option.ldap.timeout", timeout);
781
782         // Sets the values in searchBroker for immediate use...
783
jx.searchBroker.setTimeout(Integer.parseInt(timeout));
784         jx.searchBroker.setLimit(Integer.parseInt(limit));
785     }
786
787     /**
788      * Checks what the URL handling is and sets it in the property file.
789      * Does this by getting the user selected index...if 0 then
790      * 'JXplorer' if 1 then 'Launch'.
791      */

792     private void checkUrlHandling()
793     {
794         int index = urlCombo.getSelectedIndex();
795
796         if (index == 1)
797             JXplorer.setProperty("option.url.handling", "Launch");
798         else
799             JXplorer.setProperty("option.url.handling", "JXplorer");
800     }
801
802    /**
803     * Checks what the URL handling is and sets it in the property file.
804     * Does this by getting the user selected index...if 0 then
805     * 'JXplorer' if 1 then 'Launch'.
806     */

807     private void checkCachePwds()
808     {
809         int index = cachePwdCombo.getSelectedIndex();
810
811         if(index == 1)
812             JXplorer.setProperty("jxplorer.cache.passwords", "false");
813         else
814             JXplorer.setProperty("jxplorer.cache.passwords", "true");
815     }
816
817    /**
818      * Resets all values in the advanced options window back to the values in the property file.
819      */

820     private void reset()
821     {
822         getLookAndFeel();
823         getLogLevel();
824         getLogMethod();
825         getLdapLevels();
826         getURLHandling();
827         getPasswordCachingOption();
828     }
829
830     /**
831      * Shuts the advanced options dialog.
832      */

833     private void quit()
834     {
835         setVisible(false);
836         dispose();
837     }
838 }
839
Popular Tags