/** */ public ExTextField() { Font font = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN); setFont(font); // Do not override getActions() method, because it is has side effect: propogates these actions to defaults. final Action[] actions = ExEditorKit.getInstance().getActions(); final ActionMap actionMap = getActionMap(); for (Action a : actions) { actionMap.put(a.getValue(Action.NAME), a); //System.out.println(" " + a.getValue(Action.NAME)); } setInputMap(WHEN_FOCUSED, new InputMap()); Keymap map = addKeymap("ex", getKeymap()); loadKeymap(map, ExKeyBindings.getBindings(), actions); map.setDefaultAction(new ExEditorKit.DefaultExKeyHandler()); setKeymap(map); addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { setCaretPosition(getText().length()); } @Override public void focusLost(FocusEvent e) { } }); //origCaret = getCaret(); //blockCaret = new BlockCaret(); }
@Override public InputMap getInputMap(int condition) { // SFrame has only one inputMap if (myInputMap == null) { myInputMap = new InputMap(); } return myInputMap; }
/** * Create empty leaf {@link InputMap} and {@link ActionMap}. */ public InputActionBindings() { this( new InputMap() ); }
protected InputMap getInputMap(int condition) { InputMap im = new InputMap(); im.put(KeyStroke.getKeyStroke("DELETE"), "delete"); return im; } }
// setting LAF InteractiveTestCase.setLAF("Nimbus"); // tweak inputMap, immediately after setting the ui is fine InputMap inputMap = (InputMap) UIManager.get("Button.focusInputMap"); InputMap custom = new InputMap(); if (inputMap != null) { // copy all bindings to custom ... } else { // add the binding we know of (as implementation detail) custom.put(KeyStroke.getKeyStroke("released SPACE"), "released"); } // overwrite the binding you want to change custom.put(KeyStroke.getKeyStroke("SPACE"), "do-nothing"); // set the custom map UIManager.put("Button.focusInputMap", custom);
public PerspectivesManager(SyDockingContext dockingContext) { super(); this.defaultActionMap = new ActionMap(); this.defaultInputMap = new InputMap(); this.dockingContext = dockingContext; UIManager.put("DockingDesktop.closeActionAccelerator", KeyStroke.getKeyStroke(87, InputEvent.CTRL_DOWN_MASK)); // ctrl + w }
private void removeDesktopPaneAccelerators() { final InputMap map = new InputMap(); rootWindow.setInputMap(JDesktopPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, map); }
/** * Construct with new, empty {@link InputMap} and {@link ActionMap}. Actions * that are added to these maps (using * {@link #namedAction(AbstractNamedAction, String...)}, * {@link #runnableAction(Runnable, String, String...)}) have their key * stroke triggers defined by the specified {@code keyConfig}. * * @param keyConfig * added actions have their key stroke triggers defined by the * specified {@code keyConfig}. (overrides default key strokes.) * @param keyConfigContexts * for which context names in the keyConfig should key strokes be * retrieved. */ public Actions( final KeyStrokeAdder.Factory keyConfig, final String ... keyConfigContexts ) { this( new InputMap(), new ActionMap(), keyConfig, keyConfigContexts ); }
private static InputMap createDefaultInputMap(InputMap parent) { InputMap map = new InputMap(); map.setParent(parent); bindKeyStrokesFromMainMenuShortcuts(map); // Add KeyStrokes: Enter, Ctrl+Enter (Cmd+Enter for MacOS) map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), KEY_GO_TO_NEXT_SEGMENT); map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), KEY_GO_TO_PREVIOUS_SEGMENT); return map; }
private static InputMap createDefaultInputMapUseTab(InputMap parent) { InputMap map = new InputMap(); map.setParent(parent); bindKeyStrokesFromMainMenuShortcuts(map); // Add KeyStrokes: Tab, Shift+Tab, Ctrl+Tab, Ctrl+Shift+Tab // (Cmd+Tab is used by the system on OS X) map.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), KEY_GO_TO_NEXT_SEGMENT); map.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK), KEY_GO_TO_PREVIOUS_SEGMENT); map.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK), KEY_TRANSFER_FOCUS); map.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK), KEY_TRANSFER_FOCUS_BACKWARD); // Enter to jump to selected segment in editor map.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), KEY_JUMP_TO_ENTRY_IN_EDITOR); return map; }
final JTextField myTextFiled=new JTextField(); JFrame frame=new JFrame("onlyNums"); KeyListener myKeyListner=new KeyListener() { @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub if(e.getKeyChar()>='0' && e.getKeyChar()<='9') myTextFiled.setText(myTextFiled.getText()+e.getKeyChar()); else if(e.getKeyChar()==KeyEvent.VK_BACK_SPACE && myTextFiled.getText().length()>0) myTextFiled.setText(myTextFiled.getText().substring(0, myTextFiled.getText().length()-1)); } @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } }; //to null out handling other inputs myTextFiled.setInputMap(JTextField.WHEN_FOCUSED, new InputMap()); //to add your own handling myTextFiled.addKeyListener(myKeyListner);
map = ( InputMap ) UIManager.get( "ScrollPane.ancestorInputMap" ); else map = new InputMap();
@Override public void installCG(SComponent component) { super.installCG(component); final STabbedPane tab = (STabbedPane) component; InputMap inputMap = new InputMap(); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK, false), "previous"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK, false), "next"); tab.setInputMap(SComponent.WHEN_FOCUSED_OR_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); Action action = new MyAbstractAction(tab); ActionMap actionMap = new ActionMap(); actionMap.put("previous", action); actionMap.put("next", action); tab.setActionMap(actionMap); }
/** * @param condition Either {@link #WHEN_FOCUSED_OR_ANCESTOR_OF_FOCUSED_COMPONENT} or {@link #WHEN_IN_FOCUSED_FRAME} * @return The input map for the given condition. * @see #setInputMap(int, javax.swing.InputMap) */ public InputMap getInputMap(int condition) { initInputMaps(); InputMap result = inputMaps[condition]; if (result == null) { inputMaps[condition] = new InputMap(); result = inputMaps[condition]; } registerGlobalInputMapWithFrame(); return result; }
private WidgetAction createActionMapAction(Page page) { InputMap inputMap = new InputMap(); ActionMap actionMap = new ActionMap(); Action[] actions = page.getActions(true); for (Action action : actions) { KeyStroke keyStroke = (KeyStroke) action.getValue(javax.swing.Action.ACCELERATOR_KEY); if (keyStroke != null) { inputMap.put(keyStroke, action.toString()); actionMap.put(action.toString(), action); } } if (actionMap.size() < 1) { return null; } /* Not sure if it is the right thing to create a new action map * should I be adding it? */ return new MyActionMapAction(inputMap, actionMap); //return ActionFactory.createActionMapAction(inputMap, actionMap); }
private void uninstallTracking() { InputMap currMap = SwingUtilities.getUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED); if (currMap != null) { InputMap newMap = new InputMap(); KeyStroke[] kss = currMap.allKeys(); for (int i = 0; i < kss.length; i++) { KeyStroke stroke = kss[i]; Object val = currMap.get(stroke); if (stroke .equals(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)) && "flipTextSelection".equals(val)) { continue; } newMap.put(stroke, val); } SwingUtilities.replaceUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED, newMap); } this.jcomp.getActionMap().remove("flipTextSelection"); }
/** * Associated the specified acion with key presses in the specified * compoent. * * @param component * @param theAction */ public static void setKeyCatcher(final JComponent component, final AbstractAction theAction) { InputMap oldInputMap = component .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); InputMap newInputMap = new InputMap(); newInputMap.setParent(oldInputMap); newInputMap.put(KeyStroke.getKeyStroke("F1"), "doSomething"); component.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, newInputMap); ActionMap oldActionMap = component.getActionMap(); ActionMap newActionMap = new ActionMap(); newActionMap.setParent(oldActionMap); newActionMap.put("doSomething", theAction); component.setActionMap(newActionMap); }
/** * Associated the specified acion with key presses in the specified * compoent. * * @param component * @param theAction */ public static void setKeyCatcher(final JComponent component, final AbstractAction theAction) { InputMap oldInputMap = component .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); InputMap newInputMap = new InputMap(); newInputMap.setParent(oldInputMap); newInputMap.put(KeyStroke.getKeyStroke("F1"), "doSomething"); component.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, newInputMap); ActionMap oldActionMap = component.getActionMap(); ActionMap newActionMap = new ActionMap(); newActionMap.setParent(oldActionMap); newActionMap.put("doSomething", theAction); component.setActionMap(newActionMap); }
public void testBindKeyStrokesInputMapObjectArr() { InputMap inputMap = new InputMap(); shortcuts.bindKeyStrokes(inputMap, TEST_SAVE, TEST_CUT, TEST_USER_1);