/** * Get the InputMap to use for the UI.<p> * * This method is not named <code>getInputMap()</code> because there is * a package-private method in <code>BasicTextAreaUI</code> with that name. * Thus, creating a new method with that name causes certain compilers to * issue warnings that you are not actually overriding the original method * (since it is package-private). */ @Override protected InputMap getRTextAreaInputMap() { InputMap map = new InputMapUIResource(); InputMap shared = (InputMap)UIManager.get(SHARED_INPUT_MAP_NAME); if (shared==null) { shared = new RSyntaxTextAreaDefaultInputMap(); UIManager.put(SHARED_INPUT_MAP_NAME, shared); } //KeyStroke[] keys = shared.allKeys(); //for (int i=0; i<keys.length; i++) // System.err.println(keys[i] + " -> " + shared.get(keys[i])); map.setParent(shared); return map; }
/** * Installs the state needed for mnemonics. */ private void initMnemonics() { mnemonicToIndexMap = new Hashtable<Integer, Integer>(); mnemonicInputMap = new InputMapUIResource(); mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)); SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, mnemonicInputMap); }
public Object createValue(UIDefaults table) { InputMapUIResource im = new InputMapUIResource(); for (int i = 0; 2 * i + 1 < bind.length; ++i) { Object curr = bind[2 * i]; if (curr instanceof KeyStroke) im.put((KeyStroke) curr, bind[2 * i + 1]); else im.put(KeyStroke.getKeyStroke((String) curr), bind[2 * i + 1]); } return im; }
/** * Gets the input map for the specified <code>condition</code>. * * @return the InputMap for the specified condition */ private InputMap getInputMap() { InputMap im = new InputMapUIResource(); String prefix = getPropertyPrefix(); InputMap shared = (InputMap) SharedUIDefaults.get(prefix + ".focusInputMap"); if (shared != null) im.setParent(shared); return im; }
/** * Get the InputMap to use for the UI. * <p> * * This method is not named <code>getInputMap()</code> because there is a package-private method in * <code>BasicTextAreaUI</code> with that name. Thus, creating a new method with that name causes certain compilers * to issue warnings that you are not actually overriding the original method (since it is package-private). */ protected InputMap getRTextAreaInputMap() { InputMap map = new InputMapUIResource(); InputMap shared = (InputMap) UIManager.get(SHARED_INPUT_MAP_NAME); if (shared == null) { shared = new RSyntaxTextAreaDefaultInputMap(); UIManager.put(SHARED_INPUT_MAP_NAME, shared); } // KeyStroke[] keys = shared.allKeys(); // for (int i=0; i<keys.length; i++) // System.err.println(keys[i] + " -> " + shared.get(keys[i])); map.setParent(shared); return map; }
/** * A hack to work around swing hard coding key bindings, and providing * no reasonable way to access the native ones. Add new components and * key bindings here when mac users report them. * * @param table A mess of all UI defaults crammed in one hash map */ private void restoreSystemKeymaps(UIDefaults table) { /* * Input mappings that need to be tuned. the list is not exhaustive and * will likely need more entries when new components start to be used. */ String[] keys = { "EditorPane.focusInputMap", "FormattedTextField.focusInputMap", "PasswordField.focusInputMap", "TextArea.focusInputMap", "TextField.focusInputMap", "TextPane.focusInputMap" }; // Native modifier key. Ctrl for others, cmd on mac int modifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); for (String key : keys) { Object value = table.get(key); if (value instanceof InputMapUIResource) { InputMapUIResource map = (InputMapUIResource) value; // CUT remapKey(map, KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK, modifier); // COPY remapKey(map, KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK, modifier); // PASTE remapKey(map, KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK, modifier); // SELECT ALL remapKey(map, KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK, modifier); } else { Logger.getLogger(StyledLookAndFeel.class).error("Can not modify resource: " + key); } } }
/** * Remap a swing default key binding to a native one, if needed. * * @param map keymap to be modified * @param key * @param defaultModifier swing default modifier key for the action * @param nativeModifier native modifier key for the action */ private void remapKey(InputMapUIResource map, int key, int defaultModifier, int nativeModifier) { KeyStroke defaultKey = KeyStroke.getKeyStroke(key, defaultModifier); Object action = map.get(defaultKey); KeyStroke nativeKey = KeyStroke.getKeyStroke(key, nativeModifier); if (!nativeKey.equals(defaultKey)) { map.remove(defaultKey); map.put(nativeKey, action); } }
public static void listFocusInputMap(String component) { InputMapUIResource iomap = (InputMapUIResource)UIManager.get(component); KeyStroke[] keys = iomap.keys(); for (KeyStroke keyStroke : keys) { cat.debug("Component"+component+":"); cat.debug(" "+keyStroke+" -> "+iomap.get(keyStroke)+""); } }
final void installUIInputMap() { String propertyName = addPrefix(".focusInputMap"); InputMapUIResource inputMap1 = new InputMapUIResource(); InputMapUIResource inputMap2 = (InputMapUIResource)UIManager .get(propertyName); inputMap1.setParent(inputMap2); SwingUtilities.replaceUIInputMap(component, JComponent.WHEN_FOCUSED, inputMap1); }
public void testInputMap() { uiDefaults.put("1", new UIDefaults.LazyInputMap(new Object[] { "1", "11", "2", "22", "3", "33", "4", "44" })); assertTrue(uiDefaults.get("1") instanceof InputMapUIResource); InputMapUIResource map = (InputMapUIResource) uiDefaults.get("1"); assertEquals(4, map.allKeys().length); }
@Override protected void setUp() throws Exception { super.setUp(); ui = new BasicButtonUI(); previousBorder = UIManager.getBorder("Button.border"); uiInputMap = new InputMapUIResource(); uiInputMap.put(KeyStroke.getKeyStroke("SPACE"), "pressed"); uiInputMap.put(KeyStroke.getKeyStroke("released SPACE"), "released"); uiInputMap.put(KeyStroke.getKeyStroke("ENTER"), "pressed"); uiInputMap.put(KeyStroke.getKeyStroke("released ENTER"), "released"); }
public void testInstallKeyboardActions() throws Exception { ((BasicTextUI) jta.getUI()).uninstallKeyboardActions(); assertEquals(0, getInputMap(0).size()); assertFalse(getInputMap(0) instanceof InputMapUIResource); assertEquals(0, getInputMap(1).size()); assertTrue(getInputMap(1) instanceof InputMapUIResource); //assertEquals(55, jta.getInputMap().getParent().getParent().size());1.5.0 assertTrue(getInputMap(2) instanceof InputMapUIResource); assertNull(getInputMap(3)); assertEquals(0, getActionMap(0).size()); assertFalse(getActionMap(0) instanceof ActionMapUIResource); assertNull(getActionMap(1)); assertNull(jta.getKeymap()); ((BasicTextUI) jta.getUI()).installKeyboardActions(); assertNotNull(jta.getKeymap()); assertEquals(getKeymapName(jta), jta.getKeymap().getName()); assertEquals(0, getInputMap(0).size()); assertEquals(0, getInputMap(1).size()); assertEquals(0, getInputMap(2).size()); //assertEquals(55, jta.getInputMap().getParent().getParent().getParent() // .size()); //1.5.0 assertNull(getInputMap(4)); assertEquals(0, getActionMap(0).size()); assertEquals(1, getActionMap(1).size()); //Note //assertEquals(2,jta.getActionMap().getParent().getParent().size()); assertEquals(56, getActionMap(3).size()); assertNull(getActionMap(4)); assertFalse(getInputMap(0) instanceof InputMapUIResource); assertFalse(getInputMap(1) instanceof InputMapUIResource); assertTrue(getInputMap(2) instanceof InputMapUIResource); assertTrue(getInputMap(3) instanceof InputMapUIResource); assertFalse(getActionMap(0) instanceof ActionMapUIResource); assertFalse(getActionMap(1) instanceof ActionMapUIResource); assertTrue(getActionMap(2) instanceof ActionMapUIResource); assertTrue(getActionMap(3) instanceof ActionMapUIResource); }
/** * Get the InputMap to use for the UI.<p> * * This method is not named <code>getInputMap()</code> because there is * a package-private method in <code>BasicTextAreaUI</code> with that name. * Thus, creating a new method with that name causes certain compilers to * issue warnings that you are not actually overriding the original method * (since it is package-private). */ protected InputMap getRTextAreaInputMap() { InputMap map = new InputMapUIResource(); InputMap shared = (InputMap)UIManager.get(SHARED_INPUT_MAP_NAME); if (shared==null) { shared = new RSyntaxTextAreaDefaultInputMap(); UIManager.put(SHARED_INPUT_MAP_NAME, shared); } //KeyStroke[] keys = shared.allKeys(); //for (int i=0; i<keys.length; i++) // System.err.println(keys[i] + " -> " + shared.get(keys[i])); map.setParent(shared); return map; }
protected void initLookAndFeelDefaults() { InputMapUIResource inputMap = (InputMapUIResource) UIManager.getLookAndFeelDefaults().get("FormattedTextField.focusInputMap"); inputMap.remove(KeyStroke.getKeyStroke("ESCAPE")); }
/** * <p>Change the shared, UI-managed {@link InputMap} for a given * component. InputMaps are arranged in a hierarchy, in order to * encourage sharing of common input mappings between components. The * hierarchy unfortunately places UI-managed InputMaps at the * <em>end</em> of the parent-pointer chain, as illustrated:</p> * * <pre> * [{@link javax.swing.JComponent#getInputMap()}] * --> [{@link javax.swing.InputMap}] * parent --> [{@link javax.swing.text.JTextComponent.KeymapWrapper}] * parent --> [{@link javax.swing.plaf.InputMapUIResource}] * </pre> * * <p>Our goal with this method is to replace the first InputMap along * this chain which is an instance of {@link InputMapUIResource}, since * these are the InputMaps which are supposed to be shared between * components.</p> * * <p>If the provided InputMap is <code>null</code>, we interpret the * call as a request to remove the UI-managed InputMap from the * component's InputMap parent chain.</p> */ public static void replaceUIInputMap(JComponent component, int condition, InputMap uiInputMap) { InputMap child = component.getInputMap(condition); if (child == null) component.setInputMap(condition, uiInputMap); else { InputMap parent = child.getParent(); while (parent != null && !(parent instanceof InputMapUIResource)) { child = parent; parent = parent.getParent(); } // Sanity check to avoid loops. if (child != uiInputMap) child.setParent(uiInputMap); } }
private static void fixCtrlShiftO(String component) { InputMapUIResource iomap = (InputMapUIResource)UIManager.get(component); KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK); iomap.put(keyStroke, null); }
protected InputMap getInputMap() { InputMap map = new InputMapUIResource(); return map; }
public static InputMap makeInputMap(final Object[] bindings) { InputMapUIResource result = new InputMapUIResource(); loadKeyBindings(result, bindings); return result; }
public void testMakeInputMap() { Object[] keys = new Object[] { "SPACE", "pressed" }; InputMap inputMap = LookAndFeel.makeInputMap(keys); assertTrue(inputMap instanceof InputMapUIResource); assertEquals(1, inputMap.size()); }