Example usage for javax.swing InputMap put

List of usage examples for javax.swing InputMap put

Introduction

In this page you can find the example usage for javax.swing InputMap put.

Prototype

public void put(KeyStroke keyStroke, Object actionMapKey) 

Source Link

Document

Adds a binding for keyStroke to actionMapKey .

Usage

From source file:se.trixon.pacoma.ui.MainFrame.java

private void initActions() {
    mActionManager = ActionManager.getInstance().init(getRootPane().getActionMap(),
            getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW));

    InputMap inputMap = mPopupMenu.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = mPopupMenu.getActionMap();
    Action action = new AbstractAction("HideMenu") {

        @Override/*  ww w . j a v a2s.c  o  m*/
        public void actionPerformed(ActionEvent e) {
            mPopupMenu.setVisible(false);
        }
    };

    String key = "HideMenu";
    actionMap.put(key, action);
    KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    inputMap.put(keyStroke, key);

    //about
    PomInfo pomInfo = new PomInfo(Pacoma.class, "se.trixon", "pacoma");
    AboutModel aboutModel = new AboutModel(SystemHelper.getBundle(Pacoma.class, "about"),
            SystemHelper.getResourceAsImageIcon(MainFrame.class, "pacoma-icon.png"));
    aboutModel.setAppVersion(pomInfo.getVersion());
    AboutPanel aboutPanel = new AboutPanel(aboutModel);
    action = AboutPanel.getAction(MainFrame.this, aboutPanel);
    getRootPane().getActionMap().put(ActionManager.ABOUT, action);

    //File
    newButton.setAction(mActionManager.getAction(ActionManager.NEW));
    newMenuItem.setAction(mActionManager.getAction(ActionManager.NEW));

    openButton.setAction(mActionManager.getAction(ActionManager.OPEN));
    openMenuItem.setAction(mActionManager.getAction(ActionManager.OPEN));

    closeButton.setAction(mActionManager.getAction(ActionManager.CLOSE));
    closeMenuItem.setAction(mActionManager.getAction(ActionManager.CLOSE));

    saveButton.setAction(mActionManager.getAction(ActionManager.SAVE));
    saveMenuItem.setAction(mActionManager.getAction(ActionManager.SAVE));

    saveAsButton.setAction(mActionManager.getAction(ActionManager.SAVE_AS));
    saveAsMenuItem.setAction(mActionManager.getAction(ActionManager.SAVE_AS));

    propertiesMenuItem.setAction(mActionManager.getAction(ActionManager.PROPERTIES));
    propertiesButton.setAction(mActionManager.getAction(ActionManager.PROPERTIES));

    quitMenuItem.setAction(mActionManager.getAction(ActionManager.QUIT));

    //Edit
    undoMenuItem.setAction(mActionManager.getAction(ActionManager.UNDO));
    undoButton.setAction(mActionManager.getAction(ActionManager.UNDO));
    undoButton.setText("");

    redoMenuItem.setAction(mActionManager.getAction(ActionManager.REDO));
    redoButton.setAction(mActionManager.getAction(ActionManager.REDO));
    redoButton.setText("");

    //Tools
    optionsMenuItem.setAction(mActionManager.getAction(ActionManager.OPTIONS));

    //Help
    helpMenuItem.setAction(mActionManager.getAction(ActionManager.HELP));
    aboutMenuItem.setAction(mActionManager.getAction(ActionManager.ABOUT));

    //Toolbar
    addButton.setAction(mActionManager.getAction(ActionManager.ADD));
    clearButton.setAction(mActionManager.getAction(ActionManager.CLEAR));
    regenerateButton.setAction(mActionManager.getAction(ActionManager.REGENERATE));

    //        startButton.setAction(mActionManager.getAction(ActionManager.START));
    //        cancelButton.setAction(mActionManager.getAction(ActionManager.CANCEL));
    menuButton.setAction(mActionManager.getAction(ActionManager.MENU));
    renderButton.setAction(mActionManager.getAction(ActionManager.START));

    SwingHelper.clearTextButtons(menuButton);
}

From source file:storybook.toolkit.swing.SwingUtil.java

public static void addCtrlEnterAction(JComponent comp, AbstractAction action) {
    InputMap inputMap = comp.getInputMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK), action);
}

From source file:wsattacker.plugin.intelligentdos.ui.dialog.ConfigureCommonParams_NB.java

private void configureKeyBinding() {
    InputMap inputMap = commonParamTable.getInputMap(JTable.WHEN_FOCUSED);
    ActionMap actionMap = commonParamTable.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
    actionMap.put(DELETE, new AbstractAction() {
        @Override/* ww  w  .j  a  v  a  2 s.c  o  m*/
        public void actionPerformed(ActionEvent evt) {
            removeRow();
        }
    });
}