reportmenubar.java
来自「测试工具」· Java 代码 · 共 567 行 · 第 1/2 页
JAVA
567 行
// TODO: do accelerator keys make sense? The key may not be present in
// translations
JMenu languageMenu = new JMenu(JMeterUtils.getResString("choose_language"));
languageMenu.setMnemonic('C');
// add english
JMenuItem english = new JMenuItem(JMeterUtils.getResString("en"), 'E');
english.addActionListener(ReportActionRouter.getInstance());
english.setActionCommand(ActionNames.CHANGE_LANGUAGE);
english.setName(Locale.ENGLISH.getLanguage());
languageMenu.add(english);
// add Japanese
JMenuItem japanese = new JMenuItem(JMeterUtils.getResString("jp"), 'J');
japanese.addActionListener(ReportActionRouter.getInstance());
japanese.setActionCommand(ActionNames.CHANGE_LANGUAGE);
japanese.setName(Locale.JAPANESE.getLanguage());
languageMenu.add(japanese);
// add Norwegian
JMenuItem norway = new JMenuItem(JMeterUtils.getResString("no"), 'N');
norway.addActionListener(ReportActionRouter.getInstance());
norway.setActionCommand(ActionNames.CHANGE_LANGUAGE);
norway.setName("no"); // No default for Norwegian
languageMenu.add(norway);
// add German
JMenuItem german = new JMenuItem(JMeterUtils.getResString("de"), 'G');
german.addActionListener(ReportActionRouter.getInstance());
german.setActionCommand(ActionNames.CHANGE_LANGUAGE);
german.setName(Locale.GERMAN.getLanguage());
languageMenu.add(german);
// add French
JMenuItem french = new JMenuItem(JMeterUtils.getResString("fr"), 'F');
french.addActionListener(ReportActionRouter.getInstance());
french.setActionCommand(ActionNames.CHANGE_LANGUAGE);
french.setName(Locale.FRENCH.getLanguage());
languageMenu.add(french);
// add chinese (simple)
JMenuItem chineseSimple = new JMenuItem(JMeterUtils.getResString("zh_cn"));
chineseSimple.addActionListener(ReportActionRouter.getInstance());
chineseSimple.setActionCommand(ActionNames.CHANGE_LANGUAGE);
chineseSimple.setName(Locale.SIMPLIFIED_CHINESE.toString());
languageMenu.add(chineseSimple);
// add chinese (traditional)
JMenuItem chineseTrad = new JMenuItem(JMeterUtils.getResString("zh_TW"));
chineseTrad.addActionListener(ReportActionRouter.getInstance());
chineseTrad.setActionCommand(ActionNames.CHANGE_LANGUAGE);
chineseTrad.setName(Locale.TRADITIONAL_CHINESE.toString());
languageMenu.add(chineseTrad);
// add spanish
JMenuItem spanish = new JMenuItem(JMeterUtils.getResString("es"));
spanish.addActionListener(ReportActionRouter.getInstance());
spanish.setActionCommand(ActionNames.CHANGE_LANGUAGE);
spanish.setName("es");
languageMenu.add(spanish);
return languageMenu;
}
/*
* Strings used to set up and process actions in this menu The strings need
* to agree with the those in the Action routines
*/
public static final String ACTION_SHUTDOWN = "shutdown";
public static final String ACTION_STOP = "stop";
public static final String ACTION_START = "start";
private void makeRunMenu() {
// RUN MENU
runMenu = new JMenu(JMeterUtils.getResString("run"));
runMenu.setMnemonic('R');
run_start = new JMenuItem(JMeterUtils.getResString("start"), 'S');
run_start.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_MASK));
run_start.addActionListener(ReportActionRouter.getInstance());
run_start.setActionCommand(ACTION_START);
run_stop = new JMenuItem(JMeterUtils.getResString("stop"), 'T');
run_stop.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, KeyEvent.CTRL_MASK));
run_stop.setEnabled(false);
run_stop.addActionListener(ReportActionRouter.getInstance());
run_stop.setActionCommand(ACTION_STOP);
run_shut = new JMenuItem(JMeterUtils.getResString("shutdown"), 'Y');
run_shut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, KeyEvent.CTRL_MASK));
run_shut.setEnabled(false);
run_shut.addActionListener(ReportActionRouter.getInstance());
run_shut.setActionCommand(ACTION_SHUTDOWN);
run_clear = new JMenuItem(JMeterUtils.getResString("clear"), 'C');
run_clear.addActionListener(ReportActionRouter.getInstance());
run_clear.setActionCommand(ActionNames.CLEAR);
run_clearAll = new JMenuItem(JMeterUtils.getResString("clear_all"), 'a');
run_clearAll.addActionListener(ReportActionRouter.getInstance());
run_clearAll.setActionCommand(ActionNames.CLEAR_ALL);
run_clearAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_MASK));
runMenu.add(run_start);
if (remote_start != null) {
runMenu.add(remote_start);
}
remote_start_all = new JMenuItem(JMeterUtils.getResString("remote_start_all"), 'Z');
remote_start_all.setName("remote_start_all");
remote_start_all.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK));
remote_start_all.addActionListener(ReportActionRouter.getInstance());
remote_start_all.setActionCommand("remote_start_all");
runMenu.add(remote_start_all);
runMenu.add(run_stop);
runMenu.add(run_shut);
if (remote_stop != null) {
runMenu.add(remote_stop);
}
remote_stop_all = new JMenuItem(JMeterUtils.getResString("remote_stop_all"), 'X');
remote_stop_all.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.ALT_MASK));
remote_stop_all.addActionListener(ReportActionRouter.getInstance());
remote_stop_all.setActionCommand("remote_stop_all");
runMenu.add(remote_stop_all);
if (remote_exit != null) {
runMenu.add(remote_exit);
}
remote_exit_all = new JMenuItem(JMeterUtils.getResString("remote_exit_all"));
remote_exit_all.addActionListener(ReportActionRouter.getInstance());
remote_exit_all.setActionCommand("remote_exit_all");
runMenu.add(remote_exit_all);
runMenu.addSeparator();
runMenu.add(run_clear);
runMenu.add(run_clearAll);
}
private void makeEditMenu() {
// EDIT MENU
editMenu = new JMenu(JMeterUtils.getResString("edit"));
// From the Java Look and Feel Guidelines: If all items in a menu
// are disabled, then disable the menu. Makes sense.
editMenu.setEnabled(false);
}
private void makeFileMenu() {
// FILE MENU
fileMenu = new JMenu(JMeterUtils.getResString("file"));
fileMenu.setMnemonic('F');
JMenuItem file_save = new JMenuItem(JMeterUtils.getResString("save"), 'S');
file_save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
file_save.setActionCommand("save");
file_save.addActionListener(ReportActionRouter.getInstance());
file_save.setEnabled(true);
file_save_as = new JMenuItem(JMeterUtils.getResString("save_all_as"), 'A');
file_save_as.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK));
file_save_as.setActionCommand("save_all_as");
file_save_as.addActionListener(ReportActionRouter.getInstance());
file_save_as.setEnabled(true);
file_load = new JMenuItem(JMeterUtils.getResString("menu_open"), 'O');
file_load.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
file_load.addActionListener(ReportActionRouter.getInstance());
// Set default SAVE menu item to disabled since the default node that
// is selected is ROOT, which does not allow items to be inserted.
file_load.setEnabled(false);
file_load.setActionCommand("open");
file_close = new JMenuItem(JMeterUtils.getResString("menu_close"), 'C');
file_close.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_MASK));
file_close.setActionCommand("close");
file_close.addActionListener(ReportActionRouter.getInstance());
file_exit = new JMenuItem(JMeterUtils.getResString("exit"), 'X');
file_exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_MASK));
file_exit.setActionCommand("exit");
file_exit.addActionListener(ReportActionRouter.getInstance());
file_merge = new JMenuItem(JMeterUtils.getResString("menu_merge"), 'M');
// file_merge.setAccelerator(
// KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
file_merge.addActionListener(ReportActionRouter.getInstance());
// Set default SAVE menu item to disabled since the default node that
// is selected is ROOT, which does not allow items to be inserted.
file_merge.setEnabled(false);
file_merge.setActionCommand("merge");
fileMenu.add(file_close);
fileMenu.add(file_load);
fileMenu.add(file_merge);
fileMenu.add(file_save);
fileMenu.add(file_save_as);
fileMenu.addSeparator();
fileMenu.add(file_exit);
}
public void setRunning(boolean running, String host) {
log.info("setRunning(" + running + "," + host + ")");
Iterator iter = remote_engine_start.iterator();
Iterator iter2 = remote_engine_stop.iterator();
Iterator iter3 = remote_engine_exit.iterator();
while (iter.hasNext() && iter2.hasNext() && iter3.hasNext()) {
JMenuItem start = (JMenuItem) iter.next();
JMenuItem stop = (JMenuItem) iter2.next();
JMenuItem exit = (JMenuItem) iter3.next();
if (start.getText().equals(host)) {
log.info("Found start host: " + start.getText());
start.setEnabled(!running);
}
if (stop.getText().equals(host)) {
log.info("Found stop host: " + stop.getText());
stop.setEnabled(running);
}
if (exit.getText().equals(host)) {
log.info("Found exit host: " + exit.getText());
exit.setEnabled(true);
}
}
}
public void setEnabled(boolean enable) {
run_start.setEnabled(!enable);
run_stop.setEnabled(enable);
run_shut.setEnabled(enable);
}
private void getRemoteItems() {
if (remoteHosts.length > 0) {
remote_start = new JMenu(JMeterUtils.getResString("remote_start"));
remote_stop = new JMenu(JMeterUtils.getResString("remote_stop"));
remote_exit = new JMenu(JMeterUtils.getResString("remote_exit"));
for (int i = 0; i < remoteHosts.length; i++) {
remoteHosts[i] = remoteHosts[i].trim();
JMenuItem item = new JMenuItem(remoteHosts[i]);
item.setActionCommand("remote_start");
item.setName(remoteHosts[i]);
item.addActionListener(ReportActionRouter.getInstance());
remote_engine_start.add(item);
remote_start.add(item);
item = new JMenuItem(remoteHosts[i]);
item.setActionCommand("remote_stop");
item.setName(remoteHosts[i]);
item.addActionListener(ReportActionRouter.getInstance());
item.setEnabled(false);
remote_engine_stop.add(item);
remote_stop.add(item);
item = new JMenuItem(remoteHosts[i]);
item.setActionCommand("remote_exit");
item.setName(remoteHosts[i]);
item.addActionListener(ReportActionRouter.getInstance());
item.setEnabled(false);
remote_engine_exit.add(item);
remote_exit.add(item);
}
}
}
/**
* Processes a locale change notification. Changes the texts in all menus to
* the new language.
*/
public void localeChanged(LocaleChangeEvent event) {
updateMenuElement(fileMenu);
updateMenuElement(editMenu);
updateMenuElement(runMenu);
updateMenuElement(optionsMenu);
updateMenuElement(helpMenu);
}
/**
* Refreshes all texts in the menu and all submenus to a new locale.
*/
private void updateMenuElement(MenuElement menu) {
Component component = menu.getComponent();
if (component.getName() != null) {
if (component instanceof JMenu) {
((JMenu) component).setText(JMeterUtils.getResString(component.getName()));
} else {
((JMenuItem) component).setText(JMeterUtils.getResString(component.getName()));
}
}
MenuElement[] subelements = menu.getSubElements();
for (int i = 0; i < subelements.length; i++) {
updateMenuElement(subelements[i]);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?