List of usage examples for javax.swing ActionMap getParent
public ActionMap getParent()
ActionMap
's parent. From source file:Main.java
public static void main(String args[]) { String ACTION_KEY = "The Action"; JFrame frame = new JFrame("KeyStroke Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton buttonA = new JButton("FOCUSED (control alt 7)"); JButton buttonB = new JButton("FOCUS/RELEASE (VK_ENTER)"); JButton buttonC = new JButton("ANCESTOR (VK_F4+SHIFT_MASK)"); JButton buttonD = new JButton("WINDOW (' ')"); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { JButton source = (JButton) actionEvent.getSource(); System.out.println("Activated: " + source.getText()); }/*from www .j a v a2 s .c o m*/ }; KeyStroke controlAlt7 = KeyStroke.getKeyStroke("control alt 7"); InputMap inputMap = buttonA.getInputMap(); inputMap.put(controlAlt7, ACTION_KEY); ActionMap actionMap = buttonA.getActionMap(); ActionMap newMap = new ActionMap(); newMap.setParent(actionMap); System.out.println(newMap.getParent()); actionMap.put(ACTION_KEY, actionListener); KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true); inputMap = buttonB.getInputMap(); inputMap.put(enter, ACTION_KEY); buttonB.setActionMap(actionMap); KeyStroke shiftF4 = KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.SHIFT_MASK); inputMap = buttonC.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(shiftF4, ACTION_KEY); buttonC.setActionMap(actionMap); KeyStroke space = KeyStroke.getKeyStroke(' '); inputMap = buttonD.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(space, ACTION_KEY); buttonD.setActionMap(actionMap); frame.setLayout(new GridLayout(2, 2)); frame.add(buttonA); frame.add(buttonB); frame.add(buttonC); frame.add(buttonD); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static ActionMap installActionMap(JComponent c, ActionMap map) { if (map == null) { return null; }/*from w w w . ja va2 s . c o m*/ ActionMap currentMap = c.getActionMap(); if (currentMap != null) { ActionMap parent = currentMap; while (parent.getParent() != null) { if (parent == map) { return map; } parent = parent.getParent(); } parent.setParent(map); } else { c.setActionMap(map); } return map; }
From source file:Main.java
static void list(ActionMap map, Object[] actionKeys) { if (actionKeys == null) { return;/*from ww w .j a v a2s . c om*/ } for (int i = 0; i < actionKeys.length; i++) { // Get the action bound to this action key while (map.get(actionKeys[i]) == null) { map = map.getParent(); } Action action = (Action) map.get(actionKeys[i]); } }
From source file:Main.java
public static void uninstallActionMap(JComponent c, ActionMap map) { if (map == null) { return;//from w w w . ja va 2 s . c o m } ActionMap firstMap = c.getActionMap(); ActionMap parent = firstMap; ActionMap child = null; ActionMap 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.setActionMap(newMap); } }
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); }