提交 f90d6618 编写于 作者: V vikram

6939261: Since 1.6.0_18 JMenus at JMenuBar are not selectable by their Mnemonic key anymore

Reviewed-by: peterz
上级 ac631d5d
......@@ -196,6 +196,10 @@ public class BasicMenuUI extends BasicMenuItemUI
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 class BasicMenuUI extends BasicMenuItemUI
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 class BasicMenuUI extends BasicMenuItemUI
}
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) {}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册