Example usage for javax.swing JRootPane getActionMap

List of usage examples for javax.swing JRootPane getActionMap

Introduction

In this page you can find the example usage for javax.swing JRootPane getActionMap.

Prototype

public final ActionMap getActionMap() 

Source Link

Document

Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding.

Usage

From source file:Main.java

public static void installEscapeCloseOperation(final JDialog dialog) {
    Action dispatchClosing = new AbstractAction() {
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }/*from  w  ww. j a v a2  s  .c o m*/
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY);
    root.getActionMap().put(ESCAPE_KEY, dispatchClosing);
}

From source file:Main.java

public static void installEscapeCloseOperation(final JFrame dialog) {
    Action dispatchClosing = new AbstractAction() {
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }//from  ww w. java2 s.  c om
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_KEY_STROKE, ESCAPE_KEY);
    root.getActionMap().put(ESCAPE_KEY, dispatchClosing);
}

From source file:Main.java

public static void closeOnEscape(final JFrame frame) {
    KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE");
    Action actionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent actionEvent) {
            frame.setVisible(false);//from  w w w. j  a v a2 s .  c  o m
            frame.dispose();
        }
    };
    JRootPane rootPane = frame.getRootPane();
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(stroke, "ESCAPE");
    rootPane.getActionMap().put("ESCAPE", actionListener);
}

From source file:Main.java

public static void setCancelButton(final JRootPane rp, final JButton b) {
    rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "cancel");
    rp.getActionMap().put("cancel", new AbstractAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent ev) {
            b.doClick();//from   w  ww  . jav  a2s  . c  om
        }
    });
}

From source file:Main.java

public static void setDontSaveButton(final JRootPane rp, final JButton b) {
    rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_D, 0), "dontSave");
    rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_D, rp.getToolkit().getMenuShortcutKeyMask()), "dontSave");
    rp.getActionMap().put("dontSave", new AbstractAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent ev) {
            b.doClick();/*  www .j a  va 2s. c  o m*/
        }
    });
}

From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static void installEscapeCloseOperation(final JDialog dialog) {
    Action dispatchClosing = new AbstractAction() {

        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }/* w  w  w  . j a  v a  2  s  .  co  m*/
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey);
    root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing);
}

From source file:net.sf.jabref.util.Util.java

/**
 * Binds ESC-Key to cancel button/* w  w  w .  j  a  v  a2s.co  m*/
 *
 * @param rootPane     the pane to bind the action to. Typically, this variable is retrieved by this.getRootPane();
 * @param cancelAction the action to bind
 */
// TODO: move to GUI
public static void bindCloseDialogKeyToCancelAction(JRootPane rootPane, Action cancelAction) {
    InputMap im = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap am = rootPane.getActionMap();
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);
}

From source file:FrameKey.java

protected JRootPane createRootPane() {
    JRootPane rootPane = new JRootPane();
    KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE");
    Action actionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);//from   w ww  .  j  a v a  2  s  .com
        }
    };
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(stroke, "ESCAPE");
    rootPane.getActionMap().put("ESCAPE", actionListener);

    return rootPane;
}

From source file:EscapeDialog.java

License:asdf

protected JRootPane createRootPane() {
    JRootPane rootPane = new JRootPane();
    KeyStroke stroke = KeyStroke.getKeyStroke("ESCAPE");
    Action actionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("about to disappear");
            setVisible(false);/*from   w  w w . ja  v  a 2  s  .c om*/
        }
    };
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(stroke, "ESCAPE");
    rootPane.getActionMap().put("ESCAPE", actionListener);

    return rootPane;
}

From source file:ee.ioc.cs.vsle.editor.Editor.java

/**
 * Creates Action objects and initializes Input and Action mappings
 *///from  w w w  . j a  va2 s  . c o  m
private void initActions() {
    JRootPane rp = getRootPane();

    ActionMap am = rp.getActionMap();
    InputMap im = rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    am.put(DeleteAction.class, deleteAction);
    am.put(CloneAction.class, cloneAction);

    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DeleteAction.class);
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK), CloneAction.class);
}