This patch makes our JMenu usage more compatible with the reference implementation. Oddly enough, calls to JMenu.setSelected will allow more than one menu in a menubar to be selected, so I wrote popupVisible to make clear the criteria for selecting a menu due to a mouse entered event.
Removing the check for !menu.isArmed is so that if a menu is selected but doesn't have its popup menu showing, and then receives a valid mouse entered event (while another menu is open), it will show its popup menu. Patch attached. 2005-07-11 Anthony Balkissoon <[EMAIL PROTECTED]> * javax/swing/plaf/basic/BasicMenuUI.java: (MouseHandler.popupVisible): new method. (MouseHandler.mouseEntered): Removed check for menu being armed to comply with reference implementation. Calls popupVisible to check for menus with their popup menu visible
Index: javax/swing/plaf/basic/BasicMenuUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicMenuUI.java,v retrieving revision 1.11 diff -u -r1.11 BasicMenuUI.java --- javax/swing/plaf/basic/BasicMenuUI.java 11 Jul 2005 18:07:15 -0000 1.11 +++ javax/swing/plaf/basic/BasicMenuUI.java 11 Jul 2005 19:09:53 -0000 @@ -292,6 +292,19 @@ manager.processMouseEvent(e); } + private boolean popupVisible() + { + JMenuBar mb = (JMenuBar) ((JMenu)menuItem).getParent(); + // check if mb.isSelected because if no menus are selected + // we don't have to look through the list for popup menus + if (!mb.isSelected()) + return false; + for (int i=0;i<mb.getMenuCount();i++) + if (((JMenu)mb.getComponent(i)).isPopupMenuVisible()) + return true; + return false; + } + public void mouseEntered(MouseEvent e) { /* When mouse enters menu item, it should be considered selected @@ -303,12 +316,15 @@ it will be selected) */ JMenu menu = (JMenu) menuItem; - JMenuBar mb = (JMenuBar) menu.getParent(); - if (! menu.isTopLevelMenu() - || (mb.isSelected() && (((JMenu)(mb.getComponent - (mb.getSelectionModel(). - getSelectedIndex()))). - isPopupMenuVisible()) && ! menu.isArmed())) + + // NOTE: the following if used to require !menu.isArmed but I could find + // no reason for this and it was preventing some JDK-compatible behaviour. + // Specifically, if a menu is selected but its popup menu not visible, + // and then another menu is selected whose popup menu IS visible, when + // the mouse is moved over the first menu, its popup menu should become + // visible. + + if (! menu.isTopLevelMenu() || popupVisible()) { // set new selection and forward this event to MenuSelectionManager MenuSelectionManager manager = MenuSelectionManager.defaultManager();
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches