6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore
Reviewed-by: peterz
--- a/jdk/src/share/classes/javax/swing/plaf/basic/BasicMenuUI.java Mon Nov 15 19:50:09 2010 +0300
+++ b/jdk/src/share/classes/javax/swing/plaf/basic/BasicMenuUI.java Mon Nov 15 21:51:16 2010 -0800
@@ -196,6 +196,10 @@
return getHandler();
}
+ protected MenuKeyListener createMenuKeyListener(JComponent c) {
+ return (MenuKeyListener)getHandler();
+ }
+
public Dimension getMaximumSize(JComponent c) {
if (((JMenu)menuItem).isTopLevelMenu() == true) {
Dimension d = c.getPreferredSize();
@@ -397,7 +401,7 @@
public void stateChanged(ChangeEvent e) { }
}
- private class Handler extends BasicMenuItemUI.Handler {
+ private class Handler extends BasicMenuItemUI.Handler implements MenuKeyListener {
//
// PropertyChangeListener
//
@@ -580,5 +584,48 @@
}
public void menuDragMouseExited(MenuDragMouseEvent e) {}
public void menuDragMouseReleased(MenuDragMouseEvent e) {}
+
+ //
+ // MenuKeyListener
+ //
+ /**
+ * Open the Menu
+ */
+ public void menuKeyTyped(MenuKeyEvent e) {
+ if (!crossMenuMnemonic && BasicPopupMenuUI.getLastPopup() != null) {
+ // when crossMenuMnemonic is not set, we don't open a toplevel
+ // menu if another toplevel menu is already open
+ return;
+ }
+
+ if (BasicPopupMenuUI.getPopups().size() != 0) {
+ //Fix 6939261: to return in case not on the main menu
+ //and has a pop-up.
+ //after return code will be handled in BasicPopupMenuUI.java
+ return;
+ }
+
+ char key = Character.toLowerCase((char)menuItem.getMnemonic());
+ MenuElement path[] = e.getPath();
+ if (key == Character.toLowerCase(e.getKeyChar())) {
+ JPopupMenu popupMenu = ((JMenu)menuItem).getPopupMenu();
+ ArrayList newList = new ArrayList(Arrays.asList(path));
+ newList.add(popupMenu);
+ MenuElement subs[] = popupMenu.getSubElements();
+ MenuElement sub =
+ BasicPopupMenuUI.findEnabledChild(subs, -1, true);
+ if(sub != null) {
+ newList.add(sub);
+ }
+ MenuSelectionManager manager = e.getMenuSelectionManager();
+ MenuElement newPath[] = new MenuElement[0];;
+ newPath = (MenuElement[]) newList.toArray(newPath);
+ manager.setSelectedPath(newPath);
+ e.consume();
+ }
+ }
+
+ public void menuKeyPressed(MenuKeyEvent e) {}
+ public void menuKeyReleased(MenuKeyEvent e) {}
}
}