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

📄 jmetermenubar.java

📁 测试工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		collapse.setAccelerator(KeyStrokes.COLLAPSE_ALL);
		optionsMenu.add(collapse);
		
		JMenuItem expand = new JMenuItem(JMeterUtils.getResString("menu_expand_all")); //$NON-NLS-1$
		expand.addActionListener(ActionRouter.getInstance());
		expand.setActionCommand(ActionNames.EXPAND_ALL);
		expand.setAccelerator(KeyStrokes.EXPAND_ALL);
		optionsMenu.add(expand);
	}

	// 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
		 */
		// TODO: do accelerator keys make sense? The key may not be present in
		// translations
		JMenu languageMenu = new JMenu(JMeterUtils.getResString("choose_language")); //$NON-NLS-1$
		languageMenu.setMnemonic('C');
		// add english
		JMenuItem english = new JMenuItem(JMeterUtils.getResString("en"), 'E'); //$NON-NLS-1$
		english.addActionListener(ActionRouter.getInstance());
		english.setActionCommand(ActionNames.CHANGE_LANGUAGE);
		english.setName(Locale.ENGLISH.getLanguage());
		languageMenu.add(english);
		// add Japanese
		JMenuItem japanese = new JMenuItem(JMeterUtils.getResString("jp"), 'J'); //$NON-NLS-1$
		japanese.addActionListener(ActionRouter.getInstance());
		japanese.setActionCommand(ActionNames.CHANGE_LANGUAGE);
		japanese.setName(Locale.JAPANESE.getLanguage());
		languageMenu.add(japanese);
		// add Norwegian
		JMenuItem norway = new JMenuItem(JMeterUtils.getResString("no"), 'N'); //$NON-NLS-1$
		norway.addActionListener(ActionRouter.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'); //$NON-NLS-1$
		german.addActionListener(ActionRouter.getInstance());
		german.setActionCommand(ActionNames.CHANGE_LANGUAGE);
		german.setName(Locale.GERMAN.getLanguage());
		languageMenu.add(german);
		// add French
		JMenuItem french = new JMenuItem(JMeterUtils.getResString("fr"), 'F'); //$NON-NLS-1$
		french.addActionListener(ActionRouter.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")); //$NON-NLS-1$
		chineseSimple.addActionListener(ActionRouter.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")); //$NON-NLS-1$
		chineseTrad.addActionListener(ActionRouter.getInstance());
		chineseTrad.setActionCommand(ActionNames.CHANGE_LANGUAGE);
		chineseTrad.setName(Locale.TRADITIONAL_CHINESE.toString());
		languageMenu.add(chineseTrad);
		// add spanish
		JMenuItem spanish = new JMenuItem(JMeterUtils.getResString("es")); //$NON-NLS-1$
		spanish.addActionListener(ActionRouter.getInstance());
		spanish.setActionCommand(ActionNames.CHANGE_LANGUAGE);
		spanish.setName("es"); //$NON-NLS-1$
		languageMenu.add(spanish);
		return languageMenu;
	}

	private void makeRunMenu() {
		// RUN MENU
		runMenu = new JMenu(JMeterUtils.getResString("run")); //$NON-NLS-1$
		runMenu.setMnemonic('R');
		run_start = new JMenuItem(JMeterUtils.getResString("start"), 'S'); //$NON-NLS-1$
		run_start.setAccelerator(KeyStrokes.ACTION_START);
		run_start.addActionListener(ActionRouter.getInstance());
		run_start.setActionCommand(ActionNames.ACTION_START);
		run_stop = new JMenuItem(JMeterUtils.getResString("stop"), 'T'); //$NON-NLS-1$
		run_stop.setAccelerator(KeyStrokes.ACTION_STOP);
		run_stop.setEnabled(false);
		run_stop.addActionListener(ActionRouter.getInstance());
		run_stop.setActionCommand(ActionNames.ACTION_STOP);

		run_shut = new JMenuItem(JMeterUtils.getResString("shutdown"), 'Y'); //$NON-NLS-1$
		run_shut.setAccelerator(KeyStrokes.ACTION_SHUTDOWN);
		run_shut.setEnabled(false);
		run_shut.addActionListener(ActionRouter.getInstance());
		run_shut.setActionCommand(ActionNames.ACTION_SHUTDOWN);

		run_clear = new JMenuItem(JMeterUtils.getResString("clear"), 'C'); //$NON-NLS-1$
		run_clear.addActionListener(ActionRouter.getInstance());
		run_clear.setActionCommand(ActionNames.CLEAR);
		run_clear.setAccelerator(KeyStrokes.CLEAR);
		
		run_clearAll = new JMenuItem(JMeterUtils.getResString("clear_all"), 'a'); //$NON-NLS-1$
		run_clearAll.addActionListener(ActionRouter.getInstance());
		run_clearAll.setActionCommand(ActionNames.CLEAR_ALL);
		run_clearAll.setAccelerator(KeyStrokes.CLEAR_ALL);
		
		runMenu.add(run_start);
		if (remote_start != null) {
			runMenu.add(remote_start);
		}
		remote_start_all = new JMenuItem(JMeterUtils.getResString("remote_start_all")); //$NON-NLS-1$
		remote_start_all.setName("remote_start_all"); //$NON-NLS-1$
		remote_start_all.setAccelerator(KeyStrokes.REMOTE_START_ALL);
		remote_start_all.addActionListener(ActionRouter.getInstance());
		remote_start_all.setActionCommand(ActionNames.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'); //$NON-NLS-1$
		remote_stop_all.setAccelerator(KeyStrokes.REMOTE_STOP_ALL);
		remote_stop_all.addActionListener(ActionRouter.getInstance());
		remote_stop_all.setActionCommand(ActionNames.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")); //$NON-NLS-1$
		remote_exit_all.addActionListener(ActionRouter.getInstance());
		remote_exit_all.setActionCommand(ActionNames.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")); //$NON-NLS-1$
        editMenu.setMnemonic('E');
		// 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")); //$NON-NLS-1$
		fileMenu.setMnemonic('F');
		JMenuItem file_save = new JMenuItem(JMeterUtils.getResString("save"), 'S'); //$NON-NLS-1$
		file_save.setAccelerator(KeyStrokes.SAVE);
		file_save.setActionCommand(ActionNames.SAVE);
		file_save.addActionListener(ActionRouter.getInstance());
		file_save.setEnabled(true);

		file_save_as = new JMenuItem(JMeterUtils.getResString("save_all_as"), 'A'); //$NON-NLS-1$
		file_save_as.setAccelerator(KeyStrokes.SAVE_ALL_AS);
		file_save_as.setActionCommand(ActionNames.SAVE_ALL_AS);
		file_save_as.addActionListener(ActionRouter.getInstance());
		file_save_as.setEnabled(true);

		file_selection_as = new JMenuItem(JMeterUtils.getResString("save_as")); //$NON-NLS-1$
		file_selection_as.setActionCommand(ActionNames.SAVE_AS);
		file_selection_as.addActionListener(ActionRouter.getInstance());
		file_selection_as.setEnabled(true);

		file_revert = new JMenuItem(JMeterUtils.getResString("revert_project"), 'R'); //$NON-NLS-1$
		file_revert.setActionCommand(ActionNames.REVERT_PROJECT);
		file_revert.addActionListener(ActionRouter.getInstance());
		file_revert.setEnabled(false);

		file_load = new JMenuItem(JMeterUtils.getResString("menu_open"), 'O'); //$NON-NLS-1$
		file_load.setAccelerator(KeyStrokes.OPEN);
		file_load.addActionListener(ActionRouter.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(ActionNames.OPEN);

		file_close = new JMenuItem(JMeterUtils.getResString("menu_close"), 'C'); //$NON-NLS-1$
		file_close.setAccelerator(KeyStrokes.CLOSE);
		file_close.setActionCommand(ActionNames.CLOSE);
		file_close.addActionListener(ActionRouter.getInstance());

		file_exit = new JMenuItem(JMeterUtils.getResString("exit"), 'X'); //$NON-NLS-1$
		file_exit.setAccelerator(KeyStrokes.EXIT);
		file_exit.setActionCommand(ActionNames.EXIT);
		file_exit.addActionListener(ActionRouter.getInstance());

		file_merge = new JMenuItem(JMeterUtils.getResString("menu_merge"), 'M'); //$NON-NLS-1$
		// file_merge.setAccelerator(
		// KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
		file_merge.addActionListener(ActionRouter.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(ActionNames.MERGE);

		fileMenu.add(file_close);
		fileMenu.add(file_load);
		fileMenu.add(file_merge);
        fileMenu.addSeparator();
		fileMenu.add(file_save);
		fileMenu.add(file_save_as);
		fileMenu.add(file_selection_as);
        fileMenu.add(file_revert);
        fileMenu.addSeparator();
        // Add the recent files, which will also add a separator that is
        // visible when needed
        file_load_recent_files = LoadRecentProject.getRecentFileMenuItems();
        for(Iterator i = file_load_recent_files.iterator(); i.hasNext();) {
            fileMenu.add((JComponent)i.next());
        }
        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.debug("Found start host: " + start.getText());
				start.setEnabled(!running);
			}
			if (stop.getText().equals(host)) {
				log.debug("Found stop  host: " + stop.getText());
				stop.setEnabled(running);
			}
			if (exit.getText().equals(host)) {
				log.debug("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")); //$NON-NLS-1$
			remote_stop = new JMenu(JMeterUtils.getResString("remote_stop")); //$NON-NLS-1$
			remote_exit = new JMenu(JMeterUtils.getResString("remote_exit")); //$NON-NLS-1$

			for (int i = 0; i < remoteHosts.length; i++) {
				remoteHosts[i] = remoteHosts[i].trim();
				JMenuItem item = new JMenuItem(remoteHosts[i]);
				item.setActionCommand(ActionNames.REMOTE_START);
				item.setName(remoteHosts[i]);
				item.addActionListener(ActionRouter.getInstance());
				remote_engine_start.add(item);
				remote_start.add(item);
				item = new JMenuItem(remoteHosts[i]);
				item.setActionCommand(ActionNames.REMOTE_STOP);
				item.setName(remoteHosts[i]);
				item.addActionListener(ActionRouter.getInstance());
				item.setEnabled(false);
				remote_engine_stop.add(item);
				remote_stop.add(item);
				item = new JMenuItem(remoteHosts[i]);
				item.setActionCommand(ActionNames.REMOTE_EXIT);
				item.setName(remoteHosts[i]);
				item.addActionListener(ActionRouter.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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -