Example usage for javax.swing InputMap get

List of usage examples for javax.swing InputMap get

Introduction

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

Prototype

public Object get(KeyStroke keyStroke) 

Source Link

Document

Returns the binding for keyStroke , messaging the parent InputMap if the binding is not locally defined.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTree tree = new JTree();
    InputMap inputMap = tree.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke[] keyStrokes = inputMap.allKeys();
    for (KeyStroke keyStroke : keyStrokes) {
        Object actionCommand = inputMap.get(keyStroke);
        System.out.println("keyStroke = " + keyStroke);
        System.out.println("actionCommand = " + actionCommand);
    }/* ww  w .j av  a 2  s .c  om*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    InputMap inputMap = new InputMap();

    inputMap.put(KeyStroke.getKeyStroke("F2"), "actionName");

    JButton component = new JButton("button");

    inputMap.setParent(component.getInputMap(JComponent.WHEN_FOCUSED));
    component.setInputMap(JComponent.WHEN_FOCUSED, inputMap);

    System.out.println(inputMap.get(KeyStroke.getKeyStroke("F2")));

}

From source file:Main.java

public static void refleshAction(JComponent com, KeyStroke keyStroke) {
    InputMap im = com.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    Object o = im.get(keyStroke);
    if (o == null) {
        im = com.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        o = im.get(keyStroke);/*from   w w  w  . ja  v a  2  s  .  c  om*/
    }
    if (o != null) {
        Action a = com.getActionMap().get(o);
        a.setEnabled(a.isEnabled());
    }
}

From source file:Main.java

/**
 * Obtine actiunea inregistrata pentru apasarea de tasta
 * @return /* w ww. j  av a 2s  .co  m*/
 */
public static Action getActionForKeystroke(JComponent component, int inputMapId, KeyStroke keyStroke) {
    //Identify the action key
    InputMap inputMap = component.getInputMap(inputMapId);
    String key = (String) inputMap.get(keyStroke);

    //Get the action
    if (key != null) {
        ActionMap localMap = component.getActionMap();
        return localMap.get(key);
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * Registers the keystroke of the given action as "command" of the given
 * component.//from www. j a v  a2s  .c  o m
 * <p>
 * This code is based on the Sulky-tools, found at
 * &lt;http://github.com/huxi/sulky&gt;.
 * </p>
 * 
 * @param aComponent
 *          the component that should react on the keystroke, cannot be
 *          <code>null</code>;
 * @param aAction
 *          the action of the keystroke, cannot be <code>null</code>;
 * @param aCommandName
 *          the name of the command to register the keystore under.
 */
public static void registerKeystroke(final JComponent aComponent, final Action aAction,
        final String aCommandName) {
    final KeyStroke keyStroke = (KeyStroke) aAction.getValue(Action.ACCELERATOR_KEY);
    if (keyStroke == null) {
        return;
    }

    InputMap inputMap = aComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = aComponent.getActionMap();
    inputMap.put(keyStroke, aCommandName);
    actionMap.put(aCommandName, aAction);

    inputMap = aComponent.getInputMap(JComponent.WHEN_FOCUSED);
    Object value = inputMap.get(keyStroke);
    if (value != null) {
        inputMap.put(keyStroke, aCommandName);
    }

    inputMap = aComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    value = inputMap.get(keyStroke);
    if (value != null) {
        inputMap.put(keyStroke, aCommandName);
    }
}

From source file:Main.java

static void list(InputMap map, KeyStroke[] keys) {
    if (keys == null) {
        return;//from  w  ww .j a  v a 2 s .co  m
    }
    for (int i = 0; i < keys.length; i++) {
        keyStroke2String(keys[i]);
        while (map.get(keys[i]) == null) {
            map = map.getParent();
        }
        if (map.get(keys[i]) instanceof String) {
            String actionName = (String) map.get(keys[i]);
        } else {
            Action action = (Action) map.get(keys[i]);
        }
    }
}

From source file:Main.java

static void list(InputMap map, KeyStroke[] keys) {
    if (keys == null) {
        return;// w  w  w . j av a 2 s.co m
    }
    for (int i = 0; i < keys.length; i++) {
        keyStroke2String(keys[i]);
        while (map.get(keys[i]) == null) {
            map = map.getParent();
        }
        if (map.get(keys[i]) instanceof String) {
            String actionName = (String) map.get(keys[i]);
            System.out.println(actionName);
        } else {
            Action action = (Action) map.get(keys[i]);
            System.out.println(action);
        }
    }
}

From source file:com.limegroup.gnutella.gui.GUIUtils.java

/**
 * Moves the action for the specified character from the 'ctrl' mask
 * to the 'meta' mask.// w ww  .j  a va 2 s . c  o  m
 */
private static void replaceAction(InputMap map, char c) {
    KeyStroke ctrl = KeyStroke.getKeyStroke("control pressed " + c);
    KeyStroke meta = KeyStroke.getKeyStroke("meta pressed " + c);
    if (ctrl == null || meta == null)
        return;
    Object action = map.get(ctrl);
    if (action != null) {
        map.remove(ctrl);
        map.put(meta, action);
    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Set the tab and return behavior for a table.
 *///from   w  w  w  .  j a va 2 s  .co m
private void setupTabReturnBehavior(final JTable table) {
    final InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    // Have the enter key work the same as the tab key
    final KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    final KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    im.put(enter, im.get(tab));

    // Override the default tab behavior
    // Tab to the next editable cell. When no editable cells goto next cell.
    final Action oldTabAction = table.getActionMap().get(im.get(tab));
    final Action tabAction = new AbstractAction() {
        public void actionPerformed(final ActionEvent e) {
            if (null != oldTabAction) {
                oldTabAction.actionPerformed(e);
            }

            final JTable table = (JTable) e.getSource();
            final int rowCount = table.getRowCount();
            final int columnCount = table.getColumnCount();
            int row = table.getSelectedRow();
            int column = table.getSelectedColumn();

            // skip the no show when tabbing
            while (!table.isCellEditable(row, column) || table.getColumnClass(column) == Boolean.class) {
                column += 1;

                if (column == columnCount) {
                    column = 0;
                    row += 1;
                }

                if (row == rowCount) {
                    row = 0;
                }

                // Back to where we started, get out.
                if (row == table.getSelectedRow() && column == table.getSelectedColumn()) {
                    break;
                }
            }

            table.changeSelection(row, column, false, false);
        }
    };
    table.getActionMap().put(im.get(tab), tabAction);
}

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

private void removeWindowsF10() {
    InputMap imap = menuBar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    Object action = imap.get(KeyStroke.getKeyStroke("F10"));
    if (log.isInfoEnabled())
        log.info("Removing the F10 key from the menuBar's InputMap; it did " + (action == null ? "not" : "")
                + " exist");
    ActionMap amap = menuBar.getActionMap();
    amap.getParent().remove(action);/*from  w ww .  j a  v  a 2  s  .  c  o m*/
}