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 ; 10 import java.awt.event.ActionListener ; 11 import java.util.logging.Level ; 12 import java.util.logging.Logger ; 13 14 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 [] lookAndFeelVal; 31 32 private final String [] logLevelVal = new String []{CBIntText.get("Severe"), CBIntText.get("Warning"), CBIntText.get("Info"), CBIntText.get("Fine"), CBIntText.get("Finest"), CBIntText.get("All + BER Trace")}; 34 35 private final String [] logMethodVal = new String []{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 dirImage; 41 42 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 log = Logger.getLogger(AdvancedOptions.class.getName()); 49 50 public static final String WINDOWS_LF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; 52 public static final String JAVA_LF = "javax.swing.plaf.metal.MetalLookAndFeel"; 53 public static final String MOTIF_LF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; 54 public static final String MAC_LF = "com.sun.java.swing.plaf.mac.MacLookAndFeel"; 55 56 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 () 78 { 79 public void actionPerformed(ActionEvent 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 () 88 { 89 public void actionPerformed(ActionEvent 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 () 98 { 99 public void actionPerformed(ActionEvent e) 100 { 101 quit(); 102 } 103 }); 104 105 btnHelp = new CBButton(CBIntText.get("Help"), CBIntText.get("Click here for help")); 107 CBHelpSystem.useDefaultHelp(btnHelp, HelpIDs.CONFIG_ADVANCED); 108 109 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 lookAndFeelTab(); 119 120 ldapLevels(); 122 123 logLevel(); 125 126 logMethod(); 128 129 urlTab(); 131 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 160 private class MyAction extends CBAction 161 { 162 167 public MyAction(int key) 168 { 169 super(key); 170 } 171 172 178 public void actionPerformed(ActionEvent e) 179 { 180 if (getKey() == ESCAPE) 181 quit(); 182 else if (getKey() == ENTER) 183 apply(); 184 } 185 } 186 187 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 [] toolTip = new String []{ 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 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 238 private void addLookAndFeelOption(ButtonGroup lookAndFeelButtonGroup, int i, CBPanel lookAndFeelPanel, String [] toolTip) 239 { 240 lookAndFeelButtonGroup.add(lookAndFeel[i]); 241 lookAndFeelPanel.addln(lookAndFeel[i]); 242 lookAndFeel[i].setToolTipText(toolTip[i]); 243 } 244 245 248 private void getLookAndFeel() 249 { 250 lookAndFeelVal = new String []{"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 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 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 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 290 private void getLogMethod() 291 { 292 String logHandlers = (JXplorer.getProperty("handlers")); 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 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 329 private void getLogLevel() 330 { 331 Level logLevel; 333 try 334 { 335 logLevel = Level.parse(JXplorer.getProperty(".level")); 336 } 337 catch (Exception e) { 339 logLevel = Level.WARNING; } 341 342 if (logLevel.equals(Level.SEVERE)) 343 logLevelCombo.setSelectedItem(logLevelVal[0]); else if (logLevel.equals(Level.WARNING)) 345 logLevelCombo.setSelectedItem(logLevelVal[1]); else if (logLevel.equals(Level.INFO)) 347 logLevelCombo.setSelectedItem(logLevelVal[2]); else if (logLevel.equals(Level.FINE)) 349 logLevelCombo.setSelectedItem(logLevelVal[3]); else if (logLevel.equals(Level.FINEST)) 351 logLevelCombo.setSelectedItem(logLevelVal[4]); else if (logLevel.equals(Level.ALL)) 353 logLevelCombo.setSelectedItem(logLevelVal[5]); else 355 logLevelCombo.setSelectedItem(logLevelVal[1]); } 357 358 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(" ")); ldapLevelsPanel.add(new JLabel(CBIntText.get("LDAP Limit: "))); 373 ldapLevelsPanel.add(ldapLimit); 374 ldapLevelsPanel.newLine(); 375 ldapLevelsPanel.addln(new JLabel(" ")); 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 387 private void getLdapLevels() 388 { 389 String limit = JXplorer.getProperty("option.ldap.limit"); 391 String 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 402 private void urlTab() 403 { 404 String [] url = new String []{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 425 private void getURLHandling() 426 { 427 String 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 442 private void pwdTab() 443 { 444 String [] cache = new String [] {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 464 private void getPasswordCachingOption() 465 { 466 String 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 481 private void apply() 482 { 483 checkLookAndFeel(); 484 checkLogMethod(); 485 checkLogLevel(); 486 checkLdapLevels(); 487 checkUrlHandling(); 488 checkCachePwds(); 489 490 quit(); 491 } 492 493 497 private void checkLookAndFeel() 498 { 499 JRadioButton rb = null; 502 String currentLF = JXplorer.getProperty("gui.lookandfeel"); 503 504 try 505 { 506 if ((lookAndFeel[WINDOWS].isSelected()) == true) 507 { 508 if(currentLF.equalsIgnoreCase(WINDOWS_LF)) 510 return; 511 512 rb = setNewLookAndFeel(WINDOWS_LF, WINDOWS); 513 } 514 else if ((lookAndFeel[JAVA].isSelected()) == true) 515 { 516 if(currentLF.equalsIgnoreCase(JAVA_LF)) 518 return; 519 520 rb = setNewLookAndFeel(JAVA_LF, JAVA); 521 } 522 else if ((lookAndFeel[MOTIF].isSelected()) == true) 523 { 524 if(currentLF.equalsIgnoreCase(MOTIF_LF)) 526 return; 527 528 rb = setNewLookAndFeel(MOTIF_LF, MOTIF); 529 } 530 else if ((lookAndFeel[MAC].isSelected()) == true) 531 { 532 if(currentLF.equalsIgnoreCase(MAC_LF)) 534 return; 535 536 rb = setNewLookAndFeel(MAC_LF, MAC); 537 } 538 } 539 catch (UnsupportedLookAndFeelException exc) { 541 rb.setEnabled(false); 542 log.warning("Unsupported LookAndFeel: " + rb.getText()); 543 } 544 catch (Exception exc) { 546 rb.setEnabled(false); 547 exc.printStackTrace(); 548 log.warning("Could not load LookAndFeel: " + rb.getText()); 549 exc.printStackTrace(); 550 } 551 552 getOwner().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 554 555 updateLookAndFeel(); 556 557 if (mainMenu.getConnection != null) 558 SwingUtilities.updateComponentTreeUI(mainMenu.getConnection); 559 560 getOwner().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 562 563 (jx.getAttributeDisplay()).refreshEditors(); 565 } 566 567 577 private JRadioButton setNewLookAndFeel(String lf, int pos) 578 throws ClassNotFoundException , InstantiationException , IllegalAccessException , UnsupportedLookAndFeelException 579 { 580 JRadioButton rb = lookAndFeel[pos]; 582 UIManager.setLookAndFeel(lf); 583 584 JXplorer.setProperty("gui.lookandfeel", lf); 586 return rb; 587 } 588 589 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 SwingUtilities.updateComponentTreeUI(jx); 613 614 SwingUtilities.updateComponentTreeUI(this); 616 617 SmartTree explore = jx.getTree(); 619 SmartTree search = jx.getSearchTree(); 620 SmartTree schema = jx.getSchemaTree(); 621 622 SwingUtilities.updateComponentTreeUI(explore); 624 SwingUtilities.updateComponentTreeUI(search); 625 SwingUtilities.updateComponentTreeUI(schema); 626 627 SwingUtilities.updateComponentTreeUI(explore.getPopupTool()); 629 SwingUtilities.updateComponentTreeUI(search.getPopupTool()); 630 SwingUtilities.updateComponentTreeUI(schema.getPopupTool()); 631 632 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 650 private void checkLogMethod() 651 { 652 try 653 { 654 int logMethod = logMethodCombo.getSelectedIndex(); 655 656 String 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 } 685 catch (Exception e) 686 { 687 return; } 689 690 } 691 692 697 private void checkLogLevel() 698 { 699 String 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 } case 1: 710 { 711 JXplorer.setProperty(".level", "WARNING"); 712 JXplorer.setProperty("com.ca.level", "WARNING"); 713 break; 714 } case 2: 716 { 717 JXplorer.setProperty(".level", "INFO"); 718 JXplorer.setProperty("com.ca.level", "INFO"); 719 break; 720 } case 3: 722 { 723 JXplorer.setProperty(".level", "FINE"); 724 JXplorer.setProperty("com.ca.level", "FINE"); 725 break; 726 } case 4: 728 { 729 JXplorer.setProperty(".level", "FINEST"); 730 JXplorer.setProperty("com.ca.level", "FINEST"); 731 break; 732 } case 5: 734 { 735 JXplorer.setProperty(".level", "ALL"); 736 JXplorer.setProperty("com.ca.level", "ALL"); 737 break; 738 } default: 740 { 741 JXplorer.setProperty(".level", "WARNING"); 742 JXplorer.setProperty("com.ca.level", "WARNING"); 743 break; 744 } } 746 747 if (original.equals(JXplorer.getProperty(".handlers")) == false) 748 { 749 JXplorer.writePropertyFile(); 750 JXplorer.setupLogger(); 751 } 752 753 jx.checkSpecialLoggingActions(); 755 } 756 757 761 private void checkLdapLevels() 762 { 763 String limit = ldapLimit.getText(); 764 String timeout = ldapTimeout.getText(); 765 766 try 767 { 768 Integer.valueOf(limit); 770 Integer.valueOf(timeout); 771 } 772 catch (NumberFormatException e) 773 { 774 CBUtility.error("Both Ldap Limit & Ldap timeout must be of Integer type.\n" + e); 775 getLdapLevels(); 776 } 777 778 JXplorer.setProperty("option.ldap.limit", limit); 780 JXplorer.setProperty("option.ldap.timeout", timeout); 781 782 jx.searchBroker.setTimeout(Integer.parseInt(timeout)); 784 jx.searchBroker.setLimit(Integer.parseInt(limit)); 785 } 786 787 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 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 820 private void reset() 821 { 822 getLookAndFeel(); 823 getLogLevel(); 824 getLogMethod(); 825 getLdapLevels(); 826 getURLHandling(); 827 getPasswordCachingOption(); 828 } 829 830 833 private void quit() 834 { 835 setVisible(false); 836 dispose(); 837 } 838 } 839 | Popular Tags |