Index: javax/swing/LookAndFeel.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/LookAndFeel.java,v retrieving revision 1.14 diff -u -r1.14 LookAndFeel.java --- javax/swing/LookAndFeel.java 19 Oct 2005 15:45:05 -0000 1.14 +++ javax/swing/LookAndFeel.java 20 Oct 2005 18:57:26 -0000 @@ -45,7 +45,9 @@ import java.net.URL; import javax.swing.border.Border; +import javax.swing.plaf.ComponentInputMapUIResource; import javax.swing.plaf.IconUIResource; +import javax.swing.plaf.InputMapUIResource; import javax.swing.plaf.UIResource; import javax.swing.text.JTextComponent; @@ -183,20 +185,47 @@ public abstract boolean isSupportedLookAndFeel(); /** - * Loads the bindings in keys into retMap. + * Loads the bindings in keys into retMap. Does not remove existing entries + * from retMap. keys 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 retMap the InputMap into which we load bindings + * @param keys the Object array describing the InputMap as above */ public static void loadKeyBindings(InputMap retMap, Object[] keys) { - // TODO: Implement this properly. + if (keys == null) + return; + for (int i = 0; i < keys.length - 1; i+= 2) + { + Object key = keys[i]; + KeyStroke keyStroke; + if (key instanceof KeyStroke) + keyStroke = (KeyStroke)key; + else + keyStroke = KeyStroke.getKeyStroke((String)key); + retMap.put(keyStroke, keys[i+1]); + } } /** - * Creates a ComponentInputMap from keys. + * Creates a ComponentInputMap from keys. + * keys 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 */ public static ComponentInputMap makeComponentInputMap(JComponent c, Object[] keys) { - return null; + ComponentInputMap retMap = new ComponentInputMapUIResource(c); + loadKeyBindings(retMap, keys); + return retMap; } /** @@ -217,18 +246,43 @@ /** * Creates a InputMap from keys. + * keys 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 keys the Object array describing the InputMap as above */ public static InputMap makeInputMap(Object[] keys) { - return null; + InputMap retMap = new InputMapUIResource(); + loadKeyBindings(retMap, keys); + return retMap; } /** - * Convenience method for building lists of KeyBindings. + * Convenience method for building lists of KeyBindings. + * keyBindingList is an array of KeyStroke-Action pairs where + * even indexed elements are KeyStrokes or Strings representing KeyStrokes + * and odd indexed elements are the associated Actions. + * + * @param keyBindingList the array of KeyStroke-Action pairs + * @return a JTextComponent.KeyBinding array */ public static JTextComponent.KeyBinding[] makeKeyBindings(Object[] keyBindingList) { - return null; + JTextComponent.KeyBinding[] retBindings = + new JTextComponent.KeyBinding[keyBindingList.length / 2]; + for (int i = 0; i < keyBindingList.length - 1; i+= 2) + { + KeyStroke stroke; + if (keyBindingList[i] instanceof KeyStroke) + stroke = (KeyStroke)keyBindingList[i]; + else + stroke = KeyStroke.getKeyStroke((String)keyBindingList[i]); + retBindings[i/2] = new JTextComponent.KeyBinding(stroke, (String)keyBindingList[i+1]); + } + return retBindings; } /** Index: javax/swing/plaf/basic/BasicListUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicListUI.java,v retrieving revision 1.35 diff -u -r1.35 BasicListUI.java --- javax/swing/plaf/basic/BasicListUI.java 18 Oct 2005 22:10:32 -0000 1.35 +++ javax/swing/plaf/basic/BasicListUI.java 20 Oct 2005 18:57:26 -0000 @@ -930,36 +930,6 @@ list.removeMouseMotionListener(mouseInputListener); list.removePropertyChangeListener(propertyChangeListener); } - - private int convertModifiers(int mod) - { - if ((mod & KeyEvent.SHIFT_DOWN_MASK) != 0) - { - mod |= KeyEvent.SHIFT_MASK; - mod &= ~KeyEvent.SHIFT_DOWN_MASK; - } - if ((mod & KeyEvent.CTRL_DOWN_MASK) != 0) - { - mod |= KeyEvent.CTRL_MASK; - mod &= ~KeyEvent.CTRL_DOWN_MASK; - } - if ((mod & KeyEvent.META_DOWN_MASK) != 0) - { - mod |= KeyEvent.META_MASK; - mod &= ~KeyEvent.META_DOWN_MASK; - } - if ((mod & KeyEvent.ALT_DOWN_MASK) != 0) - { - mod |= KeyEvent.ALT_MASK; - mod &= ~KeyEvent.ALT_DOWN_MASK; - } - if ((mod & KeyEvent.ALT_GRAPH_DOWN_MASK) != 0) - { - mod |= KeyEvent.ALT_GRAPH_MASK; - mod &= ~KeyEvent.ALT_GRAPH_DOWN_MASK; - } - return mod; - } /** * Installs keyboard actions for this UI in the address@hidden JList}. @@ -974,24 +944,19 @@ action = new ListAction(); Object keys[] = focusInputMap.allKeys(); // Register key bindings in the UI InputMap-ActionMap pair - // Note that we register key bindings with both the old and new modifier - // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on. for (int i = 0; i < keys.length; i++) { - parentInputMap.put(KeyStroke.getKeyStroke - (((KeyStroke)keys[i]).getKeyCode(), convertModifiers - (((KeyStroke)keys[i]).getModifiers())), - (String)focusInputMap.get((KeyStroke)keys[i])); - - parentInputMap.put(KeyStroke.getKeyStroke - (((KeyStroke)keys[i]).getKeyCode(), - ((KeyStroke)keys[i]).getModifiers()), - (String)focusInputMap.get((KeyStroke)keys[i])); + KeyStroke stroke = (KeyStroke)keys[i]; + String actionString = (String) focusInputMap.get(stroke); + parentInputMap.put(KeyStroke.getKeyStroke(stroke.getKeyCode(), + stroke.getModifiers()), + actionString); - parentActionMap.put - ((String)focusInputMap.get((KeyStroke)keys[i]), new ActionListenerProxy - (action, (String)focusInputMap.get((KeyStroke)keys[i]))); + parentActionMap.put (actionString, + new ActionListenerProxy(action, actionString)); } + // Register the new InputMap-ActionMap as the parents of the list's + // InputMap and ActionMap parentInputMap.setParent(list.getInputMap().getParent()); parentActionMap.setParent(list.getActionMap().getParent()); list.getInputMap().setParent(parentInputMap); Index: javax/swing/plaf/basic/BasicTableUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTableUI.java,v retrieving revision 1.33 diff -u -r1.33 BasicTableUI.java --- javax/swing/plaf/basic/BasicTableUI.java 18 Oct 2005 22:10:32 -0000 1.33 +++ javax/swing/plaf/basic/BasicTableUI.java 20 Oct 2005 18:57:26 -0000 @@ -335,36 +335,6 @@ rendererPane = new CellRendererPane(); } - private int convertModifiers(int mod) - { - if ((mod & KeyEvent.SHIFT_DOWN_MASK) != 0) - { - mod |= KeyEvent.SHIFT_MASK; - mod &= ~KeyEvent.SHIFT_DOWN_MASK; - } - if ((mod & KeyEvent.CTRL_DOWN_MASK) != 0) - { - mod |= KeyEvent.CTRL_MASK; - mod &= ~KeyEvent.CTRL_DOWN_MASK; - } - if ((mod & KeyEvent.META_DOWN_MASK) != 0) - { - mod |= KeyEvent.META_MASK; - mod &= ~KeyEvent.META_DOWN_MASK; - } - if ((mod & KeyEvent.ALT_DOWN_MASK) != 0) - { - mod |= KeyEvent.ALT_MASK; - mod &= ~KeyEvent.ALT_DOWN_MASK; - } - if ((mod & KeyEvent.ALT_GRAPH_DOWN_MASK) != 0) - { - mod |= KeyEvent.ALT_GRAPH_MASK; - mod &= ~KeyEvent.ALT_GRAPH_DOWN_MASK; - } - return mod; - } - protected void installKeyboardActions() { UIDefaults defaults = UIManager.getLookAndFeelDefaults(); @@ -375,23 +345,17 @@ action = new TableAction(); Object keys[] = ancestorMap.allKeys(); // Register key bindings in the UI InputMap-ActionMap pair - // Note that we register key bindings with both the old and new modifier - // masks: InputEvent.SHIFT_MASK and InputEvent.SHIFT_DOWN_MASK and so on. for (int i = 0; i < keys.length; i++) { - parentInputMap.put(KeyStroke.getKeyStroke - (((KeyStroke)keys[i]).getKeyCode(), convertModifiers - (((KeyStroke)keys[i]).getModifiers())), - (String)ancestorMap.get((KeyStroke)keys[i])); + KeyStroke stroke = (KeyStroke)keys[i]; + String actionString = (String) ancestorMap.get(stroke); - parentInputMap.put(KeyStroke.getKeyStroke - (((KeyStroke)keys[i]).getKeyCode(), - ((KeyStroke)keys[i]).getModifiers()), - (String)ancestorMap.get((KeyStroke)keys[i])); + parentInputMap.put(KeyStroke.getKeyStroke(stroke.getKeyCode(), + stroke.getModifiers()), + actionString); - parentActionMap.put - ((String)ancestorMap.get((KeyStroke)keys[i]), new ActionListenerProxy - (action, (String)ancestorMap.get((KeyStroke)keys[i]))); + parentActionMap.put (actionString, + new ActionListenerProxy (action, actionString)); } // Set the UI InputMap-ActionMap pair to be the parents of the