I committed the patch I sent to the list earlier today which fixes bug
13683.
Second patch fixes BasicMenuUI's handling of MouseEntered events. To
comply with the JDK a top level menu shouldn't be selected upon a mouse
entered event unless there was a previously selected menu in the same
menubar and that menu had its popup menu visible. Previously we were
selecting it whether or not the popup menu was visible. This has been
committed.
Patches attached.
2005-07-11 Anthony Balkissoon <[EMAIL PROTECTED]>
* javax/swing/plaf/basic/BasicMenuUI.java:
(MouseInputHandler.mouseEntered): Added check: if a different menu in
the menubar was selected, we don't select this one unless the old one
had its popup menu showing. This complies with the reference
implementation.
2005-07-11 Anthony Balkissoon <[EMAIL PROTECTED]>
* javax/swing/JMenu.java:
(setSelectedHelper): new method.
(setSelected): Code moved to setSelectedHelper. Calls
setSelectedHelper(selected,true,false) which doesn't expand the popup
menu and works whether the menu is enabled or not.
(menuSelectionChanged): Changed call to setSelected(changed) to
setSelectedHelper(changed,isEnabled(),true) which does expand the
popup menu, but only if the menu is enabled.
-Tony
Index: javax/swing/JMenu.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JMenu.java,v
retrieving revision 1.18
diff -u -r1.18 JMenu.java
--- javax/swing/JMenu.java 8 Jul 2005 00:23:22 -0000 1.18
+++ javax/swing/JMenu.java 11 Jul 2005 16:59:10 -0000
@@ -332,52 +332,50 @@
}
/**
- * Changes this menu selected state if selected is true and false otherwise
- * This method fires menuEvents to menu's registered listeners.
- *
- * @param selected true if the menu should be selected and false otherwise
+ * A helper method to handle setSelected calls from both mouse events and
+ * direct calls to setSelected. Direct calls shouldn't expand the popup
+ * menu and should select the JMenu even if it is disabled. Mouse events
+ * only select the JMenu if it is enabled and should expand the popup menu
+ * associated with this JMenu.
+ * @param selected whether or not the JMenu was selected
+ * @param menuEnabled whether or not selecting the menu is "enabled". This
+ * is always true for direct calls, and is set to isEnabled() for mouse
+ * based calls.
+ * @param showMenu whether or not to show the popup menu
*/
- public void setSelected(boolean selected)
+ private void setSelectedHelper(boolean selected, boolean menuEnabled, boolean showMenu)
{
// If menu is selected and enabled, activates the menu and
// displays associated popup.
- if (selected && isEnabled())
+ if (selected && menuEnabled)
{
super.setArmed(true);
super.setSelected(true);
-
- // FIXME: The reference implementation behaves different here. When
- // calling setSelected(true) it will *not* open the popup but appear
- // selected. This is even true when the menu is disabled. Our
- // implementation will always open the popup (when enabled) and
- // will not appear selected when disabled.
-
- // FIXME: The popup menu should be shown on the screen after certain
- // number of seconds pass. The 'delay' property of this menu indicates
- // this amount of seconds. 'delay' property is 0 by default.
+
if (isShowing())
{
fireMenuSelected();
-
+
int x = 0;
int y = 0;
-
- if (menuLocation == null)
- {
- // Calculate correct position of the popup. Note that location of the popup
- // passed to show() should be relative to the popup's invoker
- if (isTopLevelMenu())
- y = this.getHeight();
- else
- x = this.getWidth();
-
- getPopupMenu().show(this, x, y);
- }
- else
- getPopupMenu().show(this, menuLocation.x, menuLocation.y);
+ if (showMenu)
+ if (menuLocation == null)
+ {
+ // Calculate correct position of the popup. Note that location of the popup
+ // passed to show() should be relative to the popup's invoker
+ if (isTopLevelMenu())
+ y = this.getHeight();
+ else
+ x = this.getWidth();
+ getPopupMenu().show(this, x, y);
+ }
+ else
+ {
+ getPopupMenu().show(this, menuLocation.x, menuLocation.y);
+ }
}
}
-
+
else
{
super.setSelected(false);
@@ -385,6 +383,18 @@
fireMenuDeselected();
popupMenu.setVisible(false);
}
+
+ }
+
+ /**
+ * Changes this menu selected state if selected is true and false otherwise
+ * This method fires menuEvents to menu's registered listeners.
+ *
+ * @param selected true if the menu should be selected and false otherwise
+ */
+ public void setSelected(boolean selected)
+ {
+ setSelectedHelper(selected, true, false);
}
/**
@@ -715,7 +725,7 @@
{
// if this menu selection is true, then activate this menu and
// display popup associated with this menu
- setSelected(changed);
+ setSelectedHelper(changed, isEnabled(), true);
}
/**
Index: javax/swing/plaf/basic/BasicMenuUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicMenuUI.java,v
retrieving revision 1.10
diff -u -r1.10 BasicMenuUI.java
--- javax/swing/plaf/basic/BasicMenuUI.java 8 Jul 2005 15:24:08 -0000 1.10
+++ javax/swing/plaf/basic/BasicMenuUI.java 11 Jul 2005 17:57:19 -0000
@@ -297,14 +297,18 @@
/* When mouse enters menu item, it should be considered selected
if (i) if this menu is a submenu in some other menu
- (ii) or if this menu is in a menu bar and some other menu in a menu bar was just
- selected. (If nothing was selected, menu should be pressed before
+ (ii) or if this menu is in a menu bar and some other menu in a
+ menu bar was just selected and has its popup menu visible.
+ (If nothing was selected, menu should be pressed before
it will be selected)
*/
JMenu menu = (JMenu) menuItem;
+ JMenuBar mb = (JMenuBar) menu.getParent();
if (! menu.isTopLevelMenu()
- || (menu.isTopLevelMenu()
- && (((JMenuBar) menu.getParent()).isSelected() && ! menu.isArmed())))
+ || (mb.isSelected() && (((JMenu)(mb.getComponent
+ (mb.getSelectionModel().
+ getSelectedIndex()))).
+ isPopupMenuVisible()) && ! menu.isArmed()))
{
// set new selection and forward this event to MenuSelectionManager
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches