View | Details | Raw Unified | Return to bug 54784
Collapse All | Expand All

(-)a/src/core/org/apache/jmeter/gui/GuiPackage.java (-8 / +11 lines)
Lines 19-24 Link Here
19
package org.apache.jmeter.gui;
19
package org.apache.jmeter.gui;
20
20
21
import java.awt.Component;
21
import java.awt.Component;
22
import java.awt.Point;
22
import java.awt.event.MouseEvent;
23
import java.awt.event.MouseEvent;
23
import java.beans.Introspector;
24
import java.beans.Introspector;
24
import java.util.ArrayList;
25
import java.util.ArrayList;
Lines 151-157 public final class GuiPackage implements LocaleChangeListener, HistoryListener { Link Here
151
    public static GuiPackage getInstance() {
152
    public static GuiPackage getInstance() {
152
        return guiPack;
153
        return guiPack;
153
    }
154
    }
154
    
155
155
    /**
156
    /**
156
     * Register as listener of:
157
     * Register as listener of:
157
     * - UndoHistory
158
     * - UndoHistory
Lines 607-613 public final class GuiPackage implements LocaleChangeListener, HistoryListener { Link Here
607
     *            the popup menu to display
608
     *            the popup menu to display
608
     */
609
     */
609
    public void displayPopUp(MouseEvent e, JPopupMenu popup) {
610
    public void displayPopUp(MouseEvent e, JPopupMenu popup) {
610
        displayPopUp((Component) e.getSource(), e, popup);
611
        final Point point = new Point(e.getX(), e.getY());
612
        Component invoker = (Component) e.getSource();
613
        displayPopUp(invoker, point, popup);
611
    }
614
    }
612
615
613
    /**
616
    /**
Lines 616-632 public final class GuiPackage implements LocaleChangeListener, HistoryListener { Link Here
616
     *
619
     *
617
     * @param invoker
620
     * @param invoker
618
     *            the source component
621
     *            the source component
619
     * @param e
622
     * @param p
620
     *            the mouse event causing this popup to be displayed
623
     *            the point at which to display the popup
621
     * @param popup
624
     * @param popup
622
     *            the popup menu to display
625
     *            the popup menu to display
623
     */
626
     */
624
    public void displayPopUp(Component invoker, MouseEvent e, JPopupMenu popup) {
627
    public void displayPopUp(Component invoker, Point p, JPopupMenu popup) {
625
        if (popup != null) {
628
        if (popup != null) {
626
            log.debug("Showing pop up for " + invoker + " at x,y = " + e.getX() + "," + e.getY());
629
            log.debug("Showing pop up for " + invoker + " at x,y = " + p.x + "," + p.y);
627
630
628
            popup.pack();
631
            popup.pack();
629
            popup.show(invoker, e.getX(), e.getY());
632
            popup.show(invoker, p.x, p.y);
630
            popup.setVisible(true);
633
            popup.setVisible(true);
631
            popup.requestFocusInWindow();
634
            popup.requestFocusInWindow();
632
        }
635
        }
Lines 759-765 public final class GuiPackage implements LocaleChangeListener, HistoryListener { Link Here
759
762
760
    /**
763
    /**
761
     * Register process to stop on reload
764
     * Register process to stop on reload
762
     * 
765
     *
763
     * @param stoppable
766
     * @param stoppable
764
     *            The {@link Stoppable} to be registered
767
     *            The {@link Stoppable} to be registered
765
     */
768
     */
(-)a/src/core/org/apache/jmeter/gui/action/KeyStrokes.java (+4 lines)
Lines 57-62 public final class KeyStrokes { Link Here
57
    public static final KeyStroke SAVE              = KeyStroke.getKeyStroke(KeyEvent.VK_S, CONTROL_MASK);
57
    public static final KeyStroke SAVE              = KeyStroke.getKeyStroke(KeyEvent.VK_S, CONTROL_MASK);
58
    public static final KeyStroke SAVE_ALL_AS       = KeyStroke.getKeyStroke(KeyEvent.VK_S, CONTROL_MASK | InputEvent.SHIFT_DOWN_MASK);
58
    public static final KeyStroke SAVE_ALL_AS       = KeyStroke.getKeyStroke(KeyEvent.VK_S, CONTROL_MASK | InputEvent.SHIFT_DOWN_MASK);
59
    public static final KeyStroke SEARCH_TREE       = KeyStroke.getKeyStroke(KeyEvent.VK_F, CONTROL_MASK);
59
    public static final KeyStroke SEARCH_TREE       = KeyStroke.getKeyStroke(KeyEvent.VK_F, CONTROL_MASK);
60
    public static final KeyStroke SPACE             = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
60
    public static final KeyStroke TOGGLE            = KeyStroke.getKeyStroke(KeyEvent.VK_T, CONTROL_MASK);
61
    public static final KeyStroke TOGGLE            = KeyStroke.getKeyStroke(KeyEvent.VK_T, CONTROL_MASK);
61
    public static final KeyStroke PASTE             = KeyStroke.getKeyStroke(KeyEvent.VK_V, CONTROL_MASK);
62
    public static final KeyStroke PASTE             = KeyStroke.getKeyStroke(KeyEvent.VK_V, CONTROL_MASK);
62
    public static final KeyStroke WHAT_CLASS        = KeyStroke.getKeyStroke(KeyEvent.VK_W, CONTROL_MASK);
63
    public static final KeyStroke WHAT_CLASS        = KeyStroke.getKeyStroke(KeyEvent.VK_W, CONTROL_MASK);
Lines 75-80 public final class KeyStrokes { Link Here
75
    public static final KeyStroke ALT_LEFT_ARROW    = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.ALT_DOWN_MASK);
76
    public static final KeyStroke ALT_LEFT_ARROW    = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.ALT_DOWN_MASK);
76
    public static final KeyStroke ALT_RIGHT_ARROW   = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.ALT_DOWN_MASK);
77
    public static final KeyStroke ALT_RIGHT_ARROW   = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.ALT_DOWN_MASK);
77
78
79
    public static final KeyStroke CONTEXT_MENU      = KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0);
80
    public static final KeyStroke SHIFT_F10_CONTEXT_MENU = KeyStroke.getKeyStroke(KeyEvent.VK_F10, InputEvent.SHIFT_DOWN_MASK);
81
78
    /**
82
    /**
79
     * Check if an event matches the KeyStroke definition.
83
     * Check if an event matches the KeyStroke definition.
80
     *
84
     *
(-)a/src/core/org/apache/jmeter/gui/tree/JMeterTreeListener.java (-4 / +23 lines)
Lines 18-24 Link Here
18
18
19
package org.apache.jmeter.gui.tree;
19
package org.apache.jmeter.gui.tree;
20
20
21
import java.awt.Component;
21
import java.awt.Container;
22
import java.awt.Container;
23
import java.awt.Point;
24
import java.awt.Rectangle;
22
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
26
import java.awt.event.ActionListener;
24
import java.awt.event.InputEvent;
27
import java.awt.event.InputEvent;
Lines 54-60 public class JMeterTreeListener implements TreeSelectionListener, MouseListener, Link Here
54
57
55
    /**
58
    /**
56
     * Constructor for the JMeterTreeListener object.
59
     * Constructor for the JMeterTreeListener object.
57
     * 
60
     *
58
     * @param model
61
     * @param model
59
     *            The {@link JMeterTreeModel} for this listener
62
     *            The {@link JMeterTreeModel} for this listener
60
     */
63
     */
Lines 219-226 public class JMeterTreeListener implements TreeSelectionListener, MouseListener, Link Here
219
            actionName = ActionNames.MOVE_LEFT;
222
            actionName = ActionNames.MOVE_LEFT;
220
        } else if (KeyStrokes.matches(e, KeyStrokes.ALT_RIGHT_ARROW)) {
223
        } else if (KeyStrokes.matches(e, KeyStrokes.ALT_RIGHT_ARROW)) {
221
            actionName = ActionNames.MOVE_RIGHT;
224
            actionName = ActionNames.MOVE_RIGHT;
222
        } 
