List of usage examples for javax.swing InputMap getParent
public 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.getParent()); }
From source file:Main.java
public static InputMap installInputMap(JComponent c, InputMap map, int condition) { if (map == null) { return null; }//from www .j av a 2s. c o 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 uninstallInputMap(JComponent c, InputMap map, int condition) { if (map == null) { return;//from w w w . j a va 2s . co 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:Main.java
static void list(InputMap map, KeyStroke[] keys) { if (keys == null) { return;/* w w w . j a va 2 s. com*/ } 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 .java 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:org.dishevelled.brainstorm.BrainStorm.java
/** * Initialize components./*from ww w .j a v a 2 s . com*/ */ private void initComponents() { Font font = new Font(chooseFontName(), Font.PLAIN, fontSize); hiddenCursor = createHiddenCursor(); textArea = new JTextArea() { /** {@inheritDoc} */ protected void paintComponent(final Graphics graphics) { Graphics2D g2 = (Graphics2D) graphics; g2.setRenderingHint(KEY_FRACTIONALMETRICS, VALUE_FRACTIONALMETRICS_ON); g2.setRenderingHint(KEY_TEXT_ANTIALIASING, VALUE_TEXT_ANTIALIAS_LCD_HRGB); super.paintComponent(g2); } }; textArea.setFont(font); textArea.setOpaque(true); textArea.setCursor(hiddenCursor); textArea.setBackground(backgroundColor); textArea.setForeground(textColor); textArea.setRows(rows); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); // clear all input mappings InputMap inputMap = textArea.getInputMap(); while (inputMap != null) { inputMap.clear(); inputMap = inputMap.getParent(); } // re-add select default input mappings textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "insert-break"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "insert-tab"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete-previous"); int keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, keyMask), "delete-previous-word"); // add new input mappings textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, keyMask), "increase-font-size"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, keyMask), "decrease-font-size"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask), "save"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "quit"); textArea.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, keyMask), "quit"); Action increaseFontSizeAction = new IncreaseFontSizeAction(); Action decreaseFontSizeAction = new DecreaseFontSizeAction(); Action saveAction = new SaveAction(); Action quitAction = new QuitAction(); textArea.getActionMap().put("increase-font-size", increaseFontSizeAction); textArea.getActionMap().put("decrease-font-size", decreaseFontSizeAction); textArea.getActionMap().put("save", saveAction); textArea.getActionMap().put("quit", quitAction); placeholder = Box.createGlue(); }