classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] RFC: JMenuItem null accelerators


From: Mark Wielaard
Subject: [cp-patches] RFC: JMenuItem null accelerators
Date: Wed, 04 Jan 2006 00:08:04 +0100

Hi,

At various points we try to register a null KeyStroke with an InputMap.
This gives some problems later on when InputMaps are copied because null
entries aren't always expected. Does the following patch make sense?

2006-01-03  Mark Wielaard  <address@hidden>

    * javax/swing/JMenuItem.java (configurePropertiesFromAction): Only
    register keyboard action when accelerator is not null.
    * javax/swing/plaf/basic/BasicMenuItemUI.java (propertyChange): Only
    re-register accelerator if not null.
    (installKeyboardActions): Only put accelerator in map when not null.

Cheers,

Mark
Index: javax/swing/JMenuItem.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JMenuItem.java,v
retrieving revision 1.24
diff -u -r1.24 JMenuItem.java
--- javax/swing/JMenuItem.java  3 Jan 2006 18:42:22 -0000       1.24
+++ javax/swing/JMenuItem.java  3 Jan 2006 23:01:29 -0000
@@ -280,8 +280,9 @@
     if (! (this instanceof JMenu) && action != null)
       {
         setAccelerator((KeyStroke) (action.getValue(Action.ACCELERATOR_KEY)));
-        super.registerKeyboardAction(action, accelerator, 
-                                     JComponent.WHEN_IN_FOCUSED_WINDOW);
+        if (accelerator != null)
+          super.registerKeyboardAction(action, accelerator, 
+                                       JComponent.WHEN_IN_FOCUSED_WINDOW);
       }
   }
 
Index: javax/swing/plaf/basic/BasicMenuItemUI.java
===================================================================
RCS file: 
/sources/classpath/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java,v
retrieving revision 1.41
diff -u -r1.41 BasicMenuItemUI.java
--- javax/swing/plaf/basic/BasicMenuItemUI.java 19 Dec 2005 15:05:04 -0000      
1.41
+++ javax/swing/plaf/basic/BasicMenuItemUI.java 3 Jan 2006 23:01:30 -0000
@@ -206,7 +206,10 @@
             map.remove((KeyStroke)e.getOldValue());
           else
             map = new ComponentInputMapUIResource(menuItem);
-          map.put((KeyStroke)e.getNewValue(), "doClick");
+
+          KeyStroke accelerator = (KeyStroke) e.getNewValue();
+          if (accelerator != null)
+            map.put(accelerator, "doClick");
         }
     }
   }
@@ -485,7 +488,9 @@
     InputMap focusedWindowMap = SwingUtilities.getUIInputMap(menuItem, 
JComponent.WHEN_IN_FOCUSED_WINDOW);
     if (focusedWindowMap == null)
       focusedWindowMap = new ComponentInputMapUIResource(menuItem);
-    focusedWindowMap.put(menuItem.getAccelerator(), "doClick");
+    KeyStroke accelerator = menuItem.getAccelerator();
+    if (accelerator != null)
+      focusedWindowMap.put(accelerator, "doClick");
     SwingUtilities.replaceUIInputMap(menuItem, 
JComponent.WHEN_IN_FOCUSED_WINDOW, focusedWindowMap);
     
     ActionMap UIActionMap = SwingUtilities.getUIActionMap(menuItem);

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]