List of usage examples for javax.swing JComponent getInputMap
public final InputMap getInputMap(int condition)
InputMap
that is used during condition
. From source file:Main.java
public static void installAlternateCopyPaste(JComponent comp) { comp.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("shift INSERT"), "paste-from-clipboard"); comp.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("shift DELETE"), "cut-to-clipboard"); comp.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ctrl INSERT"), "copy-to-clipboard"); }
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
/** * // w w w . ja v a 2 s . c o m * @param comp * @param action * @param condition - see {@link JComponent} * (WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,WHEN_IN_FOCUSED_WINDOW) */ public static void registerKeyBoardAction(JComponent comp, Action action, int condition) { comp.getInputMap(condition).put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), action.getValue(Action.NAME)); comp.getActionMap().put(action.getValue(Action.NAME), 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 setKeyAction_WhenFocused(JComponent component, int keyCode, String actionIdString, Action action) {/*from w w w . ja v a2s.c o m*/ component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(keyCode, 0), actionIdString); component.getActionMap().put(actionIdString, action); }
From source file:Main.java
public static void refleshAction(JComponent com, KeyStroke keyStroke) { InputMap im = com.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); Object o = im.get(keyStroke); if (o == null) { im = com.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); o = im.get(keyStroke);/*from w ww. j a v a2s. c o m*/ } if (o != null) { Action a = com.getActionMap().get(o); a.setEnabled(a.isEnabled()); } }
From source file:Main.java
public static void setKeyAction_WhenInFocusedWindow(JComponent component, int keyCode, String actionIdString, Action action) {//from w w w .jav a2 s. co m component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(keyCode, 0), actionIdString); component.getActionMap().put(actionIdString, action); }
From source file:Main.java
/** * Adds a component action./*from ww w.ja v a 2 s .com*/ * * @param component * The compoennt to add the action to * @param action * The action to add */ public static void addComponentAction(final JComponent component, final Action action) { final InputMap imap = component .getInputMap(component.isFocusable() ? JComponent.WHEN_FOCUSED : JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap amap = component.getActionMap(); final KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); imap.put(ks, action.getValue(Action.NAME)); amap.put(action.getValue(Action.NAME), action); }
From source file:Main.java
public static void bindAction(JComponent aComponent, String aCommand, Action anAction, KeyStroke aKeyStroke) { aComponent.getInputMap(JComponent.WHEN_FOCUSED).put(aKeyStroke, aCommand); aComponent.getActionMap().put(aCommand, anAction); }