classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] Patch: large patch implements menu accelerators


From: Anthony Balkissoon
Subject: [cp-patches] Patch: large patch implements menu accelerators
Date: Mon, 14 Nov 2005 15:49:51 -0500

This rather large patch makes menu accelerators work in our
implementation.  Attached is a demo (MenuBars.java) - while focused in
the JButton pressing CTRL + {1,2,3,4,Z,X,C,V} causes different menu
items from either the top or bottom menu to be "clicked".

The patches to ActionMap and InputMap now make the following Mauve tests
pass:
gnu/testlet/javax/swing/InputMap/newMapKeysNull
gnu/testlet/javax/swing/ActionMap/newMapKeysNull

and they also fix PR 24854.

For JMenuBar, I removed the FIXME comment in addNotify and did what it
said - register the JMenuBar with the KeyboardManager.  This is because
the KeyboardManager needs to have a fast way to access all the JMenuBars
in a top-level container to give them a chance to consume any key event
that happens in that container (JMenuBars are the LAST things that get a
chance at the event).  Also, JMenuBar.processKeyBinding now overrides
the method in JComponent (this agrees with the API docs) to give all its
MenuElement descendants a chance to process the binding.

JMenuItem.setAccelerator had to fire a property change event that is
handled in BasicMenuItemUI so that when you change the accelerator key
for a menuitem, its key bindings get changed accordingly (the old one
gets thrown out and the new one gets mapped propertly).  

In KeyboardManager I put the new functionality it for registering
JMenuBars and also avoided some NPEs with standard != null checks.
Also, processKeyStroke now gives the JMenuBars a chance to consume the
event. Note that KeyboardManager currently only has the ability to
REGISTER bindings and JMenuBars, and not UNREGISTER them.  This is an
obvious flaw that I'll get to fixing at some point.

Finally, in BasicMenuItemUI I implemented a PropertyChangeListener to
change the bindings for the accelerator keystroke, and implemented the
installKeyboardActions and uninstallKeyboardActions methods.  Also made
sure that installUI calls installKeyboardActions and that
installListeners and uninstallListeners now reference the new
PropertyChangeListener.

2005-11-14  Anthony Balkissoon  <address@hidden>

        * javax/swing/ActionMap.java: 
        (keys): Return null if the map is empty.
        (allKeys): Likewise.
        * javax/swing/InputMap.java:
        (keys): Return null if the map is empty.
        (allKeys): Likewise.
        * javax/swing/JMenuBar:
        (addNotify): Register the menu with the KeyboardManager.
        (processKeyBinding): New API method.
        (processKeyBindingHelper): New implementation method.
        * javax/swing/JMenuItem.java:
        (setAccelerator): Fire a PropertyChangeEvent after changing the 
        accelerator.
        * javax/swing/KeyboardManager.java:
        (menuBarLookup): New field, Hashtable mapping between top-level 
        containers and a Vector of the JMenuBars contained in them.
        (getHashtableForTopLevel): Changed this public method to package
        private.
        (registerEntireMap): Avoid NPE by returning early if the parameter
        is null or contains no mappings.
        (processKeyStroke): If the mapped component doesn't consume the event,
        let all JMenuBars in the top-level container have a chance at it.
        (getVectorForTopLevel): New implementation method.
        (registerJMenuBar): Likewise.
        * javax/swing/plaf/basic/BasicMenuItemUI.java:
        (propertyChangeListener): New field.
        (PropertyChangeHandler): New class to handle PropertyChangeEvents on 
        the JMenuItem.
        (ClickAction): New class to implement accelerator key handling.
        (BasicMenuItemUI<init>): Instantiate the propertyChangeListener field.
        (installKeyboardActions): Implemented.
        (installListeners): Install the propertyChangeListener.
        (installUI): Call installKeyboardAcions after installing the listeners.
        (uninstallKeyboardActions): Implemented.
        (uninstallListeners): Remove the propertyChangeListener.

--Tony

Attachment: MenuAccelerators.diff
Description: Text Data

Attachment: MenuBars.java
Description: Text Data


reply via email to

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