225
        } else if (KeyStrokes.matches(e, KeyStrokes.SHIFT_F10_CONTEXT_MENU)
223
        
226
                || KeyStrokes.matches(e, KeyStrokes.CONTEXT_MENU)) {
227
            // Bug 54784
228
            displayPopupMenu(e);
229
        }
230
224
        if (actionName != null) {
231
        if (actionName != null) {
225
            final ActionRouter actionRouter = ActionRouter.getInstance();
232
            final ActionRouter actionRouter = ActionRouter.getInstance();
226
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), actionName));
233
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), actionName));
Lines 228-233 public class JMeterTreeListener implements TreeSelectionListener, MouseListener, Link Here
228
        }
235
        }
229
    }
236
    }
230
237
238
    private void displayPopupMenu(KeyEvent e) {
239
        Component invoker = e.getComponent();
240
        TreePath path = new TreePath(getCurrentNode().getPath());
241
        Rectangle r = getJTree().getPathBounds(path);
242
        int padding = 5;
243
        Point point = new Point(r.x + padding, r.y + padding);
244
        JPopupMenu popup = getCurrentNode().createPopupMenu();
245
        GuiPackage.getInstance().displayPopUp(invoker, point, popup);
246
    }
247
231
    @Override
248
    @Override
232
    public void keyReleased(KeyEvent e) {
249
    public void keyReleased(KeyEvent e) {
233
    }
250
    }
