public Result testMakeComponentInputMap() { Object[] bindings = new Object[]{}; JComponent component = new JComponent() { }; try { ComponentInputMap map = LookAndFeel.makeComponentInputMap(component, bindings); checkForNull( map, "map created from zero-length array is not empty"); if (map.getComponent() != component) { return failed("wrong component in the map"); } bindings = new Object[]{KeyStroke.getKeyStroke('a'), new Object(), KeyStroke.getKeyStroke( 'b')}; try { LookAndFeel.makeComponentInputMap(component, bindings ); return failed("Expect an RuntimeException"); } catch (RuntimeException ee ) {} bindings = createBindings(); if (!checkIsSubset( bindings, buildBindings( LookAndFeel.makeComponentInputMap(component, bindings )))) { return failed("Failed to make input map"); } } catch (RuntimeException e) { // e.printStackTrace(); return failed("Unexpected exception of " + e.getClass()); } return passed(); }
public EuropeButton(String text, int keyEvent, String command, ActionListener listener) { setOpaque(true); setText(text); setActionCommand(command); addActionListener(listener); InputMap closeInputMap = new ComponentInputMap(this); closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, false), "pressed"); closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, true), "released"); SwingUtilities.replaceUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW, closeInputMap); enterPressesWhenFocused(this); }
private void filterInputMap(JComponent component, int condition) { InputMap imap = component.getInputMap(condition); if (imap instanceof ComponentInputMap) { imap = new F8FilterComponentInputMap(component, imap); } else { imap = new F8FilterInputMap(imap); } component.setInputMap(condition, imap); }
public EuropeButton(String text, int keyEvent, String command, ActionListener listener) { setOpaque(true); setText(text); setActionCommand(command); addActionListener(listener); InputMap closeInputMap = new ComponentInputMap(this); closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, false), "pressed"); closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, true), "released"); SwingUtilities.replaceUIInputMap(this, JComponent.WHEN_IN_FOCUSED_WINDOW, closeInputMap); }
public MapKeyboardController(PreviewMap map, boolean enabled) { super(map); inputMap = new ComponentInputMap(map); ActionMap actionMap = map.getActionMap(); // map moving inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, false), "MOVE_RIGHT"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false), "MOVE_LEFT"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false), "MOVE_UP"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false), "MOVE_DOWN"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, true), "STOP_MOVE_HORIZONTALLY"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, true), "STOP_MOVE_HORIZONTALLY"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, true), "STOP_MOVE_VERTICALLY"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, true), "STOP_MOVE_VERTICALLY"); // zooming. To avoid confusion about which modifier key to use, // we just add all keys left of the space bar inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_DOWN_MASK, false), "ZOOM_IN"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.META_DOWN_MASK, false), "ZOOM_IN"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK, false), "ZOOM_IN"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_DOWN_MASK, false), "ZOOM_OUT"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.META_DOWN_MASK, false), "ZOOM_OUT"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK, false), "ZOOM_OUT"); // map selection inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.CTRL_DOWN_MASK, false), "PREVIOUS_MAP"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.META_DOWN_MASK, false), "PREVIOUS_MAP"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.ALT_DOWN_MASK, false), "PREVIOUS_MAP"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.CTRL_DOWN_MASK, false), "NEXT_MAP"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.META_DOWN_MASK, false), "NEXT_MAP"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.ALT_DOWN_MASK, false), "NEXT_MAP"); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true), "REFRESH"); // action mapping actionMap.put("MOVE_RIGHT", new MoveRightAction()); actionMap.put("MOVE_LEFT", new MoveLeftAction()); actionMap.put("MOVE_UP", new MoveUpAction()); actionMap.put("MOVE_DOWN", new MoveDownAction()); actionMap.put("STOP_MOVE_HORIZONTALLY", new StopMoveHorizontallyAction()); actionMap.put("STOP_MOVE_VERTICALLY", new StopMoveVerticallyAction()); actionMap.put("ZOOM_IN", new ZoomInAction()); actionMap.put("ZOOM_OUT", new ZoomOutAction()); actionMap.put("NEXT_MAP", new NextMapAction()); actionMap.put("PREVIOUS_MAP", new PreviousMapAction()); actionMap.put("REFRESH", new RefreshAction()); if (enabled) enable(); }
@Override public void disable() { map.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, new ComponentInputMap(map)); }