jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1817428 - in /jmeter/trunk: src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java src/core/org/apache/jmeter/gui/util/MenuFactory.java xdocs/changes.xml
Date Thu, 07 Dec 2017 21:41:20 GMT
Author: pmouawad
Date: Thu Dec  7 21:41:19 2017
New Revision: 1817428

URL: http://svn.apache.org/viewvc?rev=1817428&view=rev
Log:
Menu bar - added mnemonics to more menu items 
Contributed by Graham Russell
This closes #352

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/util/MenuFactory.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java?rev=1817428&r1=1817427&r2=1817428&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java Thu Dec  7 21:41:19
2017
@@ -23,6 +23,7 @@ import java.awt.event.KeyEvent;
 import java.io.IOException;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -63,93 +64,36 @@ public class JMeterMenuBar extends JMenu
     private static final Logger log = LoggerFactory.getLogger(JMeterMenuBar.class);
 
     private JMenu fileMenu;
-
     private JMenuItem fileSaveAs;
-
-    private JMenuItem fileSelectionAs;
-
-    private JMenuItem fileSelectionAsTestFragment;
-
     private JMenuItem fileRevert;
-
     private JMenuItem fileLoad;
-    
     private JMenu recentFilesOpen;
-
-    private JMenuItem templates;
-
     private List<JComponent> fileLoadRecentFiles;
-
     private JMenuItem fileMerge;
-
-    private JMenuItem fileExit;
-
-    private JMenuItem fileNew;
-
     private JMenu editMenu;
-
     private JMenu editAdd;
-
     private JMenu runMenu;
-
     private JMenuItem runStart;
-
     private JMenuItem runStartNoTimers;
-
     private JMenu remoteStart;
-
-    private JMenuItem remoteStartAll;
-
     private Collection<JMenuItem> remoteEngineStart;
-
     private JMenuItem runStop;
-
     private JMenuItem runShut;
-
     private JMenu remoteStop;
-
     private JMenu remoteShut;
-
-    private JMenuItem remoteStopAll;
-
-    private JMenuItem remoteShutAll;
-
     private Collection<JMenuItem> remoteEngineStop;
-
     private Collection<JMenuItem> remoteEngineShut;
-
-    private JMenuItem runClear;
-
-    private JMenuItem runClearAll;
-
     private JMenu optionsMenu;
-
-    private JMenu lafMenu;
-
-    private JMenuItem sslManager;
-
     private JMenu helpMenu;
-
-    private JMenuItem helpAbout;
-
     private String[] remoteHosts;
-
     private JMenu remoteExit;
-
-    private JMenuItem remoteExitAll;
-
     private Collection<JMenuItem> remoteEngineExit;
-
     private JMenu searchMenu;
-
-    private ArrayList<MenuCreator> menuCreators;
+    private List<MenuCreator> menuCreators;
 
     public static final String SYSTEM_LAF = "System"; // $NON-NLS-1$
-
     public static final String CROSS_PLATFORM_LAF = "CrossPlatform"; // $NON-NLS-1$
-
     public static final String DARCULA_LAF = "Darcula"; // $NON-NLS-1$
-
     public static final String DARCULA_LAF_CLASS = "com.bulenkov.darcula.DarculaLaf"; //
$NON-NLS-1$
     
     public JMeterMenuBar() {
@@ -170,7 +114,7 @@ public class JMeterMenuBar extends JMenu
     }
 
     public void setFileSaveEnabled(boolean enabled) {
-        if(fileSaveAs != null) {
+        if (fileSaveAs != null) {
             fileSaveAs.setEnabled(enabled);
         }
     }
@@ -185,13 +129,13 @@ public class JMeterMenuBar extends JMenu
     }
 
     public void setFileRevertEnabled(boolean enabled) {
-        if(fileRevert != null) {
+        if (fileRevert != null) {
             fileRevert.setEnabled(enabled);
         }
     }
 
     public void setProjectFileLoaded(String file) {
-        if(fileLoadRecentFiles != null && file != null) {
+        if (fileLoadRecentFiles != null && file != null) {
             LoadRecentProject.updateRecentFileMenuItems(fileLoadRecentFiles, file);
             recentFilesOpen.setEnabled(true);
         }
@@ -218,8 +162,7 @@ public class JMeterMenuBar extends JMenu
     public void setEditMenu(JPopupMenu menu) {
         if (menu != null) {
             editMenu.removeAll();
-            Component[] comps = menu.getComponents();
-            for (Component comp : comps) {
+            for (Component comp : menu.getComponents()) {
                 editMenu.add(comp);
             }
             editMenu.setEnabled(true);
@@ -244,7 +187,31 @@ public class JMeterMenuBar extends JMenu
      * should be defined in a file somewhere, but that is for later.
      */
     public void createMenuBar() {
-        this.menuCreators = new ArrayList<>();
+
+        this.menuCreators = findMenuCreators();
+
+        makeFileMenu();
+        makeEditMenu();
+        makeRunMenu();
+        makeSearchMenu();
+        makeOptionsMenu();
+        makeHelpMenu();
+        this.add(fileMenu);
+        this.add(editMenu);
+        this.add(searchMenu);
+        this.add(runMenu);
+        this.add(optionsMenu);
+
+        menuCreators.stream()
+                .map(MenuCreator::getTopLevelMenus)
+                .flatMap(Arrays::stream)
+                .forEachOrdered(this::add);
+
+        this.add(helpMenu);
+    }
+
+    private List<MenuCreator> findMenuCreators() {
+        List<MenuCreator> creators = new ArrayList<>();
         try {
             List<String> listClasses = ClassFinder.findClassesThatExtend(
                     JMeterUtils.getSearchPaths(),
@@ -256,7 +223,7 @@ public class JMeterMenuBar extends JMenu
                     if (!Modifier.isAbstract(commandClass.getModifiers())) {
                         log.debug("Instantiating: {}", commandClass);
                         MenuCreator creator = (MenuCreator) commandClass.newInstance();
-                        menuCreators.add(creator);
+                        creators.add(creator);
                     }
                 } catch (Exception e) {
                     log.error("Exception registering {} with implementation: {}", MenuCreator.class,
strClassName, e);
@@ -265,50 +232,24 @@ public class JMeterMenuBar extends JMenu
         } catch (IOException e) {
             log.error("Exception finding implementations of {}", MenuCreator.class, e);
         }
-
-        makeFileMenu();
-        makeEditMenu();
-        makeRunMenu();
-        makeOptionsMenu();
-        makeHelpMenu();
-        makeSearchMenu();
-        this.add(fileMenu);
-        this.add(editMenu);
-        this.add(searchMenu);
-        this.add(runMenu);
-        this.add(optionsMenu);
-        for (MenuCreator menuCreator : menuCreators) {
-            JMenu[] topLevelMenus = menuCreator.getTopLevelMenus();
-            for (JMenu topLevelMenu : topLevelMenus) {
-                this.add(topLevelMenu);
-            }
-        }
-        this.add(helpMenu);
+        return creators;
     }
 
     private void makeHelpMenu() {
-        // HELP MENU
         helpMenu = makeMenuRes("help",'H'); //$NON-NLS-1$
 
         JMenuItem contextHelp = makeMenuItemRes("help", 'H', ActionNames.HELP, KeyStrokes.HELP);
//$NON-NLS-1$
-
         JMenuItem whatClass = makeMenuItemRes("help_node", 'W', ActionNames.WHAT_CLASS, KeyStrokes.WHAT_CLASS);//$NON-NLS-1$
-
         JMenuItem setDebug = makeMenuItemRes("debug_on", ActionNames.DEBUG_ON, KeyStrokes.DEBUG_ON);//$NON-NLS-1$
-
         JMenuItem resetDebug = makeMenuItemRes("debug_off", ActionNames.DEBUG_OFF, KeyStrokes.DEBUG_OFF);//$NON-NLS-1$
-
         JMenuItem heapDump = makeMenuItemRes("heap_dump", ActionNames.HEAP_DUMP);//$NON-NLS-1$
-
         JMenuItem threadDump = makeMenuItemRes("thread_dump", ActionNames.THREAD_DUMP);//$NON-NLS-1$
         
         JMenu usefulLinks = makeMenuRes("useful_links");//$NON-NLS-1$
-        JMenuItem subMenuLinkBugTraker = makeMenuItemRes("link_bug_tracker", ActionNames.LINK_BUG_TRACKER);//$NON-NLS-1$
-        usefulLinks.add(subMenuLinkBugTraker);
-        JMenuItem subMenuLinkNightlyBuild = makeMenuItemRes("link_nightly_build", ActionNames.LINK_NIGHTLY_BUILD);//$NON-NLS-1$
-        usefulLinks.add(subMenuLinkNightlyBuild);
+        usefulLinks.add(makeMenuItemRes("link_bug_tracker", ActionNames.LINK_BUG_TRACKER));
+        usefulLinks.add(makeMenuItemRes("link_nightly_build", ActionNames.LINK_NIGHTLY_BUILD));
 
-        helpAbout = makeMenuItemRes("about", 'A', ActionNames.ABOUT); //$NON-NLS-1$
+        JMenuItem helpAbout = makeMenuItemRes("about", 'A', ActionNames.ABOUT);
 
         helpMenu.add(contextHelp);
         helpMenu.addSeparator();
@@ -327,20 +268,9 @@ public class JMeterMenuBar extends JMenu
     }
 
     private void makeOptionsMenu() {
-        // OPTIONS MENU
         optionsMenu = makeMenuRes("option",'O'); //$NON-NLS-1$
-        JMenuItem functionHelper = makeMenuItemRes("function_dialog_menu_item", 'F', ActionNames.FUNCTIONS,
KeyStrokes.FUNCTIONS); //$NON-NLS-1$
-
-        lafMenu = makeMenuRes("appearance",'L'); //$NON-NLS-1$
-        for (LookAndFeelInfo laf : getAllLAFs()) {
-            JMenuItem menuItem = new JMenuItem(laf.getName());
-            menuItem.addActionListener(ActionRouter.getInstance());
-            menuItem.setActionCommand(ActionNames.LAF_PREFIX + laf.getClassName());
-            menuItem.setToolTipText(laf.getClassName()); // show the classname to the user
-            lafMenu.add(menuItem);
-        }
-        optionsMenu.add(functionHelper);
-        optionsMenu.add(lafMenu);
+        optionsMenu.add(makeMenuItemRes("function_dialog_menu_item", 'F', ActionNames.FUNCTIONS,
KeyStrokes.FUNCTIONS));
+        optionsMenu.add(createLaFMenu());
 
         JCheckBoxMenuItem menuLoggerPanel = makeCheckBoxMenuItemRes("menu_logger_panel",
ActionNames.LOGGER_PANEL_ENABLE_DISABLE); //$NON-NLS-1$
         GuiPackage guiInstance = GuiPackage.getInstance();
@@ -363,21 +293,14 @@ public class JMeterMenuBar extends JMenu
         optionsMenu.add(menuLoggerLevel);
 
         if (SSLManager.isSSLSupported()) {
-            sslManager = makeMenuItemRes("sslmanager", 'S', ActionNames.SSL_MANAGER, KeyStrokes.SSL_MANAGER);
//$NON-NLS-1$
-            optionsMenu.add(sslManager);
+            optionsMenu.add(makeMenuItemRes("sslmanager", 'S', ActionNames.SSL_MANAGER, KeyStrokes.SSL_MANAGER));
         }
         optionsMenu.add(makeLanguageMenu());
 
-        JMenuItem collapse = makeMenuItemRes("menu_collapse_all", ActionNames.COLLAPSE_ALL,
KeyStrokes.COLLAPSE_ALL); //$NON-NLS-1$
-        optionsMenu.add(collapse);
-
-        JMenuItem expand = makeMenuItemRes("menu_expand_all", ActionNames.EXPAND_ALL, KeyStrokes.EXPAND_ALL);
//$NON-NLS-1$
-        optionsMenu.add(expand);
-
-        JMenuItem zoomIn = makeMenuItemRes("menu_zoom_in", ActionNames.ZOOM_IN); //$NON-NLS-1$
-        optionsMenu.add(zoomIn);
-        JMenuItem zoomOut = makeMenuItemRes("menu_zoom_out", ActionNames.ZOOM_OUT); //$NON-NLS-1$
-        optionsMenu.add(zoomOut);        
+        optionsMenu.add(makeMenuItemRes("menu_collapse_all", 'A', ActionNames.COLLAPSE_ALL,
KeyStrokes.COLLAPSE_ALL));
+        optionsMenu.add(makeMenuItemRes("menu_expand_all", 'X', ActionNames.EXPAND_ALL, KeyStrokes.EXPAND_ALL));
+        optionsMenu.add(makeMenuItemRes("menu_zoom_in", 'I', ActionNames.ZOOM_IN));
+        optionsMenu.add(makeMenuItemRes("menu_zoom_out", 'U', ActionNames.ZOOM_OUT));
         JCheckBoxMenuItem saveBeforeRun = makeCheckBoxMenuItemRes("menu_save_before_run",
ActionNames.SAVE_BEFORE_RUN); //$NON-NLS-1$
         if (guiInstance != null) {
             saveBeforeRun.setSelected(guiInstance.shouldSaveBeforeRunByPreference());
@@ -388,6 +311,18 @@ public class JMeterMenuBar extends JMenu
         addPluginsMenuItems(optionsMenu, menuCreators, MENU_LOCATION.OPTIONS);
     }
 
+    private JMenu createLaFMenu() {
+        JMenu lafMenu = makeMenuRes("appearance", 'L');
+        for (LookAndFeelInfo laf : getAllLAFs()) {
+            JMenuItem menuItem = new JMenuItem(laf.getName());
+            menuItem.addActionListener(ActionRouter.getInstance());
+            menuItem.setActionCommand(ActionNames.LAF_PREFIX + laf.getClassName());
+            menuItem.setToolTipText(laf.getClassName()); // show the classname to the user
+            lafMenu.add(menuItem);
+        }
+        return lafMenu;
+    }
+
     private static class LangMenuHelper{
         final ActionRouter actionRouter = ActionRouter.getInstance();
         final JMenu languageMenu;
@@ -409,13 +344,12 @@ public class JMeterMenuBar extends JMenu
             language.setName(locale); // This is used by the ChangeLanguage class to define
the Locale
             languageMenu.add(language);
         }
-
    }
 
     /**
      * Generate the list of supported languages.
      *
-     * @return list of languages
+     * @return array of language Strings
      */
     // Also used by org.apache.jmeter.resources.PackageTest
     public static String[] getLanguages(){
@@ -432,17 +366,15 @@ public class JMeterMenuBar extends JMenu
         lang.add(Locale.SIMPLIFIED_CHINESE.toString()); // zh_CN
         lang.add(Locale.TRADITIONAL_CHINESE.toString()); // zh_TW
         final String addedLocales = JMeterUtils.getProperty("locales.add");
-        if (addedLocales != null){
-            String [] addLanguages =addedLocales.split(","); // $NON-NLS-1$
-            for(String newLang : addLanguages){
-                log.info("Adding locale {}", newLang);
-                lang.add(newLang);
-            }
+        if (addedLocales != null) {
+            Arrays.stream(addedLocales.split(","))
+                    .peek(newLang -> log.info("Adding locale {}", newLang))
+                    .forEachOrdered(lang::add);
         }
         return lang.toArray(new String[lang.size()]);
     }
 
-    static JMenu makeLanguageMenu() {
+    private static JMenu makeLanguageMenu() {
         final JMenu languageMenu = makeMenuRes("choose_language",'C'); //$NON-NLS-1$
 
         LangMenuHelper langMenu = new LangMenuHelper(languageMenu);
@@ -454,19 +386,18 @@ public class JMeterMenuBar extends JMenu
          * Also, need to ensure that the names are valid resource entries too.
          */
 
-        for(String lang : getLanguages()){
+        for (String lang : getLanguages()) {
             langMenu.addLang(lang);
         }
         return languageMenu;
     }
 
     private void makeRunMenu() {
-        // RUN MENU
         runMenu = makeMenuRes("run",'R'); //$NON-NLS-1$
 
         runStart = makeMenuItemRes("start", 'S', ActionNames.ACTION_START, KeyStrokes.ACTION_START);
//$NON-NLS-1$
 
-        runStartNoTimers = makeMenuItemRes("start_no_timers", ActionNames.ACTION_START_NO_TIMERS);
//$NON-NLS-1$
+        runStartNoTimers = makeMenuItemRes("start_no_timers", 'N', ActionNames.ACTION_START_NO_TIMERS);
//$NON-NLS-1$
         
         runStop = makeMenuItemRes("stop", 'T', ActionNames.ACTION_STOP, KeyStrokes.ACTION_STOP);
//$NON-NLS-1$
         runStop.setEnabled(false);
@@ -474,16 +405,16 @@ public class JMeterMenuBar extends JMenu
         runShut = makeMenuItemRes("shutdown", 'Y', ActionNames.ACTION_SHUTDOWN, KeyStrokes.ACTION_SHUTDOWN);
//$NON-NLS-1$
         runShut.setEnabled(false);
 
-        runClear = makeMenuItemRes("clear", 'C', ActionNames.CLEAR, KeyStrokes.CLEAR); //$NON-NLS-1$
+        JMenuItem runClear = makeMenuItemRes("clear", 'C', ActionNames.CLEAR, KeyStrokes.CLEAR);
 
-        runClearAll = makeMenuItemRes("clear_all", 'a', ActionNames.CLEAR_ALL, KeyStrokes.CLEAR_ALL);
//$NON-NLS-1$
+        JMenuItem runClearAll = makeMenuItemRes("clear_all", 'a', ActionNames.CLEAR_ALL,
KeyStrokes.CLEAR_ALL);
 
         runMenu.add(runStart);
         runMenu.add(runStartNoTimers);
         if (remoteStart != null) {
             runMenu.add(remoteStart);
         }
-        remoteStartAll = makeMenuItemRes("remote_start_all", ActionNames.REMOTE_START_ALL,
KeyStrokes.REMOTE_START_ALL); //$NON-NLS-1$
+        JMenuItem remoteStartAll = makeMenuItemRes("remote_start_all", ActionNames.REMOTE_START_ALL,
KeyStrokes.REMOTE_START_ALL);
 
         runMenu.add(remoteStartAll);
         runMenu.add(runStop);
@@ -491,19 +422,19 @@ public class JMeterMenuBar extends JMenu
         if (remoteStop != null) {
             runMenu.add(remoteStop);
         }
-        remoteStopAll = makeMenuItemRes("remote_stop_all", 'X', ActionNames.REMOTE_STOP_ALL,
KeyStrokes.REMOTE_STOP_ALL); //$NON-NLS-1$
+        JMenuItem remoteStopAll = makeMenuItemRes("remote_stop_all", 'X', ActionNames.REMOTE_STOP_ALL,
KeyStrokes.REMOTE_STOP_ALL);
         runMenu.add(remoteStopAll);
 
         if (remoteShut != null) {
             runMenu.add(remoteShut);
         }
-        remoteShutAll = makeMenuItemRes("remote_shut_all", 'X', ActionNames.REMOTE_SHUT_ALL,
KeyStrokes.REMOTE_SHUT_ALL); //$NON-NLS-1$
+        JMenuItem remoteShutAll = makeMenuItemRes("remote_shut_all", 'X', ActionNames.REMOTE_SHUT_ALL,
KeyStrokes.REMOTE_SHUT_ALL);
         runMenu.add(remoteShutAll);
 
         if (remoteExit != null) {
             runMenu.add(remoteExit);
         }
-        remoteExitAll = makeMenuItemRes("remote_exit_all", ActionNames.REMOTE_EXIT_ALL);
//$NON-NLS-1$
+        JMenuItem remoteExitAll = makeMenuItemRes("remote_exit_all", ActionNames.REMOTE_EXIT_ALL);
         runMenu.add(remoteExitAll);
 
         runMenu.addSeparator();
@@ -514,7 +445,6 @@ public class JMeterMenuBar extends JMenu
     }
 
     private void makeEditMenu() {
-        // EDIT MENU
         editMenu = makeMenuRes("edit",'E'); //$NON-NLS-1$
 
         // From the Java Look and Feel Guidelines: If all items in a menu
@@ -525,38 +455,36 @@ public class JMeterMenuBar extends JMenu
     }
 
     private void makeFileMenu() {
-        // FILE MENU
         fileMenu = makeMenuRes("file",'F'); //$NON-NLS-1$
 
         JMenuItem fileSave = makeMenuItemRes("save", 'S', ActionNames.SAVE, KeyStrokes.SAVE);
//$NON-NLS-1$
-        fileSave.setEnabled(true);
 
         fileSaveAs = makeMenuItemRes("save_all_as", 'A', ActionNames.SAVE_ALL_AS, KeyStrokes.SAVE_ALL_AS);
//$NON-NLS-1$
         fileSaveAs.setEnabled(true);
 
-        fileSelectionAs = makeMenuItemRes("save_as", ActionNames.SAVE_AS); //$NON-NLS-1$
-        fileSelectionAs.setEnabled(true);
+        JMenuItem fileSaveSelectionAs = makeMenuItemRes("save_as", 'L', ActionNames.SAVE_AS);
+        fileSaveSelectionAs.setEnabled(true);
 
-        fileSelectionAsTestFragment = makeMenuItemRes("save_as_test_fragment", ActionNames.SAVE_AS_TEST_FRAGMENT);
//$NON-NLS-1$
+        JMenuItem fileSelectionAsTestFragment = makeMenuItemRes("save_as_test_fragment",
'F', ActionNames.SAVE_AS_TEST_FRAGMENT);
         fileSelectionAsTestFragment.setEnabled(true);
 
         fileRevert = makeMenuItemRes("revert_project", 'R', ActionNames.REVERT_PROJECT);
//$NON-NLS-1$
         fileRevert.setEnabled(false);
 
         fileLoad = makeMenuItemRes("menu_open", 'O', ActionNames.OPEN, KeyStrokes.OPEN);
//$NON-NLS-1$
-
-        recentFilesOpen = makeMenuRes("menu_recent"); //$NON-NLS-1$
-        recentFilesOpen.setEnabled(false);
         // Set default SAVE menu item to disabled since the default node that
         // is selected is ROOT, which does not allow items to be inserted.
         fileLoad.setEnabled(false);
 
-        templates = makeMenuItemRes("template_menu", 'T', ActionNames.TEMPLATES); //$NON-NLS-1$
+        recentFilesOpen = makeMenuRes("menu_recent", 'E'); //$NON-NLS-1$
+        recentFilesOpen.setEnabled(false);
+
+        JMenuItem templates = makeMenuItemRes("template_menu", 'T', ActionNames.TEMPLATES);
         templates.setEnabled(true);
 
-        fileNew = makeMenuItemRes("new", 'N', ActionNames.CLOSE, KeyStrokes.CLOSE); //$NON-NLS-1$
+        JMenuItem fileNew = makeMenuItemRes("new", 'N', ActionNames.CLOSE, KeyStrokes.CLOSE);
 
-        fileExit = makeMenuItemRes("exit", 'X', ActionNames.EXIT, KeyStrokes.EXIT); //$NON-NLS-1$
+        JMenuItem fileExit = makeMenuItemRes("exit", 'X', ActionNames.EXIT, KeyStrokes.EXIT);
 
         fileMerge = makeMenuItemRes("menu_merge", 'M', ActionNames.MERGE); //$NON-NLS-1$
         fileMerge.setEnabled(false);
@@ -569,16 +497,14 @@ public class JMeterMenuBar extends JMenu
         fileMenu.addSeparator();
         fileMenu.add(fileSave);
         fileMenu.add(fileSaveAs);
-        fileMenu.add(fileSelectionAs);
+        fileMenu.add(fileSaveSelectionAs);
         fileMenu.add(fileSelectionAsTestFragment);
         fileMenu.add(fileRevert);
         fileMenu.addSeparator();
         // Add the recent files, which will also add a separator that is
         // visible when needed
         fileLoadRecentFiles = LoadRecentProject.getRecentFileMenuItems();
-        for(JComponent jc : fileLoadRecentFiles){
-            recentFilesOpen.add(jc);
-        }
+        fileLoadRecentFiles.forEach(jc -> recentFilesOpen.add(jc));
         recentFilesOpen.setEnabled(LoadRecentProject.hasVisibleMenuItem(fileLoadRecentFiles));
 
         addPluginsMenuItems(fileMenu, menuCreators, MENU_LOCATION.FILE);
@@ -587,14 +513,13 @@ public class JMeterMenuBar extends JMenu
     }
 
     private void makeSearchMenu() {
-        // Search MENU
-        searchMenu = makeMenuRes("menu_search"); //$NON-NLS-1$
+        searchMenu = makeMenuRes("menu_search", 'S'); //$NON-NLS-1$
 
         JMenuItem search = makeMenuItemRes("menu_search", 'F', ActionNames.SEARCH_TREE, KeyStrokes.SEARCH_TREE);
//$NON-NLS-1$
         searchMenu.add(search);
         search.setEnabled(true);
 
-        JMenuItem searchReset = makeMenuItemRes("menu_search_reset", ActionNames.SEARCH_RESET);
//$NON-NLS-1$
+        JMenuItem searchReset = makeMenuItemRes("menu_search_reset", 'R', ActionNames.SEARCH_RESET);
//$NON-NLS-1$
         searchMenu.add(searchReset);
         searchReset.setEnabled(true);
 
@@ -602,27 +527,26 @@ public class JMeterMenuBar extends JMenu
     }
 
     /**
-     * @param menu
+     * Mutate the given menu by, for each menuCreator adding a separator
+     * followed by each of its menus based upon the menu location.
+     *
+     * @param menu the menu to mutate
      * @param menuCreators
      * @param location
      */
     private void addPluginsMenuItems(JMenu menu, List<MenuCreator> menuCreators, MENU_LOCATION
location) {
-        boolean addedSeparator = false;
         for (MenuCreator menuCreator : menuCreators) {
             JMenuItem[] menuItems = menuCreator.getMenuItemsAtLocation(location);
-            for (JMenuItem jMenuItem : menuItems) {
-                if(!addedSeparator) {
-                    menu.addSeparator();
-                    addedSeparator = true;
-                }
-                menu.add(jMenuItem);
+            if (menuItems.length != 0) {
+                menu.addSeparator();
             }
+            Arrays.stream(menuItems).forEachOrdered(menu::add);
         }
     }
     
     public void setRunning(boolean running, String host) {
         log.info("setRunning({}, {})", running, host);
-        if(org.apache.jmeter.gui.MainFrame.LOCAL.equals(host)) {
+        if (org.apache.jmeter.gui.MainFrame.LOCAL.equals(host)) {
             return;
         }
         Iterator<JMenuItem> iter = remoteEngineStart.iterator();
@@ -731,6 +655,7 @@ public class JMeterMenuBar extends JMenu
         lafsAll[i]=new UIManager.LookAndFeelInfo(SYSTEM_LAF,UIManager.getSystemLookAndFeelClassName());
         return lafsAll;
     }
+
     /**
      * <p>Refreshes all texts in the menu and all submenus to a new locale.</p>
      *

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/MenuFactory.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/MenuFactory.java?rev=1817428&r1=1817427&r2=1817428&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/MenuFactory.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/MenuFactory.java Thu Dec  7 21:41:19
2017
@@ -213,7 +213,6 @@ public final class MenuFactory {
      */
     public static void addFileMenu(JPopupMenu menu, boolean addSaveTestFragmentMenu) {
         // the undo/redo as a standard goes first in Edit menus
-        // maybe there's better place for them in JMeter?
         if(UndoHistory.isEnabled()) {
             addUndoItems(menu);
         }
@@ -244,13 +243,8 @@ public final class MenuFactory {
         JMenuItem disabled = makeMenuItemRes("disable", ActionNames.DISABLE);// $NON-NLS-1$
         JMenuItem enabled = makeMenuItemRes("enable", ActionNames.ENABLE);// $NON-NLS-1$
         boolean isEnabled = GuiPackage.getInstance().getTreeListener().getCurrentNode().isEnabled();
-        if (isEnabled) {
-            disabled.setEnabled(true);
-            enabled.setEnabled(false);
-        } else {
-            disabled.setEnabled(false);
-            enabled.setEnabled(true);
-        }
+        disabled.setEnabled(isEnabled);
+        enabled.setEnabled(!isEnabled);
         menu.add(enabled);
         menu.add(disabled);
         JMenuItem toggle = makeMenuItemRes("toggle", ActionNames.TOGGLE, KeyStrokes.TOGGLE);//
$NON-NLS-1$

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1817428&r1=1817427&r2=1817428&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Thu Dec  7 21:41:19 2017
@@ -183,6 +183,7 @@ Summary
     <li><bug>61802</bug>Loop / ForEach Controller should expose a variable
for current iteration. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
     <li><pr>349</pr> Add i18n resouces(zh_CN). Contributed by Helly Guo
(https://github.com/hellyguo)</li>
     <li><pr>351</pr> Fixed about dialog position on first view. Contributed
by Graham Russell (graham at ham1.co.uk)</li>
+    <li><pr>352</pr> Menu bar - added mnemonics to more menu items. Contributed
by Graham Russell (graham at ham1.co.uk)</li>
 </ul>
 
 <ch_section>Non-functional changes</ch_section>



Mime
View raw message