Example usage for javax.swing JComponent getInputMap

List of usage examples for javax.swing JComponent getInputMap

Introduction

In this page you can find the example usage for javax.swing JComponent getInputMap.

Prototype

public final InputMap getInputMap(int condition) 

Source Link

Document

Returns the InputMap that is used during condition.

Usage

From source file:com.moneydance.modules.features.importlist.table.AbstractEditor.java

public final void registerKeyboardShortcut(final JComponent jComponent) {
    Validate.notNull(jComponent, "jComponent must not be null");
    if (this.getKeyStroke() == null) {
        return;//from w w w .ja v a  2s  . c o  m
    }

    final Action action = new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(final ActionEvent actionEvent) {
            ActionListener actionListener = AbstractEditor.this.getActionListener(0);
            actionListener.actionPerformed(actionEvent);
        }
    };

    final String actionMapKey = this.getClass().getName(); // unique
    jComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(this.getKeyStroke(), actionMapKey);
    jComponent.getActionMap().put(actionMapKey, action);
}

From source file:ch.epfl.lis.gnwgui.NetworkGraph.java

/**
 * Add a key listener to print the content of the JPanel in which the graph is drawn.
 * @param jp JPanel that contains the network graph.
 *//*from  w w  w . j a va2  s .co  m*/
@SuppressWarnings("serial")
public void addPrintAction(JComponent jp) {
    KeyStroke k = KeyStroke.getKeyStroke("alt P");
    jp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(k, "printscreen");
    jp.getActionMap().put("printscreen", new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            item_.getNetworkViewer().getControl().printGraph();
        }
    });
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopLookupField.java

protected void initClearShortcut() {
    JComponent editor = (JComponent) comboBox.getEditor().getEditorComponent();
    KeyStroke clearKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK, false);
    editor.getInputMap(JComponent.WHEN_FOCUSED).put(clearKeyStroke, "clearShortcut");
    editor.getActionMap().put("clearShortcut", new AbstractAction() {
        @Override/*from  w w w  .ja v a2s.  com*/
        public void actionPerformed(ActionEvent e) {
            if (!isRequired() && isEditable() && isEnabled()) {
                setValue(null);

                fireUserSelectionListeners();
            }
        }
    });
}

From source file:net.sf.jabref.EntryEditor.java

protected void setupSwingComponentKeyBindings(JComponent component) {
    // Set up key bindings and focus listener for the FieldEditor.
    InputMap im = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap am = component.getActionMap();

    im.put(prefs.getKey("Entry editor, store field"), "store");
    am.put("store", storeFieldAction);

    im.put(prefs.getKey("Entry editor, next panel"), "right");
    im.put(prefs.getKey("Entry editor, next panel 2"), "right");
    am.put("right", switchRightAction);

    im.put(prefs.getKey("Entry editor, previous panel"), "left");
    im.put(prefs.getKey("Entry editor, previous panel 2"), "left");
    am.put("left", switchLeftAction);

    im.put(prefs.getKey("Help"), "help");
    am.put("help", helpAction);

    im.put(prefs.getKey("Save database"), "save");
    am.put("save", saveDatabaseAction);

    im.put(Globals.prefs.getKey("Next tab"), "nexttab");
    am.put("nexttab", frame.nextTab);

    im.put(Globals.prefs.getKey("Previous tab"), "prevtab");
    am.put("prevtab", frame.prevTab);
}

From source file:com.t3.client.ui.T3Frame.java

private void updateKeyStrokes(JComponent c) {
    c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).clear();
    Map<KeyStroke, MacroButton> keyStrokeMap = MacroButtonHotKeyManager.getKeyStrokeMap();

    if (c.getActionMap().keys() != null) {
        for (Object o : c.getActionMap().keys()) {
            // We're looking for MacroButton here, but we're adding AbstractActions below...  Is this right? XXX
            if (o instanceof MacroButton) {
                if (log.isInfoEnabled())
                    log.info("Removing MacroButton " + ((MacroButton) o).getButtonText());
                c.getActionMap().remove(o);
            }//from  w w  w .java 2 s  .c  om
        }
    }
    for (KeyStroke keyStroke : keyStrokeMap.keySet()) {
        final MacroButton button = keyStrokeMap.get(keyStroke);
        if (button != null) {
            c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, button);
            c.getActionMap().put(button, new MTButtonHotKeyAction(button));
        } else {
            // This shouldn't be possible...
            log.error("No MacroButton found for keyStroke " + keyStroke.toString());
        }
    }
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Helper for adding KeyBindings./*w w  w  .j a  va 2  s . co  m*/
 * @param comp the component (usually a JButton)
 * @param action the action to be invoked
 * @param actionName the name to put into the map for the action
 * @param keyCode the key code
 * @param modifier the modifer
 */
public static void addKeyBinding(final JComponent comp, final Action action, final String actionName,
        final int keyCode, final int modifier) {
    KeyStroke ctrlS = KeyStroke.getKeyStroke(keyCode, modifier);
    InputMap inputMap = comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMap.put(ctrlS, actionName);
    ActionMap actionMap = comp.getActionMap();
    actionMap.put(actionName, action);
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Adds a Key mappings./*from ww w  . j  ava 2s.c om*/
 * @param comp comp
 * @param keyCode keyCode
 * @param actionName actionName
 * @param action action 
 * @return the action
 */
public Action addRecordKeyMappings(final JComponent comp, final int keyCode, final String actionName,
        final Action action, int modifiers) {
    InputMap inputMap = comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap actionMap = comp.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke(keyCode, modifiers), actionName);
    actionMap.put(actionName, action);

    //UIRegistry.registerAction(actionName, action);
    return action;
}

From source file:org.omegat.gui.align.AlignPanelController.java

private static void setKeyboardShortcut(JComponent comp, Object actionName, char stroke) {
    comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(stroke), actionName);
}