Search in sources :

Example 26 with AbstractAction

use of javax.swing.AbstractAction in project jmeter by apache.

the class RowDetailDialog method createRootPane.

@Override
protected JRootPane createRootPane() {
    JRootPane rootPane = new JRootPane();
    // Hide Window on ESC
    Action escapeAction = new AbstractAction("ESCAPE") {

        private static final long serialVersionUID = -8699034338969407625L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);
        }
    };
    // Do update on Enter
    Action enterAction = new AbstractAction("ENTER") {

        private static final long serialVersionUID = -1529005452976176873L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            doUpdate(actionEvent);
            setVisible(false);
        }
    };
    ActionMap actionMap = rootPane.getActionMap();
    actionMap.put(escapeAction.getValue(Action.NAME), escapeAction);
    actionMap.put(enterAction.getValue(Action.NAME), enterAction);
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME));
    inputMap.put(KeyStrokes.ENTER, enterAction.getValue(Action.NAME));
    return rootPane;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) JRootPane(javax.swing.JRootPane) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 27 with AbstractAction

use of javax.swing.AbstractAction in project jmeter by apache.

the class MainFrame method addQuickComponentHotkeys.

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_" + actionEvent.getActionCommand();
            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) {
                // $NON-NLS-1$
                log.warn("Failed to perform quick component add: {}", comp, err);
            }
        }
    };
    InputMap inputMap = treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke[] keyStrokes = new KeyStroke[] { KeyStrokes.CTRL_0, KeyStrokes.CTRL_1, KeyStrokes.CTRL_2, KeyStrokes.CTRL_3, KeyStrokes.CTRL_4, KeyStrokes.CTRL_5, KeyStrokes.CTRL_6, KeyStrokes.CTRL_7, KeyStrokes.CTRL_8, KeyStrokes.CTRL_9 };
    for (int n = 0; n < keyStrokes.length; n++) {
        treevar.getActionMap().put(ActionNames.QUICK_COMPONENT + String.valueOf(n), quickComponent);
        inputMap.put(keyStrokes[n], ActionNames.QUICK_COMPONENT + String.valueOf(n));
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) ActionEvent(java.awt.event.ActionEvent) TestElement(org.apache.jmeter.testelement.TestElement) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) TreePath(javax.swing.tree.TreePath) KeyStroke(javax.swing.KeyStroke) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 28 with AbstractAction

use of javax.swing.AbstractAction in project jmeter by apache.

the class SavePropertyDialog method createRootPane.

@Override
protected JRootPane createRootPane() {
    JRootPane rootPane = new JRootPane();
    Action escapeAction = new AbstractAction("ESCAPE") {

        /**
             * 
             */
        private static final long serialVersionUID = 2208129319916921772L;

        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    };
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME));
    rootPane.getActionMap().put(escapeAction.getValue(Action.NAME), escapeAction);
    return rootPane;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) JRootPane(javax.swing.JRootPane) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 29 with AbstractAction

use of javax.swing.AbstractAction in project JMRI by JMRI.

the class PanelProPane method statusPanel.

@Override
protected JPanel statusPanel() {
    JPanel j = new JPanel();
    j.setLayout(new BoxLayout(j, BoxLayout.Y_AXIS));
    j.add(super.statusPanel());
    // Buttons
    Action quit = new AbstractAction(Bundle.getMessage("MenuItemQuit")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            Apps.handleQuit();
        }
    };
    JPanel p3 = new JPanel();
    p3.setLayout(new java.awt.FlowLayout());
    JButton h1 = new JButton(Bundle.getMessage("ButtonHelp"));
    jmri.util.HelpUtil.addHelpToComponent(h1, "html.apps.PanelPro.PanelPro");
    h1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    p3.add(h1);
    JButton q1 = new JButton(Bundle.getMessage("ButtonQuit"));
    q1.addActionListener(quit);
    q1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    p3.add(q1);
    j.add(p3);
    return j;
}
Also used : JPanel(javax.swing.JPanel) AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) AbstractAction(javax.swing.AbstractAction)

Example 30 with AbstractAction

use of javax.swing.AbstractAction in project JMRI by JMRI.

the class PanelPro method statusPanel.

@Override
protected JPanel statusPanel() {
    JPanel j = new JPanel();
    j.setLayout(new BoxLayout(j, BoxLayout.Y_AXIS));
    j.add(super.statusPanel());
    // Buttons
    Action quit = new AbstractAction(Bundle.getMessage("MenuItemQuit")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            Apps.handleQuit();
        }
    };
    JPanel p3 = new JPanel();
    p3.setLayout(new java.awt.FlowLayout());
    JButton h1 = new JButton(Bundle.getMessage("ButtonHelp"));
    jmri.util.HelpUtil.addHelpToComponent(h1, "html.apps.PanelPro.PanelPro");
    h1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    p3.add(h1);
    JButton q1 = new JButton(Bundle.getMessage("ButtonQuit"));
    q1.addActionListener(quit);
    q1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    p3.add(q1);
    j.add(p3);
    return j;
}
Also used : JPanel(javax.swing.JPanel) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) AbstractAction(javax.swing.AbstractAction)

Aggregations

AbstractAction (javax.swing.AbstractAction)155 ActionEvent (java.awt.event.ActionEvent)143 Action (javax.swing.Action)35 JButton (javax.swing.JButton)33 JPanel (javax.swing.JPanel)30 InputMap (javax.swing.InputMap)29 JMenu (javax.swing.JMenu)29 JMenuItem (javax.swing.JMenuItem)23 ActionListener (java.awt.event.ActionListener)21 ActionMap (javax.swing.ActionMap)20 JScrollPane (javax.swing.JScrollPane)16 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)14 BorderLayout (java.awt.BorderLayout)14 JPopupMenu (javax.swing.JPopupMenu)14 BoxLayout (javax.swing.BoxLayout)12 JSeparator (javax.swing.JSeparator)12 JDialog (javax.swing.JDialog)11 JMenuBar (javax.swing.JMenuBar)9 Dimension (java.awt.Dimension)8 WindowEvent (java.awt.event.WindowEvent)8