⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 测试工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * @param host
	 *            the host where JMeter threads are stopping
	 */
	public void showStoppingMessage(String host) {
		stoppingMessage = new JDialog(this, JMeterUtils.getResString("stopping_test_title"), true); //$NON-NLS-1$
		JLabel stopLabel = new JLabel(JMeterUtils.getResString("stopping_test") + ": " + host); //$NON-NLS-1$$NON-NLS-2$
		stopLabel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
		stoppingMessage.getContentPane().add(stopLabel);
		stoppingMessage.pack();
		ComponentUtil.centerComponentInComponent(this, stoppingMessage);
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				if (stoppingMessage != null) {// TODO - how can this be null?
					stoppingMessage.show();
				}
			}
		});
	}

    public void updateCounts() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                activeThreads.setText(Integer.toString(JMeterContextService.getNumberOfThreads()));
                totalThreads.setText(Integer.toString(JMeterContextService.getTotalThreads()));
            }
        });
    }

	public void setMainPanel(JComponent comp) {
		mainPanel.setViewportView(comp);
	}

	public JTree getTree() {
		return tree;
	}

	// TestListener implementation

	/**
	 * Called when a test is started on the local system. This implementation
	 * sets the running indicator and ensures that the menubar is enabled and in
	 * the running state.
	 */
	public void testStarted() {
		testStarted(LOCAL);
		menuBar.setEnabled(true);
	}

	/**
	 * Called when a test is started on a specific host. This implementation
	 * sets the running indicator and ensures that the menubar is in the running
	 * state.
	 * 
	 * @param host
	 *            the host where the test is starting
	 */
	public void testStarted(String host) {
		hosts.add(host);
		runningIndicator.setIcon(runningIcon);
        activeThreads.setText("0"); // $NON-NLS-1$
        totalThreads.setText("0"); // $NON-NLS-1$
		menuBar.setRunning(true, host);
	}

	/**
	 * Called when a test is ended on the local system. This implementation
	 * disables the menubar, stops the running indicator, and closes the
	 * stopping message dialog.
	 */
	public void testEnded() {
		testEnded(LOCAL);
		menuBar.setEnabled(false);
	}

	/**
	 * Called when a test is ended on the remote system. This implementation
	 * stops the running indicator and closes the stopping message dialog.
	 * 
	 * @param host
	 *            the host where the test is ending
	 */
	public void testEnded(String host) {
		hosts.remove(host);
		if (hosts.size() == 0) {
			runningIndicator.setIcon(stoppedIcon);
			JMeterContextService.endTest();
		}
		menuBar.setRunning(false, host);
		if (stoppingMessage != null) {
			stoppingMessage.dispose();
			stoppingMessage = null;
		}
        activeThreads.setText("0");
        totalThreads.setText("0");
	}

	/* Implements TestListener#testIterationStart(LoopIterationEvent) */
	public void testIterationStart(LoopIterationEvent event) {
	}

	/**
	 * Create the GUI components and layout.
	 */
	private void init() {
		menuBar = new JMeterMenuBar();
		setJMenuBar(menuBar);

		JPanel all = new JPanel(new BorderLayout());
		all.add(createToolBar(), BorderLayout.NORTH);

		JSplitPane treeAndMain = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);

		treePanel = createTreePanel();
		treeAndMain.setLeftComponent(treePanel);

		mainPanel = createMainPanel();
		treeAndMain.setRightComponent(mainPanel);

		treeAndMain.setResizeWeight(.2);
		treeAndMain.setContinuousLayout(true);
		all.add(treeAndMain, BorderLayout.CENTER);

		getContentPane().add(all);

		tree.setSelectionRow(1);
		addWindowListener(new WindowHappenings());
		
		setTitle(DEFAULT_TITLE);
		setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage());// $NON-NLS-1$
	}

	public void setExtendedFrameTitle(String fname) {
		// file New operation may set to null, so just return app name
		if (fname == null) {
			setTitle(DEFAULT_TITLE);
			return;
		}

		// allow for windows / chars in filename
		String temp = fname.replace('\\', '/'); // $NON-NLS-1$ // $NON-NLS-2$
		String simpleName = temp.substring(temp.lastIndexOf("/") + 1);// $NON-NLS-1$
		setTitle(simpleName + " (" + fname + ") - " + DEFAULT_TITLE); // $NON-NLS-1$ // $NON-NLS-2$
	}

	/**
	 * Create the JMeter tool bar pane containing the running indicator.
	 * 
	 * @return a panel containing the running indicator
	 */
	private Component createToolBar() {
		Box toolPanel = new Box(BoxLayout.X_AXIS);
		toolPanel.add(Box.createRigidArea(new Dimension(10, 15)));
		toolPanel.add(Box.createGlue());
        toolPanel.add(activeThreads);
        toolPanel.add(new JLabel(" / "));
        toolPanel.add(totalThreads);
        toolPanel.add(Box.createRigidArea(new Dimension(10, 15)));
        toolPanel.add(runningIndicator);
		return toolPanel;
	}

	/**
	 * Create the panel where the GUI representation of the test tree is
	 * displayed. The tree should already be created before calling this method.
	 * 
	 * @return a scroll pane containing the test tree GUI
	 */
	private JScrollPane createTreePanel() {
		JScrollPane treeP = new JScrollPane(tree);
		treeP.setMinimumSize(new Dimension(100, 0));
		return treeP;
	}

	/**
	 * Create the main panel where components can display their GUIs.
	 * 
	 * @return the main scroll pane
	 */
	private JScrollPane createMainPanel() {
		return new JScrollPane();
	}

	/**
	 * Create and initialize the GUI representation of the test tree.
	 * 
	 * @param treeModel
	 *            the test tree model
	 * @param treeListener
	 *            the test tree listener
	 * 
	 * @return the initialized test tree GUI
	 */
	private JTree makeTree(TreeModel treeModel, JMeterTreeListener treeListener) {
		JTree treevar = new JTree(treeModel) {
			public String getToolTipText(MouseEvent event) {
				TreePath path = this.getPathForLocation(event.getX(), event.getY());
				if (path != null) {
					Object treeNode = path.getLastPathComponent();
					if (treeNode instanceof DefaultMutableTreeNode) {
						Object testElement = ((DefaultMutableTreeNode) treeNode).getUserObject();
						if (testElement instanceof TestElement) {
							String comment = ((TestElement) testElement).getComment();
							if (comment != null && comment.length() > 0) {
								return comment;
								}
							}
						}
					}
				return null;
				}
			};
       	treevar.setToolTipText("");
		treevar.setCellRenderer(getCellRenderer());
		treevar.setRootVisible(false);
		treevar.setShowsRootHandles(true);

		treeListener.setJTree(treevar);
		treevar.addTreeSelectionListener(treeListener);
		treevar.addMouseListener(treeListener);
		treevar.addMouseMotionListener(treeListener);
		treevar.addKeyListener(treeListener);

		return treevar;
	}

	/**
	 * Create the tree cell renderer used to draw the nodes in the test tree.
	 * 
	 * @return a renderer to draw the test tree nodes
	 */
	private TreeCellRenderer getCellRenderer() {
		DefaultTreeCellRenderer rend = new JMeterCellRenderer();
		rend.setFont(new Font("Dialog", Font.PLAIN, 11));
		return rend;
	}

	/**
	 * Repaint pieces of the GUI as needed while dragging. This method should
	 * only be called from the Swing event thread.
	 * 
	 * @param dragIcon
	 *            the component being dragged
	 * @param x
	 *            the current mouse x coordinate
	 * @param y
	 *            the current mouse y coordinate
	 */
	public void drawDraggedComponent(Component dragIcon, int x, int y) {
		Dimension size = dragIcon.getPreferredSize();
		treePanel.paintImmediately(previousDragXLocation, previousDragYLocation, size.width, size.height);
		this.getLayeredPane().setLayer(dragIcon, 400);
		SwingUtilities.paintComponent(treePanel.getGraphics(), dragIcon, treePanel, x, y, size.width, size.height);
		previousDragXLocation = x;
		previousDragYLocation = y;
	}

	/**
	 * A window adapter used to detect when the main JMeter frame is being
	 * closed.
	 */
	private static class WindowHappenings extends WindowAdapter {
		/**
		 * Called when the main JMeter frame is being closed. Sends a
		 * notification so that JMeter can react appropriately.
		 * 
		 * @param event
		 *            the WindowEvent to handle
		 */
		public void windowClosing(WindowEvent event) {
			ActionRouter.getInstance().actionPerformed(new ActionEvent(this, event.getID(), ActionNames.EXIT));
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -