Author: fschumacher
Date: Sun Oct 28 12:52:03 2018
New Revision: 1845021

URL: http://svn.apache.org/viewvc?rev=1845021&view=rev
Log:
Convert anonymous inner class to nested class

With the changes for the original bug report, the inner class
got too big, so refactor it out into a nested static class.

Some shortcuts are not working correctly on windows
Contributed by Michael Pavlov (michael.paulau at gmail.com)

Followup to r1845017
Bugzilla Id: 62336
Relates to #396 on github


Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java
URL: 
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java?rev=1845021&r1=1845020&r2=1845021&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java Sun Oct 28 
12:52:03 2018
@@ -678,57 +678,7 @@ public class MainFrame extends JFrame im
     }
 
     private void addQuickComponentHotkeys(JTree treevar) {
-        Action quickComponent = new AbstractAction("Quick Component") {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public void actionPerformed(ActionEvent actionEvent) {
-                String propname = "gui.quick_" + getCurrentKey(actionEvent);
-                String comp = JMeterUtils.getProperty(propname);
-                log.debug("Event {}: {}", propname, comp);
-
-                if (comp == null) {
-                    log.warn("No component set through property: {}", 
propname);
-                    return;
-                }
-
-                GuiPackage guiPackage = GuiPackage.getInstance();
-                try {
-                    guiPackage.updateCurrentNode();
-                    TestElement testElement = 
guiPackage.createTestElement(SaveService.aliasToClass(comp));
-                    JMeterTreeNode parentNode = guiPackage.getCurrentNode();
-                    while (!MenuFactory.canAddTo(parentNode, testElement)) {
-                        parentNode = (JMeterTreeNode) parentNode.getParent();
-                    }
-                    if (parentNode.getParent() == null) {
-                        log.debug("Cannot add element on very top level");
-                    } else {
-                        JMeterTreeNode node = 
guiPackage.getTreeModel().addComponent(testElement, parentNode);
-                        
guiPackage.getMainFrame().getTree().setSelectionPath(new 
TreePath(node.getPath()));
-                    }
-                } catch (Exception err) {
-                    log.warn("Failed to perform quick component add: {}", 
comp, err); // $NON-NLS-1$
-                }
-            }
-
-            /*
-             * Bug 62336: On Windows CTRL+6 doesn't give us an actionCommand, 
so
-             * we have to try harder and read the KeyEvent from the EventQueue
-             */
-            private String getCurrentKey(ActionEvent actionEvent) {
-                String actionCommand = actionEvent.getActionCommand();
-                if (actionCommand != null) {
-                    return actionCommand;
-                }
-                AWTEvent currentEvent = EventQueue.getCurrentEvent();
-                if (currentEvent instanceof KeyEvent) {
-                    KeyEvent keyEvent = (KeyEvent) currentEvent;
-                    return KeyEvent.getKeyText(keyEvent.getKeyCode());
-                }
-                log.debug("No keycode could be found for this actionEvent {}", 
actionEvent);
-                return "NONE";
-            }
-        };
+        Action quickComponent = new QuickComponent("Quick Component");
 
         InputMap inputMap = 
treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
         KeyStroke[] keyStrokes = new KeyStroke[]{KeyStrokes.CTRL_0,
@@ -750,6 +700,62 @@ public class MainFrame extends JFrame im
         return new JMeterCellRenderer();
     }
 
+    private static final class QuickComponent extends AbstractAction {
+        private static final long serialVersionUID = 1L;
+
+        private QuickComponent(String name) {
+            super(name);
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent actionEvent) {
+            String propname = "gui.quick_" + getCurrentKey(actionEvent);
+            String comp = JMeterUtils.getProperty(propname);
+            log.debug("Event {}: {}", propname, comp);
+
+            if (comp == null) {
+                log.warn("No component set through property: {}", propname);
+                return;
+            }
+
+            GuiPackage guiPackage = GuiPackage.getInstance();
+            try {
+                guiPackage.updateCurrentNode();
+                TestElement testElement = 
guiPackage.createTestElement(SaveService.aliasToClass(comp));
+                JMeterTreeNode parentNode = guiPackage.getCurrentNode();
+                while (!MenuFactory.canAddTo(parentNode, testElement)) {
+                    parentNode = (JMeterTreeNode) parentNode.getParent();
+                }
+                if (parentNode.getParent() == null) {
+                    log.debug("Cannot add element on very top level");
+                } else {
+                    JMeterTreeNode node = 
guiPackage.getTreeModel().addComponent(testElement, parentNode);
+                    guiPackage.getMainFrame().getTree().setSelectionPath(new 
TreePath(node.getPath()));
+                }
+            } catch (Exception err) {
+                log.warn("Failed to perform quick component add: {}", comp, 
err); // $NON-NLS-1$
+            }
+        }
+
+        /*
+         * Bug 62336: On Windows CTRL+6 doesn't give us an actionCommand, so
+         * we have to try harder and read the KeyEvent from the EventQueue
+         */
+        private String getCurrentKey(ActionEvent actionEvent) {
+            String actionCommand = actionEvent.getActionCommand();
+            if (actionCommand != null) {
+                return actionCommand;
+            }
+            AWTEvent currentEvent = EventQueue.getCurrentEvent();
+            if (currentEvent instanceof KeyEvent) {
+                KeyEvent keyEvent = (KeyEvent) currentEvent;
+                return KeyEvent.getKeyText(keyEvent.getKeyCode());
+            }
+            log.debug("No keycode could be found for this actionEvent {}", 
actionEvent);
+            return "NONE";
+        }
+    }
+
     /**
      * A window adapter used to detect when the main JMeter frame is being
      * closed.


Reply via email to