reportmenubar.java
来自「测试工具」· Java 代码 · 共 567 行 · 第 1/2 页
JAVA
567 行
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter.gui.util;
import java.awt.Component;
import java.awt.event.KeyEvent;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import javax.swing.UIManager;
import org.apache.jmeter.report.gui.action.ReportActionRouter;
import org.apache.jmeter.gui.action.ActionNames;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.util.LocaleChangeEvent;
import org.apache.jmeter.util.LocaleChangeListener;
import org.apache.jmeter.util.SSLManager;
import org.apache.jorphan.util.JOrphanUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
/**
* This is a version of the MenuBar for the reporting tool. I started
* with the existing jmeter menubar.
* @author Peter Lin
* @author Michael Stover
* @version $Revision: 493793 $ updated on $Date: 2007-01-07 18:19:27 +0000 (Sun, 07 Jan 2007) $
*/
public class ReportMenuBar extends JMenuBar implements LocaleChangeListener {
transient private static Logger log = LoggingManager.getLoggerForClass();
JMenu fileMenu;
JMenuItem file_save_as;
JMenuItem file_load;
JMenuItem file_merge;
JMenuItem file_exit;
JMenuItem file_close;
JMenu editMenu;
JMenu edit_add;
// JMenu edit_add_submenu;
JMenuItem edit_remove; // TODO - should this be created?
JMenu runMenu;
JMenuItem run_start;
JMenu remote_start;
JMenuItem remote_start_all;
Collection remote_engine_start;
JMenuItem run_stop;
private JMenuItem run_shut; // all the others could be private too?
JMenu remote_stop;
JMenuItem remote_stop_all;
Collection remote_engine_stop;
JMenuItem run_clear;
JMenuItem run_clearAll;
// JMenu reportMenu;
// JMenuItem analyze;
JMenu optionsMenu;
JMenu lafMenu;
JMenuItem sslManager;
JMenu helpMenu;
JMenuItem help_about;
String[] remoteHosts;
private JMenu remote_exit;
private JMenuItem remote_exit_all;
private Collection remote_engine_exit;
public ReportMenuBar() {
remote_engine_start = new LinkedList();
remote_engine_stop = new LinkedList();
remote_engine_exit = new LinkedList();
remoteHosts = JOrphanUtils.split(JMeterUtils.getPropDefault("remote_hosts", ""), ",");
if (remoteHosts.length == 1 && remoteHosts[0].equals("")) {
remoteHosts = new String[0];
}
this.getRemoteItems();
createMenuBar();
}
public void setFileSaveEnabled(boolean enabled) {
file_save_as.setEnabled(enabled);
}
public void setFileLoadEnabled(boolean enabled) {
if (file_load != null) {
file_load.setEnabled(enabled);
}
if (file_merge != null) {
file_merge.setEnabled(enabled);
}
}
public void setEditEnabled(boolean enabled) {
if (editMenu != null) {
editMenu.setEnabled(enabled);
}
}
public void setEditAddMenu(JMenu menu) {
// If the Add menu already exists, remove it.
if (edit_add != null) {
editMenu.remove(edit_add);
}
// Insert the Add menu as the first menu item in the Edit menu.
edit_add = menu;
editMenu.insert(edit_add, 0);
}
public void setEditMenu(JPopupMenu menu) {
if (menu != null) {
editMenu.removeAll();
Component[] comps = menu.getComponents();
for (int i = 0; i < comps.length; i++) {
editMenu.add(comps[i]);
}
editMenu.setEnabled(true);
} else {
// editMenu.setEnabled(false);
}
}
public void setEditAddEnabled(boolean enabled) {
// There was a NPE being thrown without the null check here.. JKB
if (edit_add != null) {
edit_add.setEnabled(enabled);
}
// If we are enabling the Edit-->Add menu item, then we also need to
// enable the Edit menu. The Edit menu may already be enabled, but
// there's no harm it trying to enable it again.
if (enabled) {
setEditEnabled(true);
} else {
// If we are disabling the Edit-->Add menu item and the
// Edit-->Remove menu item is disabled, then we also need to
// disable the Edit menu.
// The Java Look and Feel Guidelines say to disable a menu if all
// menu items are disabled.
if (!edit_remove.isEnabled()) {
editMenu.setEnabled(false);
}
}
}
public void setEditRemoveEnabled(boolean enabled) {
edit_remove.setEnabled(enabled);
// If we are enabling the Edit-->Remove menu item, then we also need to
// enable the Edit menu. The Edit menu may already be enabled, but
// there's no harm it trying to enable it again.
if (enabled) {
setEditEnabled(true);
} else {
// If we are disabling the Edit-->Remove menu item and the
// Edit-->Add menu item is disabled, then we also need to disable
// the Edit menu.
// The Java Look and Feel Guidelines say to disable a menu if all
// menu items are disabled.
if (!edit_add.isEnabled()) {
editMenu.setEnabled(false);
}
}
}
/**
* Creates the MenuBar for this application. I believe in my heart that this
* should be defined in a file somewhere, but that is for later.
*/
public void createMenuBar() {
makeFileMenu();
makeEditMenu();
makeRunMenu();
makeOptionsMenu();
makeHelpMenu();
this.add(fileMenu);
this.add(editMenu);
this.add(runMenu);
this.add(optionsMenu);
this.add(helpMenu);
}
private void makeHelpMenu() {
// HELP MENU
helpMenu = new JMenu(JMeterUtils.getResString("help"));
helpMenu.setMnemonic('H');
JMenuItem contextHelp = new JMenuItem(JMeterUtils.getResString("help"), 'H');
contextHelp.setActionCommand("help");
contextHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK));
contextHelp.addActionListener(ReportActionRouter.getInstance());
help_about = new JMenuItem(JMeterUtils.getResString("about"), 'A');
help_about.setActionCommand("about");
help_about.addActionListener(ReportActionRouter.getInstance());
helpMenu.add(contextHelp);
helpMenu.add(help_about);
}
private void makeOptionsMenu() {
// OPTIONS MENU
optionsMenu = new JMenu(JMeterUtils.getResString("option"));
JMenuItem functionHelper = new JMenuItem(JMeterUtils.getResString("function_dialog_menu_item"), 'F');
functionHelper.addActionListener(ReportActionRouter.getInstance());
functionHelper.setActionCommand("functions");
functionHelper.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK));
lafMenu = new JMenu(JMeterUtils.getResString("appearance"));
UIManager.LookAndFeelInfo lafs[] = UIManager.getInstalledLookAndFeels();
for (int i = 0; i < lafs.length; ++i) {
JMenuItem laf = new JMenuItem(lafs[i].getName());
laf.addActionListener(ReportActionRouter.getInstance());
laf.setActionCommand("laf:" + lafs[i].getClassName());
lafMenu.setMnemonic('L');
lafMenu.add(laf);
}
optionsMenu.setMnemonic('O');
optionsMenu.add(functionHelper);
optionsMenu.add(lafMenu);
if (SSLManager.isSSLSupported()) {
sslManager = new JMenuItem(JMeterUtils.getResString("sslManager"));
sslManager.addActionListener(ReportActionRouter.getInstance());
sslManager.setActionCommand("sslManager");
sslManager.setMnemonic('S');
sslManager.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_MASK));
optionsMenu.add(sslManager);
}
optionsMenu.add(makeLanguageMenu());
}
// TODO fetch list of languages from a file?
// N.B. Changes to language list need to be reflected in
// resources/PackageTest.java
private JMenu makeLanguageMenu() {
/*
* Note: the item name is used by ChangeLanguage to create a Locale for
* that language, so need to ensure that the language strings are valid
* If they exist, use the Locale language constants
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?