< prev index next >
src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuUI.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 251,261 ****
timer.setRepeats(false);
timer.start();
}
private static void appendPath(MenuElement[] path, MenuElement elem) {
! MenuElement newPath[] = new MenuElement[path.length+1];
System.arraycopy(path, 0, newPath, 0, path.length);
newPath[path.length] = elem;
MenuSelectionManager.defaultManager().setSelectedPath(newPath);
}
--- 251,261 ----
timer.setRepeats(false);
timer.start();
}
private static void appendPath(MenuElement[] path, MenuElement elem) {
! MenuElement[] newPath = new MenuElement[path.length+1];
System.arraycopy(path, 0, newPath, 0, path.length);
newPath[path.length] = elem;
MenuSelectionManager.defaultManager().setSelectedPath(newPath);
}
*** 291,302 ****
final MenuSelectionManager defaultManager = MenuSelectionManager.defaultManager();
if(force) {
Container cnt = menu.getParent();
if(cnt != null && cnt instanceof JMenuBar) {
! MenuElement me[];
! MenuElement subElements[];
subElements = menu.getPopupMenu().getSubElements();
if(subElements.length > 0) {
me = new MenuElement[4];
me[0] = (MenuElement) cnt;
--- 291,302 ----
final MenuSelectionManager defaultManager = MenuSelectionManager.defaultManager();
if(force) {
Container cnt = menu.getParent();
if(cnt != null && cnt instanceof JMenuBar) {
! MenuElement[] me;
! MenuElement[] subElements;
subElements = menu.getPopupMenu().getSubElements();
if(subElements.length > 0) {
me = new MenuElement[4];
me[0] = (MenuElement) cnt;
*** 310,320 ****
me[2] = menu.getPopupMenu();
}
defaultManager.setSelectedPath(me);
}
} else {
! MenuElement path[] = defaultManager.getSelectedPath();
if(path.length > 0 && path[path.length-1] == menu) {
appendPath(path, menu.getPopupMenu());
}
}
}
--- 310,320 ----
me[2] = menu.getPopupMenu();
}
defaultManager.setSelectedPath(me);
}
} else {
! MenuElement[] path = defaultManager.getSelectedPath();
if(path.length > 0 && path[path.length-1] == menu) {
appendPath(path, menu.getPopupMenu());
}
}
}
*** 501,519 ****
if(menu.isSelected() && menu.getPopupMenu().isShowing()) {
manager.clearSelectedPath();
} else {
Container cnt = menu.getParent();
if(cnt != null && cnt instanceof JMenuBar) {
! MenuElement me[] = new MenuElement[2];
me[0]=(MenuElement)cnt;
me[1]=menu;
manager.setSelectedPath(me);
}
}
}
! MenuElement selectedPath[] = manager.getSelectedPath();
if (selectedPath.length > 0 &&
selectedPath[selectedPath.length-1] != menu.getPopupMenu()) {
if(menu.isTopLevelMenu() ||
menu.getDelay() == 0) {
--- 501,519 ----
if(menu.isSelected() && menu.getPopupMenu().isShowing()) {
manager.clearSelectedPath();
} else {
Container cnt = menu.getParent();
if(cnt != null && cnt instanceof JMenuBar) {
! MenuElement[] me = new MenuElement[2];
me[0]=(MenuElement)cnt;
me[1]=menu;
manager.setSelectedPath(me);
}
}
}
! MenuElement[] selectedPath = manager.getSelectedPath();
if (selectedPath.length > 0 &&
selectedPath[selectedPath.length-1] != menu.getPopupMenu()) {
if(menu.isTopLevelMenu() ||
menu.getDelay() == 0) {
*** 557,567 ****
return;
}
MenuSelectionManager manager =
MenuSelectionManager.defaultManager();
! MenuElement selectedPath[] = manager.getSelectedPath();
if (!menu.isTopLevelMenu()) {
if(!(selectedPath.length > 0 &&
selectedPath[selectedPath.length-1] ==
menu.getPopupMenu())) {
if(menu.getDelay() == 0) {
--- 557,567 ----
return;
}
MenuSelectionManager manager =
MenuSelectionManager.defaultManager();
! MenuElement[] selectedPath = manager.getSelectedPath();
if (!menu.isTopLevelMenu()) {
if(!(selectedPath.length > 0 &&
selectedPath[selectedPath.length-1] ==
menu.getPopupMenu())) {
if(menu.getDelay() == 0) {
*** 572,582 ****
}
}
} else {
if(selectedPath.length > 0 &&
selectedPath[0] == menu.getParent()) {
! MenuElement newPath[] = new MenuElement[3];
// A top level menu's parent is by definition
// a JMenuBar
newPath[0] = (MenuElement)menu.getParent();
newPath[1] = menu;
if (BasicPopupMenuUI.getLastPopup() != null) {
--- 572,582 ----
}
}
} else {
if(selectedPath.length > 0 &&
selectedPath[0] == menu.getParent()) {
! MenuElement[] newPath = new MenuElement[3];
// A top level menu's parent is by definition
// a JMenuBar
newPath[0] = (MenuElement)menu.getParent();
newPath[1] = menu;
if (BasicPopupMenuUI.getLastPopup() != null) {
*** 613,629 ****
public void menuDragMouseDragged(MenuDragMouseEvent e) {
if (menuItem.isEnabled() == false)
return;
MenuSelectionManager manager = e.getMenuSelectionManager();
! MenuElement path[] = e.getPath();
Point p = e.getPoint();
if(p.x >= 0 && p.x < menuItem.getWidth() &&
p.y >= 0 && p.y < menuItem.getHeight()) {
JMenu menu = (JMenu)menuItem;
! MenuElement selectedPath[] = manager.getSelectedPath();
if(!(selectedPath.length > 0 &&
selectedPath[selectedPath.length-1] ==
menu.getPopupMenu())) {
if(menu.isTopLevelMenu() ||
menu.getDelay() == 0 ||
--- 613,629 ----
public void menuDragMouseDragged(MenuDragMouseEvent e) {
if (menuItem.isEnabled() == false)
return;
MenuSelectionManager manager = e.getMenuSelectionManager();
! MenuElement[] path = e.getPath();
Point p = e.getPoint();
if(p.x >= 0 && p.x < menuItem.getWidth() &&
p.y >= 0 && p.y < menuItem.getHeight()) {
JMenu menu = (JMenu)menuItem;
! MenuElement[] selectedPath = manager.getSelectedPath();
if(!(selectedPath.length > 0 &&
selectedPath[selectedPath.length-1] ==
menu.getPopupMenu())) {
if(menu.isTopLevelMenu() ||
menu.getDelay() == 0 ||
*** 663,685 ****
//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<MenuElement> 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 = newList.toArray(newPath);
manager.setSelectedPath(newPath);
e.consume();
}
}
--- 663,685 ----
//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<MenuElement> 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 = newList.toArray(newPath);
manager.setSelectedPath(newPath);
e.consume();
}
}
< prev index next >