001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.gui.util;
020:
021: import java.awt.Component;
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.LinkedList;
025: import java.util.List;
026: import java.util.Locale;
027:
028: import javax.swing.JComponent;
029: import javax.swing.JMenu;
030: import javax.swing.JMenuBar;
031: import javax.swing.JMenuItem;
032: import javax.swing.JPopupMenu;
033: import javax.swing.MenuElement;
034: import javax.swing.UIManager;
035:
036: import org.apache.jmeter.gui.action.ActionNames;
037: import org.apache.jmeter.gui.action.ActionRouter;
038: import org.apache.jmeter.gui.action.KeyStrokes;
039: import org.apache.jmeter.gui.action.LoadRecentProject;
040: import org.apache.jmeter.util.JMeterUtils;
041: import org.apache.jmeter.util.LocaleChangeEvent;
042: import org.apache.jmeter.util.LocaleChangeListener;
043: import org.apache.jmeter.util.SSLManager;
044: import org.apache.jorphan.util.JOrphanUtils;
045: import org.apache.jorphan.logging.LoggingManager;
046: import org.apache.log.Logger;
047:
048: public class JMeterMenuBar extends JMenuBar implements
049: LocaleChangeListener {
050: private static final Logger log = LoggingManager
051: .getLoggerForClass();
052:
053: private JMenu fileMenu;
054:
055: private JMenuItem file_save_as;
056:
057: private JMenuItem file_selection_as;
058:
059: private JMenuItem file_revert;
060:
061: private JMenuItem file_load;
062:
063: private List file_load_recent_files;
064:
065: private JMenuItem file_merge;
066:
067: private JMenuItem file_exit;
068:
069: private JMenuItem file_close;
070:
071: private JMenu editMenu;
072:
073: private JMenu edit_add;
074:
075: // JMenu edit_add_submenu;
076: private JMenuItem edit_remove; // TODO - should this be created?
077:
078: private JMenu runMenu;
079:
080: private JMenuItem run_start;
081:
082: private JMenu remote_start;
083:
084: private JMenuItem remote_start_all;
085:
086: private Collection remote_engine_start;
087:
088: private JMenuItem run_stop;
089:
090: private JMenuItem run_shut;
091:
092: private JMenu remote_stop;
093:
094: private JMenuItem remote_stop_all;
095:
096: private Collection remote_engine_stop;
097:
098: private JMenuItem run_clear;
099:
100: private JMenuItem run_clearAll;
101:
102: // JMenu reportMenu;
103: // JMenuItem analyze;
104: private JMenu optionsMenu;
105:
106: private JMenu lafMenu;
107:
108: private JMenuItem sslManager;
109:
110: private JMenu helpMenu;
111:
112: private JMenuItem help_about;
113:
114: private String[] remoteHosts;
115:
116: private JMenu remote_exit;
117:
118: private JMenuItem remote_exit_all;
119:
120: private Collection remote_engine_exit;
121:
122: public JMeterMenuBar() {
123: // List for recent files menu items
124: file_load_recent_files = new LinkedList();
125: // Lists for remote engines menu items
126: remote_engine_start = new LinkedList();
127: remote_engine_stop = new LinkedList();
128: remote_engine_exit = new LinkedList();
129: remoteHosts = JOrphanUtils.split(JMeterUtils.getPropDefault(
130: "remote_hosts", ""), ","); //$NON-NLS-1$
131: if (remoteHosts.length == 1 && remoteHosts[0].equals("")) {
132: remoteHosts = new String[0];
133: }
134: this .getRemoteItems();
135: createMenuBar();
136: }
137:
138: public void setFileSaveEnabled(boolean enabled) {
139: if (file_save_as != null) {
140: file_save_as.setEnabled(enabled);
141: }
142: }
143:
144: public void setFileLoadEnabled(boolean enabled) {
145: if (file_load != null) {
146: file_load.setEnabled(enabled);
147: }
148: if (file_merge != null) {
149: file_merge.setEnabled(enabled);
150: }
151: }
152:
153: public void setFileRevertEnabled(boolean enabled) {
154: if (file_revert != null) {
155: file_revert.setEnabled(enabled);
156: }
157: }
158:
159: public void setProjectFileLoaded(String file) {
160: if (file_load_recent_files != null && file != null) {
161: LoadRecentProject.updateRecentFileMenuItems(
162: file_load_recent_files, file);
163: }
164: }
165:
166: public void setEditEnabled(boolean enabled) {
167: if (editMenu != null) {
168: editMenu.setEnabled(enabled);
169: }
170: }
171:
172: public void setEditAddMenu(JMenu menu) {
173: // If the Add menu already exists, remove it.
174: if (edit_add != null) {
175: editMenu.remove(edit_add);
176: }
177: // Insert the Add menu as the first menu item in the Edit menu.
178: edit_add = menu;
179: editMenu.insert(edit_add, 0);
180: }
181:
182: public void setEditMenu(JPopupMenu menu) {
183: if (menu != null) {
184: editMenu.removeAll();
185: Component[] comps = menu.getComponents();
186: for (int i = 0; i < comps.length; i++) {
187: editMenu.add(comps[i]);
188: }
189: editMenu.setEnabled(true);
190: } else {
191: editMenu.setEnabled(false);
192: }
193: }
194:
195: public void setEditAddEnabled(boolean enabled) {
196: // There was a NPE being thrown without the null check here.. JKB
197: if (edit_add != null) {
198: edit_add.setEnabled(enabled);
199: }
200: // If we are enabling the Edit-->Add menu item, then we also need to
201: // enable the Edit menu. The Edit menu may already be enabled, but
202: // there's no harm it trying to enable it again.
203: if (enabled) {
204: setEditEnabled(true);
205: } else {
206: // If we are disabling the Edit-->Add menu item and the
207: // Edit-->Remove menu item is disabled, then we also need to
208: // disable the Edit menu.
209: // The Java Look and Feel Guidelines say to disable a menu if all
210: // menu items are disabled.
211: if (!edit_remove.isEnabled()) {
212: editMenu.setEnabled(false);
213: }
214: }
215: }
216:
217: public void setEditRemoveEnabled(boolean enabled) {
218: edit_remove.setEnabled(enabled);
219: // If we are enabling the Edit-->Remove menu item, then we also need to
220: // enable the Edit menu. The Edit menu may already be enabled, but
221: // there's no harm it trying to enable it again.
222: if (enabled) {
223: setEditEnabled(true);
224: } else {
225: // If we are disabling the Edit-->Remove menu item and the
226: // Edit-->Add menu item is disabled, then we also need to disable
227: // the Edit menu.
228: // The Java Look and Feel Guidelines say to disable a menu if all
229: // menu items are disabled.
230: if (!edit_add.isEnabled()) {
231: editMenu.setEnabled(false);
232: }
233: }
234: }
235:
236: /**
237: * Creates the MenuBar for this application. I believe in my heart that this
238: * should be defined in a file somewhere, but that is for later.
239: */
240: public void createMenuBar() {
241: makeFileMenu();
242: makeEditMenu();
243: makeRunMenu();
244: makeOptionsMenu();
245: makeHelpMenu();
246: this .add(fileMenu);
247: this .add(editMenu);
248: this .add(runMenu);
249: this .add(optionsMenu);
250: this .add(helpMenu);
251: }
252:
253: private void makeHelpMenu() {
254: // HELP MENU
255: helpMenu = new JMenu(JMeterUtils.getResString("help")); //$NON-NLS-1$
256: helpMenu.setMnemonic('H');
257: JMenuItem contextHelp = new JMenuItem(JMeterUtils
258: .getResString("help"), 'H'); //$NON-NLS-1$
259: contextHelp.setActionCommand(ActionNames.HELP);
260: contextHelp.setAccelerator(KeyStrokes.HELP);
261: contextHelp.addActionListener(ActionRouter.getInstance());
262:
263: JMenuItem whatClass = new JMenuItem(JMeterUtils
264: .getResString("help_node"), 'W');//$NON-NLS-1$
265: whatClass.setActionCommand(ActionNames.WHAT_CLASS);
266: whatClass.setAccelerator(KeyStrokes.WHAT_CLASS);
267: whatClass.addActionListener(ActionRouter.getInstance());
268:
269: JMenuItem setDebug = new JMenuItem(JMeterUtils
270: .getResString("debug_on"));//$NON-NLS-1$
271: setDebug.setActionCommand(ActionNames.DEBUG_ON);
272: setDebug.setAccelerator(KeyStrokes.DEBUG_ON);
273: setDebug.addActionListener(ActionRouter.getInstance());
274:
275: JMenuItem resetDebug = new JMenuItem(JMeterUtils
276: .getResString("debug_off"));//$NON-NLS-1$
277: resetDebug.setActionCommand(ActionNames.DEBUG_OFF);
278: resetDebug.setAccelerator(KeyStrokes.DEBUG_OFF);
279: resetDebug.addActionListener(ActionRouter.getInstance());
280:
281: help_about = new JMenuItem(
282: JMeterUtils.getResString("about"), 'A'); //$NON-NLS-1$
283: help_about.setActionCommand(ActionNames.ABOUT);
284: help_about.addActionListener(ActionRouter.getInstance());
285: helpMenu.add(contextHelp);
286: helpMenu.addSeparator();
287: helpMenu.add(whatClass);
288: helpMenu.add(setDebug);
289: helpMenu.add(resetDebug);
290: helpMenu.addSeparator();
291: helpMenu.add(help_about);
292: }
293:
294: private void makeOptionsMenu() {
295: // OPTIONS MENU
296: optionsMenu = new JMenu(JMeterUtils.getResString("option")); //$NON-NLS-1$
297: JMenuItem functionHelper = new JMenuItem(JMeterUtils
298: .getResString("function_dialog_menu_item"), 'F'); //$NON-NLS-1$
299: functionHelper.addActionListener(ActionRouter.getInstance());
300: functionHelper.setActionCommand(ActionNames.FUNCTIONS);
301: functionHelper.setAccelerator(KeyStrokes.FUNCTIONS);
302: lafMenu = new JMenu(JMeterUtils.getResString("appearance")); //$NON-NLS-1$
303: UIManager.LookAndFeelInfo lafs[] = UIManager
304: .getInstalledLookAndFeels();
305: for (int i = 0; i < lafs.length; ++i) {
306: JMenuItem laf = new JMenuItem(lafs[i].getName());
307: laf.addActionListener(ActionRouter.getInstance());
308: laf.setActionCommand(ActionNames.LAF_PREFIX
309: + lafs[i].getClassName());
310: lafMenu.setMnemonic('L');
311: lafMenu.add(laf);
312: }
313: optionsMenu.setMnemonic('O');
314: optionsMenu.add(functionHelper);
315: optionsMenu.add(lafMenu);
316: if (SSLManager.isSSLSupported()) {
317: sslManager = new JMenuItem(JMeterUtils
318: .getResString("sslmanager")); //$NON-NLS-1$
319: sslManager.addActionListener(ActionRouter.getInstance());
320: sslManager.setActionCommand(ActionNames.SSL_MANAGER);
321: sslManager.setMnemonic('S');
322: sslManager.setAccelerator(KeyStrokes.SSL_MANAGER);
323: optionsMenu.add(sslManager);
324: }
325: optionsMenu.add(makeLanguageMenu());
326:
327: JMenuItem collapse = new JMenuItem(JMeterUtils
328: .getResString("menu_collapse_all")); //$NON-NLS-1$
329: collapse.addActionListener(ActionRouter.getInstance());
330: collapse.setActionCommand(ActionNames.COLLAPSE_ALL);
331: collapse.setAccelerator(KeyStrokes.COLLAPSE_ALL);
332: optionsMenu.add(collapse);
333:
334: JMenuItem expand = new JMenuItem(JMeterUtils
335: .getResString("menu_expand_all")); //$NON-NLS-1$
336: expand.addActionListener(ActionRouter.getInstance());
337: expand.setActionCommand(ActionNames.EXPAND_ALL);
338: expand.setAccelerator(KeyStrokes.EXPAND_ALL);
339: optionsMenu.add(expand);
340: }
341:
342: // TODO fetch list of languages from a file?
343: // N.B. Changes to language list need to be reflected in
344: // resources/PackageTest.java
345: private JMenu makeLanguageMenu() {
346: /*
347: * Note: the item name is used by ChangeLanguage to create a Locale for
348: * that language, so need to ensure that the language strings are valid
349: * If they exist, use the Locale language constants
350: */
351: // TODO: do accelerator keys make sense? The key may not be present in
352: // translations
353: JMenu languageMenu = new JMenu(JMeterUtils
354: .getResString("choose_language")); //$NON-NLS-1$
355: languageMenu.setMnemonic('C');
356: // add english
357: JMenuItem english = new JMenuItem(JMeterUtils
358: .getResString("en"), 'E'); //$NON-NLS-1$
359: english.addActionListener(ActionRouter.getInstance());
360: english.setActionCommand(ActionNames.CHANGE_LANGUAGE);
361: english.setName(Locale.ENGLISH.getLanguage());
362: languageMenu.add(english);
363: // add Japanese
364: JMenuItem japanese = new JMenuItem(JMeterUtils
365: .getResString("jp"), 'J'); //$NON-NLS-1$
366: japanese.addActionListener(ActionRouter.getInstance());
367: japanese.setActionCommand(ActionNames.CHANGE_LANGUAGE);
368: japanese.setName(Locale.JAPANESE.getLanguage());
369: languageMenu.add(japanese);
370: // add Norwegian
371: JMenuItem norway = new JMenuItem(
372: JMeterUtils.getResString("no"), 'N'); //$NON-NLS-1$
373: norway.addActionListener(ActionRouter.getInstance());
374: norway.setActionCommand(ActionNames.CHANGE_LANGUAGE);
375: norway.setName("no"); // No default for Norwegian
376: languageMenu.add(norway);
377: // add German
378: JMenuItem german = new JMenuItem(
379: JMeterUtils.getResString("de"), 'G'); //$NON-NLS-1$
380: german.addActionListener(ActionRouter.getInstance());
381: german.setActionCommand(ActionNames.CHANGE_LANGUAGE);
382: german.setName(Locale.GERMAN.getLanguage());
383: languageMenu.add(german);
384: // add French
385: JMenuItem french = new JMenuItem(
386: JMeterUtils.getResString("fr"), 'F'); //$NON-NLS-1$
387: french.addActionListener(ActionRouter.getInstance());
388: french.setActionCommand(ActionNames.CHANGE_LANGUAGE);
389: french.setName(Locale.FRENCH.getLanguage());
390: languageMenu.add(french);
391: // add chinese (simple)
392: JMenuItem chineseSimple = new JMenuItem(JMeterUtils
393: .getResString("zh_cn")); //$NON-NLS-1$
394: chineseSimple.addActionListener(ActionRouter.getInstance());
395: chineseSimple.setActionCommand(ActionNames.CHANGE_LANGUAGE);
396: chineseSimple.setName(Locale.SIMPLIFIED_CHINESE.toString());
397: languageMenu.add(chineseSimple);
398: // add chinese (traditional)
399: JMenuItem chineseTrad = new JMenuItem(JMeterUtils
400: .getResString("zh_tw")); //$NON-NLS-1$
401: chineseTrad.addActionListener(ActionRouter.getInstance());
402: chineseTrad.setActionCommand(ActionNames.CHANGE_LANGUAGE);
403: chineseTrad.setName(Locale.TRADITIONAL_CHINESE.toString());
404: languageMenu.add(chineseTrad);
405: // add spanish
406: JMenuItem spanish = new JMenuItem(JMeterUtils
407: .getResString("es")); //$NON-NLS-1$
408: spanish.addActionListener(ActionRouter.getInstance());
409: spanish.setActionCommand(ActionNames.CHANGE_LANGUAGE);
410: spanish.setName("es"); //$NON-NLS-1$
411: languageMenu.add(spanish);
412: return languageMenu;
413: }
414:
415: private void makeRunMenu() {
416: // RUN MENU
417: runMenu = new JMenu(JMeterUtils.getResString("run")); //$NON-NLS-1$
418: runMenu.setMnemonic('R');
419: run_start = new JMenuItem(
420: JMeterUtils.getResString("start"), 'S'); //$NON-NLS-1$
421: run_start.setAccelerator(KeyStrokes.ACTION_START);
422: run_start.addActionListener(ActionRouter.getInstance());
423: run_start.setActionCommand(ActionNames.ACTION_START);
424: run_stop = new JMenuItem(JMeterUtils.getResString("stop"), 'T'); //$NON-NLS-1$
425: run_stop.setAccelerator(KeyStrokes.ACTION_STOP);
426: run_stop.setEnabled(false);
427: run_stop.addActionListener(ActionRouter.getInstance());
428: run_stop.setActionCommand(ActionNames.ACTION_STOP);
429:
430: run_shut = new JMenuItem(
431: JMeterUtils.getResString("shutdown"), 'Y'); //$NON-NLS-1$
432: run_shut.setAccelerator(KeyStrokes.ACTION_SHUTDOWN);
433: run_shut.setEnabled(false);
434: run_shut.addActionListener(ActionRouter.getInstance());
435: run_shut.setActionCommand(ActionNames.ACTION_SHUTDOWN);
436:
437: run_clear = new JMenuItem(
438: JMeterUtils.getResString("clear"), 'C'); //$NON-NLS-1$
439: run_clear.addActionListener(ActionRouter.getInstance());
440: run_clear.setActionCommand(ActionNames.CLEAR);
441: run_clear.setAccelerator(KeyStrokes.CLEAR);
442:
443: run_clearAll = new JMenuItem(JMeterUtils
444: .getResString("clear_all"), 'a'); //$NON-NLS-1$
445: run_clearAll.addActionListener(ActionRouter.getInstance());
446: run_clearAll.setActionCommand(ActionNames.CLEAR_ALL);
447: run_clearAll.setAccelerator(KeyStrokes.CLEAR_ALL);
448:
449: runMenu.add(run_start);
450: if (remote_start != null) {
451: runMenu.add(remote_start);
452: }
453: remote_start_all = new JMenuItem(JMeterUtils
454: .getResString("remote_start_all")); //$NON-NLS-1$
455: remote_start_all.setName("remote_start_all"); //$NON-NLS-1$
456: remote_start_all.setAccelerator(KeyStrokes.REMOTE_START_ALL);
457: remote_start_all.addActionListener(ActionRouter.getInstance());
458: remote_start_all.setActionCommand(ActionNames.REMOTE_START_ALL);
459: runMenu.add(remote_start_all);
460: runMenu.add(run_stop);
461: runMenu.add(run_shut);
462: if (remote_stop != null) {
463: runMenu.add(remote_stop);
464: }
465: remote_stop_all = new JMenuItem(JMeterUtils
466: .getResString("remote_stop_all"), 'X'); //$NON-NLS-1$
467: remote_stop_all.setAccelerator(KeyStrokes.REMOTE_STOP_ALL);
468: remote_stop_all.addActionListener(ActionRouter.getInstance());
469: remote_stop_all.setActionCommand(ActionNames.REMOTE_STOP_ALL);
470: runMenu.add(remote_stop_all);
471:
472: if (remote_exit != null) {
473: runMenu.add(remote_exit);
474: }
475: remote_exit_all = new JMenuItem(JMeterUtils
476: .getResString("remote_exit_all")); //$NON-NLS-1$
477: remote_exit_all.addActionListener(ActionRouter.getInstance());
478: remote_exit_all.setActionCommand(ActionNames.REMOTE_EXIT_ALL);
479: runMenu.add(remote_exit_all);
480:
481: runMenu.addSeparator();
482: runMenu.add(run_clear);
483: runMenu.add(run_clearAll);
484: }
485:
486: private void makeEditMenu() {
487: // EDIT MENU
488: editMenu = new JMenu(JMeterUtils.getResString("edit")); //$NON-NLS-1$
489: editMenu.setMnemonic('E');
490: // From the Java Look and Feel Guidelines: If all items in a menu
491: // are disabled, then disable the menu. Makes sense.
492: editMenu.setEnabled(false);
493: }
494:
495: private void makeFileMenu() {
496: // FILE MENU
497: fileMenu = new JMenu(JMeterUtils.getResString("file")); //$NON-NLS-1$
498: fileMenu.setMnemonic('F');
499: JMenuItem file_save = new JMenuItem(JMeterUtils
500: .getResString("save"), 'S'); //$NON-NLS-1$
501: file_save.setAccelerator(KeyStrokes.SAVE);
502: file_save.setActionCommand(ActionNames.SAVE);
503: file_save.addActionListener(ActionRouter.getInstance());
504: file_save.setEnabled(true);
505:
506: file_save_as = new JMenuItem(JMeterUtils
507: .getResString("save_all_as"), 'A'); //$NON-NLS-1$
508: file_save_as.setAccelerator(KeyStrokes.SAVE_ALL_AS);
509: file_save_as.setActionCommand(ActionNames.SAVE_ALL_AS);
510: file_save_as.addActionListener(ActionRouter.getInstance());
511: file_save_as.setEnabled(true);
512:
513: file_selection_as = new JMenuItem(JMeterUtils
514: .getResString("save_as")); //$NON-NLS-1$
515: file_selection_as.setActionCommand(ActionNames.SAVE_AS);
516: file_selection_as.addActionListener(ActionRouter.getInstance());
517: file_selection_as.setEnabled(true);
518:
519: file_revert = new JMenuItem(JMeterUtils
520: .getResString("revert_project"), 'R'); //$NON-NLS-1$
521: file_revert.setActionCommand(ActionNames.REVERT_PROJECT);
522: file_revert.addActionListener(ActionRouter.getInstance());
523: file_revert.setEnabled(false);
524:
525: file_load = new JMenuItem(
526: JMeterUtils.getResString("menu_open"), 'O'); //$NON-NLS-1$
527: file_load.setAccelerator(KeyStrokes.OPEN);
528: file_load.addActionListener(ActionRouter.getInstance());
529: // Set default SAVE menu item to disabled since the default node that
530: // is selected is ROOT, which does not allow items to be inserted.
531: file_load.setEnabled(false);
532: file_load.setActionCommand(ActionNames.OPEN);
533:
534: file_close = new JMenuItem(JMeterUtils
535: .getResString("menu_close"), 'C'); //$NON-NLS-1$
536: file_close.setAccelerator(KeyStrokes.CLOSE);
537: file_close.setActionCommand(ActionNames.CLOSE);
538: file_close.addActionListener(ActionRouter.getInstance());
539:
540: file_exit = new JMenuItem(JMeterUtils.getResString("exit"), 'X'); //$NON-NLS-1$
541: file_exit.setAccelerator(KeyStrokes.EXIT);
542: file_exit.setActionCommand(ActionNames.EXIT);
543: file_exit.addActionListener(ActionRouter.getInstance());
544:
545: file_merge = new JMenuItem(JMeterUtils
546: .getResString("menu_merge"), 'M'); //$NON-NLS-1$
547: // file_merge.setAccelerator(
548: // KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
549: file_merge.addActionListener(ActionRouter.getInstance());
550: // Set default SAVE menu item to disabled since the default node that
551: // is selected is ROOT, which does not allow items to be inserted.
552: file_merge.setEnabled(false);
553: file_merge.setActionCommand(ActionNames.MERGE);
554:
555: fileMenu.add(file_close);
556: fileMenu.add(file_load);
557: fileMenu.add(file_merge);
558: fileMenu.addSeparator();
559: fileMenu.add(file_save);
560: fileMenu.add(file_save_as);
561: fileMenu.add(file_selection_as);
562: fileMenu.add(file_revert);
563: fileMenu.addSeparator();
564: // Add the recent files, which will also add a separator that is
565: // visible when needed
566: file_load_recent_files = LoadRecentProject
567: .getRecentFileMenuItems();
568: for (Iterator i = file_load_recent_files.iterator(); i
569: .hasNext();) {
570: fileMenu.add((JComponent) i.next());
571: }
572: fileMenu.add(file_exit);
573: }
574:
575: public void setRunning(boolean running, String host) {
576: log.info("setRunning(" + running + "," + host + ")");
577:
578: Iterator iter = remote_engine_start.iterator();
579: Iterator iter2 = remote_engine_stop.iterator();
580: Iterator iter3 = remote_engine_exit.iterator();
581: while (iter.hasNext() && iter2.hasNext() && iter3.hasNext()) {
582: JMenuItem start = (JMenuItem) iter.next();
583: JMenuItem stop = (JMenuItem) iter2.next();
584: JMenuItem exit = (JMenuItem) iter3.next();
585: if (start.getText().equals(host)) {
586: log.debug("Found start host: " + start.getText());
587: start.setEnabled(!running);
588: }
589: if (stop.getText().equals(host)) {
590: log.debug("Found stop host: " + stop.getText());
591: stop.setEnabled(running);
592: }
593: if (exit.getText().equals(host)) {
594: log.debug("Found exit host: " + exit.getText());
595: exit.setEnabled(true);
596: }
597: }
598: }
599:
600: public void setEnabled(boolean enable) {
601: run_start.setEnabled(!enable);
602: run_stop.setEnabled(enable);
603: run_shut.setEnabled(enable);
604: }
605:
606: private void getRemoteItems() {
607: if (remoteHosts.length > 0) {
608: remote_start = new JMenu(JMeterUtils
609: .getResString("remote_start")); //$NON-NLS-1$
610: remote_stop = new JMenu(JMeterUtils
611: .getResString("remote_stop")); //$NON-NLS-1$
612: remote_exit = new JMenu(JMeterUtils
613: .getResString("remote_exit")); //$NON-NLS-1$
614:
615: for (int i = 0; i < remoteHosts.length; i++) {
616: remoteHosts[i] = remoteHosts[i].trim();
617: JMenuItem item = new JMenuItem(remoteHosts[i]);
618: item.setActionCommand(ActionNames.REMOTE_START);
619: item.setName(remoteHosts[i]);
620: item.addActionListener(ActionRouter.getInstance());
621: remote_engine_start.add(item);
622: remote_start.add(item);
623: item = new JMenuItem(remoteHosts[i]);
624: item.setActionCommand(ActionNames.REMOTE_STOP);
625: item.setName(remoteHosts[i]);
626: item.addActionListener(ActionRouter.getInstance());
627: item.setEnabled(false);
628: remote_engine_stop.add(item);
629: remote_stop.add(item);
630: item = new JMenuItem(remoteHosts[i]);
631: item.setActionCommand(ActionNames.REMOTE_EXIT);
632: item.setName(remoteHosts[i]);
633: item.addActionListener(ActionRouter.getInstance());
634: item.setEnabled(false);
635: remote_engine_exit.add(item);
636: remote_exit.add(item);
637: }
638: }
639: }
640:
641: /**
642: * Processes a locale change notification. Changes the texts in all menus to
643: * the new language.
644: */
645: public void localeChanged(LocaleChangeEvent event) {
646: updateMenuElement(fileMenu);
647: updateMenuElement(editMenu);
648: updateMenuElement(runMenu);
649: updateMenuElement(optionsMenu);
650: updateMenuElement(helpMenu);
651: }
652:
653: /**
654: * Refreshes all texts in the menu and all submenus to a new locale.
655: */
656: private void updateMenuElement(MenuElement menu) {
657: Component component = menu.getComponent();
658:
659: if (component.getName() != null) {
660: if (component instanceof JMenu) {
661: ((JMenu) component).setText(JMeterUtils
662: .getResString(component.getName()));
663: } else {
664: ((JMenuItem) component).setText(JMeterUtils
665: .getResString(component.getName()));
666: }
667: }
668:
669: MenuElement[] subelements = menu.getSubElements();
670:
671: for (int i = 0; i < subelements.length; i++) {
672: updateMenuElement(subelements[i]);
673: }
674: }
675: }
|