Lines 237-243 public class JMeterTreeListener implements TreeSelectionListener, MouseListener, Link Here
237
    }
254
    }
238
255
239
    private boolean isRightClick(MouseEvent e) {
256
    private boolean isRightClick(MouseEvent e) {
240
        return e.isPopupTrigger() || (InputEvent.BUTTON2_MASK & e.getModifiers()) > 0 || (InputEvent.BUTTON3_MASK == e.getModifiers());
257
        return e.isPopupTrigger()
258
                || (InputEvent.BUTTON2_MASK & e.getModifiers()) > 0
259
                || (InputEvent.BUTTON3_MASK == e.getModifiers());
241
    }
260
    }
242
261
243
    private void displayPopUp(MouseEvent e) {
262
    private void displayPopUp(MouseEvent e) {
(-)a/src/core/org/apache/jmeter/gui/util/MenuFactory.java (-6 / +38 lines)
Lines 20-25 package org.apache.jmeter.gui.util; Link Here
20
20
21
import java.awt.Component;
21
import java.awt.Component;
22
import java.awt.HeadlessException;
22
import java.awt.HeadlessException;
23
import java.awt.event.ActionEvent;
23
import java.io.IOException;
24
import java.io.IOException;
24
import java.io.Serializable;
25
import java.io.Serializable;
25
import java.util.Collection;
26
import java.util.Collection;
Lines 39-44 import javax.swing.JMenuItem; Link Here
39
import javax.swing.JPopupMenu;
40
import javax.swing.JPopupMenu;
40
import javax.swing.KeyStroke;
41
import javax.swing.KeyStroke;
41
import javax.swing.MenuElement;
42
import javax.swing.MenuElement;
43
import javax.swing.event.MenuKeyEvent;
44
import javax.swing.event.MenuKeyListener;
45
42
import org.apache.jmeter.control.Controller;
46
import org.apache.jmeter.control.Controller;
43
import org.apache.jmeter.gui.GuiPackage;
47
import org.apache.jmeter.gui.GuiPackage;
44
import org.apache.jmeter.gui.JMeterGUIComponent;
48
import org.apache.jmeter.gui.JMeterGUIComponent;
Lines 69-75 public final class MenuFactory { Link Here
69
     *  and also for resource lookup in messages.properties
73
     *  and also for resource lookup in messages.properties
70
    */
74
    */
71
    public static final String THREADS = "menu_threads"; //$NON-NLS-1$
75
    public static final String THREADS = "menu_threads"; //$NON-NLS-1$
72
    
76
73
    public static final String FRAGMENTS = "menu_fragments"; //$NON-NLS-1$
77
    public static final String FRAGMENTS = "menu_fragments"; //$NON-NLS-1$
74
78
75
    public static final String TIMERS = "menu_timer"; //$NON-NLS-1$
79
    public static final String TIMERS = "menu_timer"; //$NON-NLS-1$
Lines 123-129 public final class MenuFactory { Link Here
123
    private static final String[] MENU_PARENT_SAMPLER = new String[] {
127
    private static final String[] MENU_PARENT_SAMPLER = new String[] {
124
        MenuFactory.CONTROLLERS };
128
        MenuFactory.CONTROLLERS };
125
129
126
    private static final List<MenuInfo> timers, controllers, samplers, threads, 
130
    private static final List<MenuInfo> timers, controllers, samplers, threads,
127
        fragments,configElements, assertions, listeners, nonTestElements,
131
        fragments,configElements, assertions, listeners, nonTestElements,
128
        postProcessors, preProcessors;
132
        postProcessors, preProcessors;
129
133
Lines 202-208 public final class MenuFactory { Link Here
202
206
203
    /**
207
    /**
204
     * @param menu JPopupMenu
208
     * @param menu JPopupMenu
205
     * @param addSaveTestFragmentMenu Add Save as Test Fragment menu if true 
209
     * @param addSaveTestFragmentMenu Add Save as Test Fragment menu if true
206
     */
210
     */
207
    public static void addFileMenu(JPopupMenu menu, boolean addSaveTestFragmentMenu) {
211
    public static void addFileMenu(JPopupMenu menu, boolean addSaveTestFragmentMenu) {
208
        // the undo/redo as a standard goes first in Edit menus
212
        // the undo/redo as a standard goes first in Edit menus
Lines 267-273 public final class MenuFactory { Link Here
267
        menu.add(redo);
271
        menu.add(redo);
268
    }
272
    }
269
273
270
271
    public static JMenu makeMenus(String[] categories, String label, String actionCommand) {
274
    public static JMenu makeMenus(String[] categories, String label, String actionCommand) {
272
        JMenu addMenu = new JMenu(label);
275
        JMenu addMenu = new JMenu(label);
273
        for (int i = 0; i < categories.length; i++) {
276
        for (int i = 0; i < categories.length; i++) {
Lines 374-379 public final class MenuFactory { Link Here
374
        for (MenuInfo info : menuInfo) {
377
        for (MenuInfo info : menuInfo) {
375
            menu.add(makeMenuItem(info, actionCommand));
378
            menu.add(makeMenuItem(info, actionCommand));
376
        }
379
        }
380
        // Bug 54784: adds listener for the enter and space keys to add items
381
        menu.addMenuKeyListener(new MenuKeyListener() {
382
            @Override
383
            public void menuKeyTyped(MenuKeyEvent e) {}
384
385
            @Override
386
            public void menuKeyReleased(MenuKeyEvent e) {}
387
388
            @Override
389
            public void menuKeyPressed(MenuKeyEvent e) {
390
                if (e.getKeyCode() != KeyStrokes.ENTER.getKeyCode()
391
                        && e.getKeyCode() != KeyStrokes.SPACE.getKeyCode()) {
392
                    return;
393
                }
394
                // using selectedPath because e.getPath() always returns the
395
                // first item in the menu rather than the selected item
396
                MenuElement[] selectedPath = e.getMenuSelectionManager().getSelectedPath();
397
                MenuElement source = selectedPath[selectedPath.length - 1];
398
399
                ActionEvent event = new ActionEvent(source, e.getID(), ActionNames.ADD);
400
                ActionRouter.getInstance().actionPerformed(event);
401
                // small hack: for some reason the menu doesn't hide when
402
                // adding elements that can't contain children, e.g.Counter
403
                if (e.getComponent().isShowing()) {
404
                    e.getComponent().setVisible(false);
405
                }
406
                e.consume();
407
            }
408
        });
409
        // end Bug 54784 change
377
        GuiUtils.makeScrollableMenu(menu);
410
        GuiUtils.makeScrollableMenu(menu);
378
        return menu;
411
        return menu;
379
    }
412
    }
Lines 435-440 public final class MenuFactory { Link Here
435
        JMenuItem newMenuChoice = new JMenuItem(info.getLabel());
468
        JMenuItem newMenuChoice = new JMenuItem(info.getLabel());
436
        newMenuChoice.setName(info.getClassName());
469
        newMenuChoice.setName(info.getClassName());
437
        newMenuChoice.addActionListener(ActionRouter.getInstance());
470
        newMenuChoice.addActionListener(ActionRouter.getInstance());
471
438
        if (actionCommand != null) {
472
        if (actionCommand != null) {
439
            newMenuChoice.setActionCommand(actionCommand);
473
            newMenuChoice.setActionCommand(actionCommand);
440
        }
474
        }
Lines 555-561 public final class MenuFactory { Link Here
555
                if (categories.contains(ASSERTIONS)) {
589
                if (categories.contains(ASSERTIONS)) {
556
                    assertions.add(new MenuInfo(item, name));
590
                    assertions.add(new MenuInfo(item, name));
557
                }
591
                }
558
559
            }
592
            }
560
        } catch (IOException e) {
593
        } catch (IOException e) {
561
            log.error("", e);
594
            log.error("", e);
562
- 

Return to bug 54784