Example usage for javax.swing InputMap setParent

List of usage examples for javax.swing InputMap setParent

Introduction

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

Prototype

public void setParent(InputMap map) 

Source Link

Document

Sets this InputMap 's parent.

Usage

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);

}

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);

    inputMap.clear();// w  w w. j  a v  a2 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.getParent());

}

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.size());

}

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.allKeys().length);

}

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 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.keys().length);

}

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);

    inputMap.remove(KeyStroke.getKeyStroke("F2"));

}

From source file:Main.java

public static InputMap installInputMap(JComponent c, InputMap map, int condition) {
    if (map == null) {
        return null;
    }/*from   w  ww  .  j  a  v  a  2  s. com*/

    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 uninstallInputMap(JComponent c, InputMap map, int condition) {
    if (map == null) {
        return;/* ww  w . j av  a  2s  .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);
    }
}