List of usage examples for javax.swing JComponent getActionMap
public final ActionMap getActionMap()
ActionMap
used to determine what Action
to fire for particular KeyStroke
binding. From source file:Main.java
/** * Add an action to execute when the validation key (Enter) is pressed. * * @param field The field to validate./* ww w .j a va 2 s . c o m*/ * @param action The action to execute on validate. */ public static void addFieldValidateAction(JComponent field, Action action) { field.getActionMap().put("validate", action); field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "validate"); }
From source file:Main.java
public static void mapAction(JComponent c, int condition, Object key, KeyStroke keyStroke, Action action) { c.getActionMap().put(key, action); c.getInputMap(condition).put(keyStroke, key); }
From source file:Main.java
public static void installActions(JComponent comp, Action actions[], int condition) { ActionMap actionMap = comp.getActionMap(); InputMap inputMap = comp.getInputMap(condition); for (int i = 0; i < actions.length; i++) { String name = (String) actions[i].getValue(Action.NAME); actionMap.put(name, actions[i]); inputMap.put((KeyStroke) actions[i].getValue(Action.ACCELERATOR_KEY), name); }/*from ww w . j a va2 s. com*/ }
From source file:Main.java
public static ActionMap installActionMap(JComponent c, ActionMap map) { if (map == null) { return null; }/*w w w. j a v a2s . 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
public static void uninstallActionMap(JComponent c, ActionMap map) { if (map == null) { return;/* w ww. j a v a2s . co 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:Main.java
public static void addEnterAction(JComponent comp, Action action) { comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ENTER"), action); comp.getActionMap().put(action, action); }
From source file:Main.java
public static void addEscAction(JComponent comp, Action action) { comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), action); comp.getActionMap().put(action, action); }
From source file:Main.java
public static void addAction(JComponent component, String kstr, AbstractAction action) { KeyStroke ks = KeyStroke.getKeyStroke(kstr); component.getInputMap().put(ks, ks); component.getActionMap().put(ks, action); }
From source file:Main.java
public static void registerKeyBoardAction(JComponent comp, Action action, KeyStroke stroke) { comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, action.getValue(Action.NAME)); comp.getActionMap().put(action.getValue(Action.NAME), action); }
From source file:Main.java
public static void bind(JComponent table, Action deleteAction, int key) { KeyStroke delete = KeyStroke.getKeyStroke(key, 0); table.getInputMap().put(KeyStroke.getKeyStroke(key, 0), delete); table.getActionMap().put(table.getInputMap().get(KeyStroke.getKeyStroke(key, 0)), deleteAction); }