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

(-)a/src/core/org/apache/jmeter/gui/GuiPackage.java (-8 / +12 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 175-181 public final class GuiPackage implements LocaleChangeListener, HistoryListener { Link Here
175
     *
176
     *
176
     * @return GuiPackage
177
     * @return GuiPackage
177
     */
178
     */
178
    public static GuiPackage getInstance(JMeterTreeListener listener, JMeterTreeModel treeModel) {
179
    public synchronized static GuiPackage getInstance(JMeterTreeListener listener, JMeterTreeModel treeModel) {
179
        if (guiPack == null) {
180
        if (guiPack == null) {
180
            guiPack = new GuiPackage(treeModel, listener);
181
            guiPack = new GuiPackage(treeModel, listener);
181
            guiPack.undoHistory.add(treeModel, "Created");
182
            guiPack.undoHistory.add(treeModel, "Created");
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
            if (log.isDebugEnabled()) {
630
                log.debug("Showing pop up for " + invoker + " at x,y = " + p.x + "," + p.y);
631
            }
627
632
628
            popup.pack();
633
            popup.pack();
629
            popup.show(invoker, e.getX(), e.getY());
634
            popup.show(invoker, p.x, p.y);
630
            popup.setVisible(true);
635
            popup.setVisible(true);
631
            popup.requestFocusInWindow();
636
            popup.requestFocusInWindow();
632
        }
637
        }
Lines 739-745 public final class GuiPackage implements LocaleChangeListener, HistoryListener { Link Here
739
                JOptionPane.showMessageDialog(null,message,title,type);
744
                JOptionPane.showMessageDialog(null,message,title,type);
740
            }
745
            }
741
        });
746
        });
742
743
    }
747
    }
744
748
745
    /**
749
    /**
(-)a/src/core/org/apache/jmeter/gui/action/KeyStrokes.java (-2 / +4 lines)
Lines 30-37 import javax.swing.KeyStroke; Link Here
30
 */
30
 */
31
public final class KeyStrokes {
31
public final class KeyStrokes {
32
    // Prevent instantiation
32
    // Prevent instantiation
33
    private KeyStrokes(){
33
    private KeyStrokes() {}
34
    }
35
34
36
    // Bug 47064 - fixes for Mac LAF
35
    // Bug 47064 - fixes for Mac LAF
37
    private static final int CONTROL_MASK =Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
36
    private static final int CONTROL_MASK =Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
Lines 74-79 public final class KeyStrokes { Link Here
74
    public static final KeyStroke ALT_DOWN_ARROW    = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK);
73
    public static final KeyStroke ALT_DOWN_ARROW    = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK);
75
    public static final KeyStroke ALT_LEFT_ARROW    = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.ALT_DOWN_MASK);
74
    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);
75
    public static final KeyStroke ALT_RIGHT_ARROW   = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.ALT_DOWN_MASK);
76
    
77
    public static final KeyStroke CONTEXT_MENU      = KeyStroke.getKeyStroke(KeyEvent.VK_CONTEXT_MENU, 0);
78
    public static final KeyStroke SHIFT_F10_CONTEXT_MENU = KeyStroke.getKeyStroke(KeyEvent.VK_F10, InputEvent.SHIFT_DOWN_MASK);
77
79
78
    /**
80
    /**
79
     * Check if an event matches the KeyStroke definition.
81
     * Check if an event matches the KeyStroke definition.
(-)a/src/core/org/apache/jmeter/gui/tree/JMeterTreeListener.java (-40 / +42 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 44-51 import org.apache.log.Logger; Link Here
44
public class JMeterTreeListener implements TreeSelectionListener, MouseListener, KeyListener {
47
public class JMeterTreeListener implements TreeSelectionListener, MouseListener, KeyListener {
45
    private static final Logger log = LoggingManager.getLoggerForClass();
48
    private static final Logger log = LoggingManager.getLoggerForClass();
46
49
47
    // Container endWindow;
48
    // JPopupMenu pop;
49
    private TreePath currentPath;
50
    private TreePath currentPath;
50
51
51
    private ActionListener actionHandler;
52
    private ActionListener actionHandler;
Lines 145-153 public class JMeterTreeListener implements TreeSelectionListener, MouseListener, Link Here
145
        log.debug("value changed, updating currentPath");
146
        log.debug("value changed, updating currentPath");
146
        currentPath = e.getNewLeadSelectionPath();
147
        currentPath = e.getNewLeadSelectionPath();
147
        // Call requestFocusInWindow to ensure current component loses focus and
148
        // Call requestFocusInWindow to ensure current component loses focus and
148
        // all values are correctly saved
149
        // all values are correctly saved. See Bug IDs 55103 and 55459.
149
        // see https://issues.apache.org/bugzilla/show_bug.cgi?id=55103
150
        // see https://issues.apache.org/bugzilla/show_bug.cgi?id=55459
151
        tree.requestFocusInWindow();
150
        tree.requestFocusInWindow();
152
        actionHandler.actionPerformed(new ActionEvent(this, 3333, ActionNames.EDIT)); // $NON-NLS-1$
151
        actionHandler.actionPerformed(new ActionEvent(this, 3333, ActionNames.EDIT)); // $NON-NLS-1$
153
    }
152
    }
Lines 177-184 public class JMeterTreeListener implements TreeSelectionListener, MouseListener, Link Here
177
            currentPath = tree.getPathForLocation(e.getX(), e.getY());
176
            currentPath = tree.getPathForLocation(e.getX(), e.getY());
178
        }
177
        }
179
        if (selRow != -1) {
178
        if (selRow != -1) {
180
            // updateMainMenu(((JMeterGUIComponent)
181
            // getCurrentNode().getUserObject()).createPopupMenu());
182
            if (isRightClick(e)) {
179
            if (isRightClick(e)) {
183
                if (tree.getSelectionCount() < 2) {
180
                if (tree.getSelectionCount() < 2) {
184
                    tree.setSelectionPath(currentPath);
181
                    tree.setSelectionPath(currentPath);
Lines 189-236 public class JMeterTreeListener implements TreeSelectionListener, MouseListener, Link Here
189
        }
186
        }
190
    }
187
    }
191
188
192
193
    @Override
189
    @Override
194
    public void mouseExited(MouseEvent ev) {
190
    public void mouseExited(MouseEvent e) {
195
    }
191
    }
196
192
197
    @Override
193
    @Override
198
    public void keyPressed(KeyEvent e) {
194
    public void keyPressed(KeyEvent e) {
199
        if (KeyStrokes.matches(e,KeyStrokes.COPY)) {
195
        String actionName = null;
200
            ActionRouter actionRouter = ActionRouter.getInstance();
196
201
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.COPY));
197
        if (KeyStrokes.matches(e, KeyStrokes.COPY)) {
202
            e.consume();
198
            actionName = ActionNames.COPY;
203
        } else if (KeyStrokes.matches(e,KeyStrokes.PASTE)) {
199
        } else if (KeyStrokes.matches(e, KeyStrokes.PASTE)) {
204
            ActionRouter actionRouter = ActionRouter.getInstance();
200
            actionName = ActionNames.PASTE;
205
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.PASTE));
201
        } else if (KeyStrokes.matches(e, KeyStrokes.CUT)) {
206
            e.consume();
202
            actionName = ActionNames.CUT;
207
        } else if (KeyStrokes.matches(e,KeyStrokes.CUT)) {
203
        } else if (KeyStrokes.matches(e, KeyStrokes.DUPLICATE)) {
208
            ActionRouter actionRouter = ActionRouter.getInstance();
204
            actionName = ActionNames.DUPLICATE;
209
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.CUT));
205
        } else if (KeyStrokes.matches(e, KeyStrokes.ALT_UP_ARROW)) {
210
            e.consume();
206
            actionName = ActionNames.MOVE_UP;
211
        } else if (KeyStrokes.matches(e,KeyStrokes.DUPLICATE)) {
207
        } else if (KeyStrokes.matches(e, KeyStrokes.ALT_DOWN_ARROW)) {
212
            ActionRouter actionRouter = ActionRouter.getInstance();
208
            actionName = ActionNames.MOVE_DOWN;
213
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.DUPLICATE));
209
        } else if (KeyStrokes.matches(e, KeyStrokes.ALT_LEFT_ARROW)) {
214
            e.consume();
210
            actionName = ActionNames.MOVE_LEFT;
215
        } else if (KeyStrokes.matches(e,KeyStrokes.ALT_UP_ARROW)) {
211
        } else if (KeyStrokes.matches(e, KeyStrokes.ALT_RIGHT_ARROW)) {
216
            ActionRouter actionRouter = ActionRouter.getInstance();
212
            actionName = ActionNames.MOVE_RIGHT;
217
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.MOVE_UP));
213
        } else if (KeyStrokes.matches(e, KeyStrokes.SHIFT_F10_CONTEXT_MENU)
218
            e.consume();
214
                || KeyStrokes.matches(e, KeyStrokes.CONTEXT_MENU)) {
219
        } else if (KeyStrokes.matches(e,KeyStrokes.ALT_DOWN_ARROW)) {
215
            // Bug 54784
220
            ActionRouter actionRouter = ActionRouter.getInstance();
216
            displayPopupMenu(e);
221
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.MOVE_DOWN));
217
        }
222
            e.consume();
218
        
223
        } else if (KeyStrokes.matches(e,KeyStrokes.ALT_LEFT_ARROW)) {
219
        if (actionName != null) {
224
            ActionRouter actionRouter = ActionRouter.getInstance();
220
            final ActionRouter actionRouter = ActionRouter.getInstance();
225
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.MOVE_LEFT));
221
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), actionName));
226
            e.consume();
227
        } else if (KeyStrokes.matches(e,KeyStrokes.ALT_RIGHT_ARROW)) {
228
            ActionRouter actionRouter = ActionRouter.getInstance();
229
            actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.MOVE_RIGHT));
230
            e.consume();
222
            e.consume();
231
        }
223
        }
232
    }
224
    }
233
225
226
    private void displayPopupMenu(KeyEvent e) {
227
        Component invoker = e.getComponent();
228
        TreePath path = new TreePath(getCurrentNode().getPath());
229
        Rectangle r = getJTree().getPathBounds(path);
230
        int padding = 5;
231
        Point point = new Point(r.x + padding, r.y + padding);
232
        JPopupMenu popup = getCurrentNode().createPopupMenu();
233
        GuiPackage.getInstance().displayPopUp(invoker, point, popup);
234
    }
235
234
    @Override
236
    @Override
235
    public void keyReleased(KeyEvent e) {
237
    public void keyReleased(KeyEvent e) {
236
    }
238
    }
(-)a/src/core/org/apache/jmeter/gui/util/MenuFactory.java (-5 / +7 lines)
Lines 39-45 import javax.swing.JMenuItem; Link Here
39
import javax.swing.JPopupMenu;
39
import javax.swing.JPopupMenu;
40
import javax.swing.KeyStroke;
40
import javax.swing.KeyStroke;
41
import javax.swing.MenuElement;
41
import javax.swing.MenuElement;
42
43
import org.apache.jmeter.control.Controller;
42
import org.apache.jmeter.control.Controller;
44
import org.apache.jmeter.gui.GuiPackage;
43
import org.apache.jmeter.gui.GuiPackage;
45
import org.apache.jmeter.gui.JMeterGUIComponent;
44
import org.apache.jmeter.gui.JMeterGUIComponent;
Lines 436-441 public final class MenuFactory { Link Here
436
        JMenuItem newMenuChoice = new JMenuItem(info.getLabel());
435
        JMenuItem newMenuChoice = new JMenuItem(info.getLabel());
437
        newMenuChoice.setName(info.getClassName());
436
        newMenuChoice.setName(info.getClassName());
438
        newMenuChoice.addActionListener(ActionRouter.getInstance());
437
        newMenuChoice.addActionListener(ActionRouter.getInstance());
438
        newMenuChoice.registerKeyboardAction(ActionRouter.getInstance(), actionCommand,
439
                KeyStrokes.ENTER, JMenuItem.WHEN_IN_FOCUSED_WINDOW); // Bug 54784
440
439
        if (actionCommand != null) {
441
        if (actionCommand != null) {
440
            newMenuChoice.setActionCommand(actionCommand);
442
            newMenuChoice.setActionCommand(actionCommand);
441
        }
443
        }
Lines 609-616 public final class MenuFactory { Link Here
609
611
610
        // Force TestFragment to only be pastable under a Test Plan
612
        // Force TestFragment to only be pastable under a Test Plan
611
        if (foundClass(nodes, new Class[]{org.apache.jmeter.control.TestFragmentController.class})){
613
        if (foundClass(nodes, new Class[]{org.apache.jmeter.control.TestFragmentController.class})){
612
            if (parent instanceof TestPlan)
614
            if (parent instanceof TestPlan) {
613
                return true;
615
                return true;
616
            }
614
            return false;
617
            return false;
615
        }
618
        }
616
619
Lines 721-729 public final class MenuFactory { Link Here
721
            String lab1 = o1.getLabel();
724
            String lab1 = o1.getLabel();
722
            String lab2 = o2.getLabel();
725
            String lab2 = o2.getLabel();
723
            if (caseBlind) {
726
            if (caseBlind) {
724
                return lab1.toLowerCase(Locale.ENGLISH).compareTo(lab2.toLowerCase(Locale.ENGLISH));                
727
                return lab1.toLowerCase(Locale.ENGLISH).compareTo(lab2.toLowerCase(Locale.ENGLISH));
725
            }
728
            }
726
            return lab1.compareTo(lab2);                
729
            return lab1.compareTo(lab2);
727
        }
730
        }
728
    }
731
    }
729
732
730
- 

Return to bug 54784