Example usage for javax.swing JComponent setInputMap

List of usage examples for javax.swing JComponent setInputMap

Introduction

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

Prototype

public final void setInputMap(int condition, InputMap map) 

Source Link

Document

Sets the InputMap to use under the condition condition to map.

Usage

From source file:Main.java

public static InputMap installInputMap(JComponent c, InputMap map, int condition) {
    if (map == null) {
        return null;
    }// ww  w.j  a v  a2  s .  co  m

    InputMap currentMap = c.getInputMap(condition);
    if (currentMap != null) {
        InputMap parent = currentMap;
        while (parent.getParent() != null) {
            parent = parent.getParent();
        }
        parent.setParent(map);
    } else {
        c.setInputMap(condition, map);
    }
    return map;
}

From source file:Main.java

public static void updateMnemonic(JComponent c, int oldKey, int newKey) {
    if (oldKey == newKey) {
        return;/*from   w  w  w  . j a  va  2  s . c  o m*/
    }

    InputMap map = c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (map != null && oldKey != 0) {
        map.remove(KeyStroke.getKeyStroke(oldKey, KeyEvent.ALT_MASK));
    }
    if (newKey != 0) {
        if (map == null) {
            map = new ComponentInputMap(c);
            c.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, map);
        }
        map.put(KeyStroke.getKeyStroke(newKey, KeyEvent.ALT_MASK), "press");
    }
}

From source file:Main.java

public static void updateToggleMnemonic(JComponent c, int oldKey, int newKey) {
    if (oldKey == newKey) {
        return;//from  w ww .j a  v a 2s  . co m
    }

    InputMap map = c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (map != null && oldKey != 0) {
        map.remove(KeyStroke.getKeyStroke(oldKey, KeyEvent.ALT_MASK, false));
        map.remove(KeyStroke.getKeyStroke(oldKey, KeyEvent.ALT_MASK, true));
        map.remove(KeyStroke.getKeyStroke(oldKey, KeyEvent.VK_UNDEFINED, true));
    }
    if (newKey != 0) {
        if (map == null) {
            map = new ComponentInputMap(c);
            c.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, map);
        }
        map.put(KeyStroke.getKeyStroke(newKey, KeyEvent.ALT_MASK, false), "press");
        map.put(KeyStroke.getKeyStroke(newKey, KeyEvent.ALT_MASK, true), "release");
        map.put(KeyStroke.getKeyStroke(newKey, KeyEvent.VK_UNDEFINED, true), "release");
    }
}

From source file:Main.java

public static void uninstallInputMap(JComponent c, InputMap map, int condition) {
    if (map == null) {
        return;//from  www.  j  a  va2 s .  c o  m
    }

    InputMap firstMap = c.getInputMap(condition);
    InputMap parent = firstMap;
    InputMap child = null;
    InputMap newMap = null;
    while (parent != null) {
        if (parent == map) {
            if (child != null) {
                child.setParent(parent.getParent());
                child = parent;
            } else {
                newMap = parent.getParent();
            }
        } else {
            child = parent;
        }
        parent = parent.getParent();
    }

    if (newMap != null) {
        c.setInputMap(condition, newMap);
    }
}

From source file:pcgen.gui2.PCGenFrame.java

private void initComponents() {
    setLayout(new BorderLayout());

    JComponent root = getRootPane();
    root.setActionMap(actionMap);//from   w  w  w  . j av a 2s  .  c  o m
    root.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, createInputMap(actionMap));

    characterTabs.add(new InfoGuidePane(this, uiContext));
    setJMenuBar(new PCGenMenuBar(this, uiContext));
    add(new PCGenToolBar(this), BorderLayout.NORTH);
    add(characterTabs, BorderLayout.CENTER);
    add(statusBar, BorderLayout.SOUTH);
    updateTitle();
    setIconImage(Icons.PCGenApp.getImageIcon().getImage());
}