/** * Installs look and feel keyboard actions on the root pane. * * @param rp the root pane to install the keyboard actions to */ protected void installKeyboardActions(JRootPane rp) { // Install the keyboard actions. ActionMapUIResource am = new ActionMapUIResource(); am.put("press", new DefaultPressAction(rp)); am.put("release", new DefaultReleaseAction(rp)); SwingUtilities.replaceUIActionMap(rp, am); // Install the input map from the UIManager. It seems like the actual // bindings are installed in the JRootPane only when the defaultButton // property receives a value. So we also only install an empty // input map here, and fill it in propertyChange. ComponentInputMapUIResource im = new ComponentInputMapUIResource(rp); SwingUtilities.replaceUIInputMap(rp, JComponent.WHEN_IN_FOCUSED_WINDOW, im); }
/** * Installs the state needed for mnemonics. */ private void initMnemonics() { mnemonicToIndexMap = new Hashtable<Integer, Integer>(); mnemonicInputMap = new ComponentInputMapUIResource(tabbedPane); mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabbedPane, JComponent.WHEN_IN_FOCUSED_WINDOW)); SwingUtilities.replaceUIInputMap(tabbedPane, JComponent.WHEN_IN_FOCUSED_WINDOW, mnemonicInputMap); }
public void testMakeComponentInputMap() { Object[] keys = new Object[] { "SPACE", "pressed" }; JButton button = new JButton(); ComponentInputMap componentInputMap = LookAndFeel.makeComponentInputMap(button, keys); assertTrue(componentInputMap instanceof ComponentInputMapUIResource); assertTrue(componentInputMap.getComponent() instanceof JButton); assertEquals(button, componentInputMap.getComponent()); assertEquals(1, componentInputMap.size()); }
public static ComponentInputMap makeComponentInputMap(final JComponent comp, final Object[] keys) { ComponentInputMapUIResource result = new ComponentInputMapUIResource(comp); loadKeyBindings(result, keys); return result; }
/** * Creates a ComponentInputMap from keys. * <code>keys</code> describes the InputMap, every even indexed * item is either a KeyStroke or a String representing a KeyStroke and every * odd indexed item is the Object associated with that KeyStroke in an * ActionMap. * * @param c the JComponent associated with the ComponentInputMap * @param keys the Object array describing the InputMap as above * * @return A new input map. */ public static ComponentInputMap makeComponentInputMap(JComponent c, Object[] keys) { ComponentInputMap retMap = new ComponentInputMapUIResource(c); loadKeyBindings(retMap, keys); return retMap; }