Didn't send the patch, here it is.

On Thu, 2005-10-20 at 15:02 -0400, Anthony Balkissoon wrote:
> This patch implements the stubbed methods loadKeyBindings, makeInputMap,
> makeComponentInputMap, and makeKeyBindings in javax.swing.LookAndFeel.
> 
> I also noticed that a previous problem we had with improper modifiers
> being sent with KeyEvents was fixed so I removed the private method
> convertModifiers from BasicListUI and BasicTableUI and cleaned up the
> code in installKeyBoardActions in both of those files.
> 
> 2005-10-20  Anthony Balkissoon  <[EMAIL PROTECTED]>
> 
>       * javax/swing/LookAndFeel.java:
>       (loadKeyBindings): Implemented and added docs.
>       (makeComponentInputMap): Likewise.
>       (makeInputMap): Likewise.
>       (makeKeyBindings): Likewise.
>       * javax/swing/plaf/basic/BasicListUI.java:
>       (convertModifiers): Removed this no longer needed private method.
>       (installKeyboardActions): Removed the code relating to modifier
>       conversion and made code more readable by using local variables.
>       * javax/swing/plaf/basic/BasicTableUI.java:
>       (convertModifiers): Removed this no longer needed private method.
>       (installKeyboardActions): Removed the code relating to modifier
>       conversion and made code more readbale by using local variables.
> 
> --Tony
> 
> 
> 
> _______________________________________________
> Classpath-patches mailing list
> Classpath-patches@gnu.org
> http://lists.gnu.org/mailman/listinfo/classpath-patches
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.  <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 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.  
+   * <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
    */
   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. 
+   * <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 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.
+   * <code>keyBindingList</code> 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 [EMAIL PROTECTED] 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
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to