📄 mainframe.java
字号:
/*
* 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;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashSet;
import java.util.Set;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.MenuElement;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.gui.action.ActionNames;
import org.apache.jmeter.gui.action.ActionRouter;
import org.apache.jmeter.gui.tree.JMeterCellRenderer;
import org.apache.jmeter.gui.tree.JMeterTreeListener;
import org.apache.jmeter.gui.util.JMeterMenuBar;
import org.apache.jmeter.samplers.Remoteable;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.testelement.TestListener;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.ComponentUtil;
/**
* The main JMeter frame, containing the menu bar, test tree, and an area for
* JMeter component GUIs.
*
*/
public class MainFrame extends JFrame implements TestListener, Remoteable {
// This is used to keep track of local (non-remote) tests
// The name is chosen to be an unlikely host-name
private static final String LOCAL = "*local*"; // $NON-NLS-1$
// The default title for the Menu bar
private static final String DEFAULT_TITLE =
"Apache JMeter ("+JMeterUtils.getJMeterVersion()+")"; // $NON-NLS-1$ $NON-NLS-2$
/** The menu bar. */
private JMeterMenuBar menuBar;
/** The main panel where components display their GUIs. */
private JScrollPane mainPanel;
/** The panel where the test tree is shown. */
private JScrollPane treePanel;
/** The test tree. */
private JTree tree;
/** An image which is displayed when a test is running. */
private ImageIcon runningIcon = JMeterUtils.getImage("thread.enabled.gif");// $NON-NLS-1$
/** An image which is displayed when a test is not currently running. */
private ImageIcon stoppedIcon = JMeterUtils.getImage("thread.disabled.gif");// $NON-NLS-1$
/** The button used to display the running/stopped image. */
private JButton runningIndicator;
/** The x coordinate of the last location where a component was dragged. */
private int previousDragXLocation = 0;
/** The y coordinate of the last location where a component was dragged. */
private int previousDragYLocation = 0;
/** The set of currently running hosts. */
private Set hosts = new HashSet();
/** A message dialog shown while JMeter threads are stopping. */
private JDialog stoppingMessage;
private JLabel totalThreads;
private JLabel activeThreads;
/**
* Create a new JMeter frame.
*
* @param actionHandler
* this parameter is not used
* @param treeModel
* the model for the test tree
* @param treeListener
* the listener for the test tree
*/
public MainFrame(ActionListener actionHandler, TreeModel treeModel, JMeterTreeListener treeListener) {
// TODO: actionHandler isn't used -- remove it from the parameter list
// this.actionHandler = actionHandler;
// TODO: Make the running indicator its own class instead of a JButton
runningIndicator = new JButton(stoppedIcon);
runningIndicator.setMargin(new Insets(0, 0, 0, 0));
runningIndicator.setBorder(BorderFactory.createEmptyBorder());
totalThreads = new JLabel("0"); // $NON-NLS-1$
activeThreads = new JLabel("0"); // $NON-NLS-1$
tree = makeTree(treeModel, treeListener);
GuiPackage.getInstance().setMainFrame(this);
init();
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
}
/**
* Default constructor for the JMeter frame. This constructor will not
* properly initialize the tree, so don't use it.
*
* @deprecated Do not use - only needed for JUnit tests
*/
public MainFrame() {
}
// MenuBar related methods
// TODO: Do we really need to have all these menubar methods duplicated
// here? Perhaps we can make the menu bar accessible through GuiPackage?
/**
* Specify whether or not the File|Load menu item should be enabled.
*
* @param enabled
* true if the menu item should be enabled, false otherwise
*/
public void setFileLoadEnabled(boolean enabled) {
menuBar.setFileLoadEnabled(enabled);
}
/**
* Specify whether or not the File|Save menu item should be enabled.
*
* @param enabled
* true if the menu item should be enabled, false otherwise
*/
public void setFileSaveEnabled(boolean enabled) {
menuBar.setFileSaveEnabled(enabled);
}
/**
* Specify whether or not the File|Revert item should be enabled.
*
* @param enabled
* true if the menu item should be enabled, false otherwise
*/
public void setFileRevertEnabled(boolean enabled) {
menuBar.setFileRevertEnabled(enabled);
}
/**
* Specify the project file that was just loaded
*
* @param file - the full path to the file that was loaded
*/
public void setProjectFileLoaded(String file) {
menuBar.setProjectFileLoaded(file);
}
/**
* Set the menu that should be used for the Edit menu.
*
* @param menu
* the new Edit menu
*/
public void setEditMenu(JPopupMenu menu) {
menuBar.setEditMenu(menu);
}
/**
* Specify whether or not the Edit menu item should be enabled.
*
* @param enabled
* true if the menu item should be enabled, false otherwise
*/
public void setEditEnabled(boolean enabled) {
menuBar.setEditEnabled(enabled);
}
/**
* Set the menu that should be used for the Edit|Add menu.
*
* @param menu
* the new Edit|Add menu
*/
public void setEditAddMenu(JMenu menu) {
menuBar.setEditAddMenu(menu);
}
/**
* Specify whether or not the Edit|Add menu item should be enabled.
*
* @param enabled
* true if the menu item should be enabled, false otherwise
*/
public void setEditAddEnabled(boolean enabled) {
menuBar.setEditAddEnabled(enabled);
}
/**
* Specify whether or not the Edit|Remove menu item should be enabled.
*
* @param enabled
* true if the menu item should be enabled, false otherwise
*/
public void setEditRemoveEnabled(boolean enabled) {
menuBar.setEditRemoveEnabled(enabled);
}
/**
* Close the currently selected menu.
*/
public void closeMenu() {
if (menuBar.isSelected()) {
MenuElement[] menuElement = menuBar.getSubElements();
if (menuElement != null) {
for (int i = 0; i < menuElement.length; i++) {
JMenu menu = (JMenu) menuElement[i];
if (menu.isSelected()) {
menu.setPopupMenuVisible(false);
menu.setSelected(false);
break;
}
}
}
}
}
/**
* Show a dialog indicating that JMeter threads are stopping on a particular
* host.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -