📄 advancedoptions.java
字号:
package com.ca.directory.jxplorer;
import com.ca.commons.cbutil.*;
import com.ca.directory.jxplorer.search.SearchGUI;
import com.ca.directory.jxplorer.tree.SmartTree;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Sets up an advanced options dialog box that is accessable through the Options drop down menu.
* It has five tabbed panes: the first is for the look and feel, the second is for log levels,
* the third is for the log method, the fourth is for LDAP limit & timeout and the last is for the URL handling.
* When the user clicks the 'Apply' button all of the changes are saved in the property file and reflected in JX.
*
* @author Trudi.
*/
public class AdvancedOptions extends JDialog
{
private CBButton btnApply, btnReset, btnCancel, btnHelp;
private JTextField ldapLimit, ldapTimeout;
private JComboBox urlCombo, logLevelCombo, logMethodCombo, cachePwdCombo;
private CBPanel display;
private JTabbedPane tabbedPane;
private JRadioButton[] lookAndFeel;
private String[] lookAndFeelVal;
// 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")};
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")};
// XXX WARNING - functionality is keyed on the order of elements in the following string array
private final String[] logMethodVal = new String[]{CBIntText.get("None"), CBIntText.get("Console"), CBIntText.get("File"), CBIntText.get("Console & File")};
private MainMenu mainMenu;
private final JXplorer jx;
private String dirImage;
// Utility constants for look and feel stuff..
private static final int WINDOWS = 0;
private static final int JAVA = 1;
protected static final int MOTIF = 2;
protected static final int MAC = 3;
private static Logger log = Logger.getLogger(AdvancedOptions.class.getName());
// Look and feels...
public static final String WINDOWS_LF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
public static final String JAVA_LF = "javax.swing.plaf.metal.MetalLookAndFeel";
public static final String MOTIF_LF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
public static final String MAC_LF = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
/**
* Sets up the panel, adds the tabbed pane and the buttons to it.
*
* @param jxplorer a JXplorer object to update changes with the log level, log method & LDAP values.
* @param mainMenu a MainMenu object to update the gui when the L&F is changed.
*/
public AdvancedOptions(JXplorer jxplorer, MainMenu mainMenu)
{
super(jxplorer);
setModal(true);
this.mainMenu = mainMenu;
jx = jxplorer;
dirImage = JXplorer.getProperty("dir.images");
setTitle(CBIntText.get("JXplorer Advanced Options"));
display = new CBPanel();
btnApply = new CBButton(CBIntText.get("Apply"), CBIntText.get("Click here to apply the changes"));
btnApply.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
apply();
}
});
btnReset = new CBButton(CBIntText.get("Reset"),
CBIntText.get("Click here to reset the options"));
btnReset.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
reset();
}
});
btnCancel = new CBButton(CBIntText.get("Cancel"),
CBIntText.get("Click here to exit Advanced Options"));
btnCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
quit();
}
});
// Creates a new help button with a listener that will open JX help at appropriate location...
btnHelp = new CBButton(CBIntText.get("Help"), CBIntText.get("Click here for help"));
CBHelpSystem.useDefaultHelp(btnHelp, HelpIDs.CONFIG_ADVANCED);
//TE: better way to implement keystroke listening...
display.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ENTER"), "enter");
display.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "escape");
display.getActionMap().put("enter", new MyAction(CBAction.ENTER));
display.getActionMap().put("escape", new MyAction(CBAction.ESCAPE));
tabbedPane = new JTabbedPane();
//Set up the L&F tab...
lookAndFeelTab();
// Set up the ldap levels tab...
ldapLevels();
// Set up the log level tab...
logLevel();
// Set up the log method tab...
logMethod();
// Set up the URL tab..
urlTab();
// Set up the password options tab...
pwdTab();
JPanel buttonPanel = new JPanel();
buttonPanel.add(btnApply);
buttonPanel.add(btnReset);
buttonPanel.add(btnCancel);
buttonPanel.add(btnHelp);
display.addln(tabbedPane);
display.addln(buttonPanel);
setSize(300, 280);
getContentPane().add(display);
}
/**
* Apparently it is better to use key bindings rather than adding a KeyListener...
* "for reacting in a special way to particular keys, you usually should use key
* bindings instead of a key listener".
* This class lets the user set the key as an int. If a key is pressed and it
* matches the assigned int, a check is done for if it is an escape or enter key.
* (27 or 10). If escape, the quit method is called. If enter, the apply
* method is called.
* Bug 4646.
*
* @author Trudi.
*/
private class MyAction extends CBAction
{
/**
* Calls super constructor.
*
* @param key
*/
public MyAction(int key)
{
super(key);
}
/**
* quit is called if the Esc key pressed,
* apply is called if Enter key is pressed.
*
* @param e never used.
*/
public void actionPerformed(ActionEvent e)
{
if (getKey() == ESCAPE)
quit();
else if (getKey() == ENTER)
apply();
}
}
/**
* Sets up the L&F radio buttons.
*/
private void lookAndFeelTab()
{
lookAndFeel = new JRadioButton[]{
new JRadioButton(CBIntText.get("Windows Look and Feel")),
new JRadioButton(CBIntText.get("Java Look and Feel")),
new JRadioButton(CBIntText.get("Motif Look and Feel")),
new JRadioButton(CBIntText.get("Mac Look and Feel"))};
String[] toolTip = new String[]{
CBIntText.get("Sets the look and feel to: Windows"),
CBIntText.get("Sets the look and feel to: Java"),
CBIntText.get("Sets the look and feel to: Motif"),
CBIntText.get("Sets the look and feel to: Apple Mac/OSX")};
ButtonGroup lookAndFeelButtonGroup = new ButtonGroup();
CBPanel lookAndFeelPanel = new CBPanel();
lookAndFeelPanel.addln(new JLabel(CBIntText.get("Select a New Look & Feel: ")));
// White space...
lookAndFeelPanel.addln(new JLabel(" "));
if (JXplorer.isWindows())
addLookAndFeelOption(lookAndFeelButtonGroup, WINDOWS, lookAndFeelPanel, toolTip);
else
lookAndFeel[WINDOWS].setSelected(false);
addLookAndFeelOption(lookAndFeelButtonGroup, JAVA, lookAndFeelPanel, toolTip);
addLookAndFeelOption(lookAndFeelButtonGroup, MOTIF, lookAndFeelPanel, toolTip);
if (JXplorer.isMac())
addLookAndFeelOption(lookAndFeelButtonGroup, MAC, lookAndFeelPanel, toolTip);
else
lookAndFeel[MAC].setSelected(false);
getLookAndFeel();
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."));
}
/**
* Adds a look and feel item to the panel.
*
* @param lookAndFeelButtonGroup the group to add it to.
* @param i the position to add it.
* @param lookAndFeelPanel the panel to add it too.
* @param toolTip the tooltip for the item.
*/
private void addLookAndFeelOption(ButtonGroup lookAndFeelButtonGroup, int i, CBPanel lookAndFeelPanel, String[] toolTip)
{
lookAndFeelButtonGroup.add(lookAndFeel[i]);
lookAndFeelPanel.addln(lookAndFeel[i]);
lookAndFeel[i].setToolTipText(toolTip[i]);
}
/**
* Gets the L&F from the property file and set the appropriate combo box item.
*/
private void getLookAndFeel()
{
lookAndFeelVal = new String[]{"com.sun.java.swing.plaf.windows.WindowsLookAndFeel",
"javax.swing.plaf.metal.MetalLookAndFeel",
"com.sun.java.swing.plaf.motif.MotifLookAndFeel",
"com.sun.java.swing.plaf.mac.MacLookAndFeel"};
for (int i = 0; i < 4; i++)
{
if (String.valueOf(lookAndFeelVal[i]).equalsIgnoreCase(JXplorer.getProperty("gui.lookandfeel")))
lookAndFeel[i].setSelected(true);
}
}
/**
* Sets up the log method radio buttons.
*/
private void logMethod()
{
CBPanel logMethodPanel = new CBPanel();
logMethodPanel.addln(new JLabel(CBIntText.get("Select a New Log Method: ")));
// White space...
logMethodPanel.addln(new JLabel(" "));
logMethodCombo = new JComboBox(logMethodVal);
logMethodCombo.setToolTipText(CBIntText.get("Set the log method in JXplorer."));
logMethodPanel.addln(logMethodCombo);
// White space...
logMethodPanel.addln(new JLabel(" "));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -