Search in sources :

Example 76 with AbstractAction

use of javax.swing.AbstractAction in project jdk8u_jdk by JetBrains.

the class Test8013370 method run.

@Override
public void run() {
    if (this.frame == null) {
        JMenuBar menu = new JMenuBar() {

            @Override
            protected boolean processKeyBinding(KeyStroke stroke, KeyEvent event, int condition, boolean pressed) {
                if (stroke == null) {
                    Test8013370.this.error = true;
                    return false;
                }
                return super.processKeyBinding(stroke, event, condition, pressed);
            }
        };
        menu.add(new JMenuItem("Menu"));
        InputMap map = menu.getInputMap(WHEN_IN_FOCUSED_WINDOW);
        // from a array to a hashtable when more than 8 values are added.
        for (int i = 0; i < 9; i++) {
            String name = " Action #" + i;
            map.put(KeyStroke.getKeyStroke(KeyEvent.VK_A + i, CTRL_DOWN_MASK), name);
            menu.getActionMap().put(name, new AbstractAction(name) {

                @Override
                public void actionPerformed(ActionEvent event) {
                    showMessageDialog(null, getValue(NAME));
                }
            });
        }
        this.frame = new JFrame("8013370");
        this.frame.setJMenuBar(menu);
        this.frame.setVisible(true);
    } else {
        this.frame.dispose();
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenuBar(javax.swing.JMenuBar)

Example 77 with AbstractAction

use of javax.swing.AbstractAction in project scylla by bptlab.

the class ScyllaGUI method initKeyBindings.

/**
 * Initializes key bindings and key event redirection to the current selected panel
 */
public void initKeyBindings() {
    contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK), ACTIONKEY_SAVE);
    contentPane.getActionMap().put(ACTIONKEY_SAVE, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ((JComponent) contentPane.getSelectedComponent()).getActionMap().get(ACTIONKEY_SAVE).actionPerformed(e);
        }
    });
    contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK), ACTIONKEY_SAVEAS);
    contentPane.getActionMap().put(ACTIONKEY_SAVEAS, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ((JComponent) contentPane.getSelectedComponent()).getActionMap().get(ACTIONKEY_SAVEAS).actionPerformed(e);
        }
    });
    contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK), ACTIONKEY_OPEN);
    contentPane.getActionMap().put(ACTIONKEY_OPEN, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ((JComponent) contentPane.getSelectedComponent()).getActionMap().get(ACTIONKEY_OPEN).actionPerformed(e);
        }
    });
    contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK), ACTIONKEY_NEW);
    contentPane.getActionMap().put(ACTIONKEY_NEW, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ((JComponent) contentPane.getSelectedComponent()).getActionMap().get(ACTIONKEY_NEW).actionPerformed(e);
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 78 with AbstractAction

use of javax.swing.AbstractAction in project knime-core by knime.

the class ParallelCoordinatesPlotter method getHideAction.

/**
 * @return the menu item for hide unhilited.
 */
public Action getHideAction() {
    Action hide = new AbstractAction(AbstractPlotter.HIDE_UNHILITED) {

        /**
         * {@inheritDoc}
         */
        @Override
        public void actionPerformed(final ActionEvent e) {
            m_hide = true;
            if (getDrawingPane() instanceof ParallelCoordinateDrawingPane) {
                getParCoordDrawinPane().setFadeUnhilited(false);
                getParCoordDrawinPane().setHideUnhilited(true);
            }
            updatePaintModel();
        }
    };
    return hide;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 79 with AbstractAction

use of javax.swing.AbstractAction in project knime-core by knime.

the class ParallelCoordinatesPlotter method getShowAllAction.

// ---------- menu -------------
/**
 * @return the menu item for show all.
 */
public Action getShowAllAction() {
    Action show = new AbstractAction(AbstractPlotter.SHOW_ALL) {

        /**
         * {@inheritDoc}
         */
        @Override
        public void actionPerformed(final ActionEvent e) {
            m_hide = false;
            if (getDrawingPane() instanceof ParallelCoordinateDrawingPane) {
                getParCoordDrawinPane().setFadeUnhilited(false);
                getParCoordDrawinPane().setHideUnhilited(false);
            }
            updatePaintModel();
        }
    };
    return show;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 80 with AbstractAction

use of javax.swing.AbstractAction in project knime-core by knime.

the class ScatterPlotter method getHideAction.

/**
 * The <code>ScatterPlotter</code> adds the posssibility to show, fade or
 * hide unhilited dots and this is the hide unhilited action. The hide flag
 * is administered in the <code>ScatterPlotter</code>, since hidden
 * points are not passed to the
 * {@link org.knime.base.node.viz.plotter.scatter
 * .ScatterPlotterDrawingPane},
 * the fade flag is administered in the
 * {@link org.knime.base.node.viz.plotter.scatter
 * .ScatterPlotterDrawingPane},
 * since the dots are painted but with a different (faded) color.
 *
 * @return the menu item for hide unhilited.
 */
public Action getHideAction() {
    Action hide = new AbstractAction(AbstractPlotter.HIDE_UNHILITED) {

        /**
         * {@inheritDoc}
         */
        @Override
        public void actionPerformed(final ActionEvent e) {
            m_hide = true;
            if (getDrawingPane() instanceof ScatterPlotterDrawingPane) {
                getScatterPlotterDrawingPane().setFadeUnhilited(false);
            }
            updatePaintModel();
        }
    };
    return hide;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Aggregations

AbstractAction (javax.swing.AbstractAction)174 ActionEvent (java.awt.event.ActionEvent)162 Action (javax.swing.Action)42 InputMap (javax.swing.InputMap)34 JButton (javax.swing.JButton)33 JMenu (javax.swing.JMenu)30 JPanel (javax.swing.JPanel)30 ActionListener (java.awt.event.ActionListener)24 JMenuItem (javax.swing.JMenuItem)24 ActionMap (javax.swing.ActionMap)23 JScrollPane (javax.swing.JScrollPane)16 JPopupMenu (javax.swing.JPopupMenu)15 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)14 BorderLayout (java.awt.BorderLayout)14 BoxLayout (javax.swing.BoxLayout)12 JSeparator (javax.swing.JSeparator)12 JDialog (javax.swing.JDialog)11 WindowEvent (java.awt.event.WindowEvent)9 JMenuBar (javax.swing.JMenuBar)9 JTextField (javax.swing.JTextField)9