📄 optiondialog.java
字号:
package org.jr.jzj;
/**
* <p>Copyright: Copyright (c) 2002-2003</p>
* <p>Company: JavaResearch(http://www.javaresearch.org)</p>
* <p>最后更新日期:2003年3月12日
* @author Cherami,Barney,Brain
* @version 0.8
*/
import java.io.*;
import java.util.prefs.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.text.*;
import org.jr.swing.*;
import org.jr.swing.util.*;
import org.jr.util.*;
/**
* 选项对话框。
*/
public class OptionDialog
extends JDialog {
public final static String PP_NAME = "options";
private static final String[] loglevels = {
"OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "ALL"};
private final static Color borderColor = new Color(148, 145, 140);
private static JZJLogger logger = new JZJLogger(OptionDialog.class);
Preferences preference = JZipJar.preference;
JZJResources resource = JZJResources.getResources();
/**
* panels
*/
JTabbedPane tabctrl = new JTabbedPane();
JPanel bottomPanel = new JPanel();
ViewPanel viewpanel;
ToolbarPanel toolbarpanel;
JPanel folderspanel;
JPanel locpanel;
JPanel mispanel;
BorderLayout borderLayout = new BorderLayout();
JButton okButton;
JButton applyButton;
JButton cancelButton;
JButton selectButton;
JButton viewerButton;
JButton scannerButton;
//
JTextField tfviewer = new JTextField();
JTextField tfscanner = new JTextField();
//
JCheckBox cbautoopen = new JCheckBox();
JSpinner sprecentfiles = new JSpinner();
JComboBox cbbloglevel = new JComboBox();
//
JRadioButton rbdefault = new JRadioButton();
JRadioButton rblast_s = new JRadioButton();
JRadioButton rbfolder_s = new JRadioButton();
JTextField tfstartup = new JTextField();
JButton startupButton;
//
JRadioButton rbopen_e = new JRadioButton();
JRadioButton rblast_e = new JRadioButton();
JRadioButton rbfolder_e = new JRadioButton();
JTextField tfextract = new JTextField();
JButton extractButton;
//
JRadioButton rbopen_a = new JRadioButton();
JRadioButton rblast_a = new JRadioButton();
JRadioButton rbfolder_a = new JRadioButton();
JTextField tfadd = new JTextField();
JButton addButton;
//
JTextField tfwork = new JTextField();
JButton workButton;
public OptionDialog(Frame frame) {
super(frame, true);
try {
init();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void init() throws Exception {
Container container = this.getContentPane();
container.setLayout(borderLayout);
setTitle(resource.getString("o_title"));
buildClient();
container.add(tabctrl, BorderLayout.CENTER);
buildBottomPanel();
container.add(bottomPanel, BorderLayout.SOUTH);
setSize(480, 360);
}
private void buildClient() {
//viewpanel = buildViewPanel();
viewpanel = new ViewPanel();
tabctrl.add(resource.getString("o_view_title"), viewpanel);
toolbarpanel = new ToolbarPanel();
tabctrl.add(resource.getString("o_toolbar_title"), toolbarpanel);
folderspanel = buildFoldersPanel();
tabctrl.add(resource.getString("o_folder_title"), folderspanel);
locpanel = buildLocationsPanel();
tabctrl.add(resource.getString("o_location_title"), locpanel);
mispanel = buildMisPanel();
tabctrl.add(resource.getString("o_mis_title"), mispanel);
}
private void buildBottomPanel() {
applyButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_apply"));
//applyButton = createButton("o_b_apply");
bottomPanel.add(applyButton, null);
applyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
OptionDialog.this.onOK();
}
});
okButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_ok"));
bottomPanel.add(okButton, null);
//添加事件监听器,确定按钮按下的时候
//
okButton.addActionListener(new OKAction());
cancelButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_cancel"));
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
OptionDialog.this.onCancel();
OptionDialog.this.setVisible(false);
}
});
bottomPanel.add(cancelButton, null);
okButton.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
OptionDialog.this.setVisible(false);
}
}
, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
}
/**
* 创建文件夹面板
* @return
*/
private JPanel buildFoldersPanel() {
int basex = 8, basey = 16; //坐标基础
int vh = 125, vw = 232; //表格panel的基础
int height = 20, width = 100; //ctrl的尺寸
JPanel p = new JPanel();
p.setLayout(null);
///////////////////////////////////////////////////////////////////////////////
JPanel ps = new JPanel();
ps.setBounds(0, 0, vw, vh);
ps.setLayout(null);
p.add(ps, null);
String[] o_f_startup = resource.getStringArray("o_f_startup");
ps.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,
borderColor), o_f_startup[0]));
ButtonGroup sp = new ButtonGroup();
sp.add(rbdefault);
sp.add(rblast_s);
sp.add(rbfolder_s);
rbdefault.setText(o_f_startup[1]);
rbdefault.setBounds(basex, basey, 160, height);
ps.add(rbdefault);
rblast_s.setText(o_f_startup[2]);
rblast_s.setBounds(basex, basey + 1 * height, 160, height);
ps.add(rblast_s);
rbfolder_s.setText(o_f_startup[3]);
rbfolder_s.setBounds(basex, basey + 2 * height, 70, height);
ps.add(rbfolder_s);
tfstartup.setBounds(basex + 70, basey + 2 * height, 100, height);
ps.add(tfstartup);
startupButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_browsebtn"));
startupButton.setBounds(basex + 180, basey + 2 * height, height, height);
startupButton.addActionListener(new SelectPathAction(tfstartup, rbfolder_s));
ps.add(startupButton, null);
//////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
JPanel pe = new JPanel();
pe.setBounds(0, vh, vw, vh);
pe.setLayout(null);
p.add(pe, null);
String[] o_f_extract = resource.getStringArray("o_f_extract");
pe.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,
borderColor), o_f_extract[0]));
ButtonGroup ep = new ButtonGroup();
ep.add(rbopen_e);
ep.add(rblast_e);
ep.add(rbfolder_e);
rbopen_e.setText(o_f_extract[1]);
rbopen_e.setBounds(basex, basey, 160, height);
pe.add(rbopen_e);
rblast_e.setText(o_f_extract[2]);
rblast_e.setBounds(basex, basey + 1 * height, 160, height);
pe.add(rblast_e);
rbfolder_e.setText(o_f_extract[3]);
rbfolder_e.setBounds(basex, basey + 2 * height, 70, height);
pe.add(rbfolder_e);
tfextract.setBounds(basex + 70, basey + 2 * height, 100, height);
pe.add(tfextract);
extractButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_browsebtn"));
extractButton.setBounds(basex + 180, basey + 2 * height, height, height);
extractButton.addActionListener(new SelectPathAction(tfextract, rbfolder_e));
pe.add(extractButton, null);
//////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
JPanel pa = new JPanel();
pa.setBounds(vw, 0, vw, vh);
pa.setLayout(null);
p.add(pa, null);
String[] o_f_add = resource.getStringArray("o_f_add");
pa.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,
borderColor), o_f_add[0]));
ButtonGroup ap = new ButtonGroup();
ap.add(rbopen_a);
ap.add(rblast_a);
ap.add(rbfolder_a);
rbopen_a.setText(o_f_add[1]);
rbopen_a.setBounds(basex, basey, 160, height);
pa.add(rbopen_a);
rblast_a.setText(o_f_add[2]);
rblast_a.setBounds(basex, basey + 1 * height, 160, height);
pa.add(rblast_a);
rbfolder_a.setText(o_f_add[3]);
rbfolder_a.setBounds(basex, basey + 2 * height, 70, height);
pa.add(rbfolder_a);
tfadd.setBounds(basex + 70, basey + 2 * height, 100, height);
pa.add(tfadd);
addButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_browsebtn"));
addButton.setBounds(basex + 180, basey + 2 * height, height, height);
addButton.addActionListener(new SelectPathAction(tfadd, rbfolder_a));
pa.add(addButton, null);
//////////////////////////////////////////////////
JPanel pw = new JPanel();
pw.setBounds(vw, vh, vw, vh);
pw.setLayout(null);
p.add(pw, null);
String[] o_f_work = resource.getStringArray("o_f_work");
pw.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,
borderColor), o_f_work[0]));
tfwork.setBounds(basex + 6, basey + 0 * height + 6, 150, height);
pw.add(tfwork);
workButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_browsebtn"));
workButton.setBounds(basex + 160, basey + 0 * height + 6, height, height);
workButton.addActionListener(new SelectPathAction(tfwork, null));
pw.add(workButton, null);
onCancel_Folders();
return p;
}
/**
* 程序位置面板
* @return
*/
private JPanel buildLocationsPanel() {
int basex = 16, basey = 10;
int height = 20, width = 160;
JLabel label;
JPanel p = new JPanel();
p.setLayout(null);
label = new JLabel(resource.getString("o_l_viewer"));
label.setBounds(basex, basey, 100, height);
p.add(label, null);
tfviewer.setBounds(basex, basey + 1 * height, width, height);
p.add(tfviewer, null);
viewerButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_browsebtn"));
viewerButton.setBounds(basex + width + 20, basey + 1 * height, height,
height);
viewerButton.addActionListener(new BrowseAction(tfviewer));
p.add(viewerButton, null);
label = new JLabel(resource.getString("o_l_virusscanner"));
label.setBounds(basex, basey + 2 * height, 100, height);
p.add(label, null);
tfscanner.setBounds(basex, basey + 3 * height, width, height);
p.add(tfscanner, null);
scannerButton = SwingUtil.createDynamicButton( (ButtonProperty) resource.
getObject("o_b_browsebtn"));
scannerButton.setBounds(basex + width + 20, basey + 3 * height, height,
height);
scannerButton.addActionListener(new BrowseAction(tfscanner));
p.add(scannerButton, null);
onCancel_Programlocations();
return p;
}
/**
* 其他杂项面板
* @return
*/
private JPanel buildMisPanel() {
int basex = 16, basey = 10;
int height = 28, width = 160;
JLabel label;
JPanel p = new JPanel();
p.setLayout(null);
cbautoopen.setText(resource.getString("o_m_autoopen"));
cbautoopen.setBounds(basex, basey, 360, height);
p.add(cbautoopen);
label = new JLabel(resource.getString("o_m_recentfiles"));
label.setBounds(basex, basey + 1 * height, 220, height);
sprecentfiles.setBounds(basex + 220, basey + 1 * height, 40, height);
// sprecentfiles.setm
p.add(sprecentfiles, null);
p.add(label, null);
SpinnerNumberModel model = new SpinnerNumberModel(4, 4, 10, 1);
sprecentfiles.setModel(model);
label = new JLabel(resource.getString("o_m_loglevel"));
label.setBounds(basex, basey + 2 * height, 100, height);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -