< prev index next >
src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -325,11 +325,11 @@
lst.add(menuToOpen);
lst.add(subpopup);
if (subitem != null) {
lst.add(subitem);
}
- MenuElement newPath[] = new MenuElement[0];
+ MenuElement[] newPath = new MenuElement[0];
newPath = lst.toArray(newPath);
MenuSelectionManager.defaultManager().setSelectedPath(newPath);
e.consume();
}
menuToOpen = null;
@@ -342,16 +342,16 @@
if (!Character.isLetterOrDigit(keyChar)) {
return;
}
MenuSelectionManager manager = e.getMenuSelectionManager();
- MenuElement path[] = e.getPath();
- MenuElement items[] = popupMenu.getSubElements();
+ MenuElement[] path = e.getPath();
+ MenuElement[] items = popupMenu.getSubElements();
int currentIndex = -1;
int matches = 0;
int firstMatch = -1;
- int indexes[] = null;
+ int[] indexes = null;
for (int j = 0; j < items.length; j++) {
if (! (items[j] instanceof JMenuItem)) {
continue;
}
@@ -395,11 +395,11 @@
// menu item in the cycle.
MenuElement newItem;
newItem = items[indexes[(currentIndex + 1) % matches]];
- MenuElement newPath[] = new MenuElement[path.length+1];
+ MenuElement[] newPath = new MenuElement[path.length+1];
System.arraycopy(path, 0, newPath, 0, path.length);
newPath[path.length] = newItem;
manager.setSelectedPath(newPath);
e.consume();
}
@@ -468,16 +468,16 @@
if(focusOwner != null && !(focusOwner instanceof JRootPane)) {
return;
}
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
- MenuElement path[] = msm.getSelectedPath();
+ MenuElement[] path = msm.getSelectedPath();
MenuElement lastElement;
if(path.length > 0) {
lastElement = path[path.length-1];
if(lastElement instanceof JMenu) {
- MenuElement newPath[] = new MenuElement[path.length+1];
+ MenuElement[] newPath = new MenuElement[path.length+1];
System.arraycopy(path,0,newPath,0,path.length);
newPath[path.length] = ((JMenu)lastElement).getPopupMenu();
msm.setSelectedPath(newPath);
} else if(lastElement instanceof JMenuItem) {
JMenuItem mi = (JMenuItem)lastElement;
@@ -492,11 +492,11 @@
}
}
}
private void selectParentChild(boolean direction) {
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
- MenuElement path[] = msm.getSelectedPath();
+ MenuElement[] path = msm.getSelectedPath();
int len = path.length;
if (direction == PARENT) {
// selecting parent
int popupIndex = len-1;
@@ -508,11 +508,11 @@
(path[popupIndex] instanceof JPopupMenu ||
path[--popupIndex] instanceof JPopupMenu) &&
!((JMenu)path[popupIndex-1]).isTopLevelMenu()) {
// we have a submenu, just close it
- MenuElement newPath[] = new MenuElement[popupIndex];
+ MenuElement[] newPath = new MenuElement[popupIndex];
System.arraycopy(path, 0, newPath, 0, popupIndex);
msm.setSelectedPath(newPath);
return;
}
} else {
@@ -546,11 +546,11 @@
MenuElement currentMenu = path[1];
MenuElement nextMenu = findEnabledChild(
path[0].getSubElements(), currentMenu, direction);
if (nextMenu != null && nextMenu != currentMenu) {
- MenuElement newSelection[];
+ MenuElement[] newSelection;
if (len == 2) {
// menu is selected but its popup not shown
newSelection = new MenuElement[2];
newSelection[0] = path[0];
newSelection[1] = nextMenu;
@@ -566,11 +566,11 @@
}
}
private void selectItem(boolean direction) {
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
- MenuElement path[] = msm.getSelectedPath();
+ MenuElement[] path = msm.getSelectedPath();
if (path.length == 0) {
return;
}
int len = path.length;
if (len == 1 && path[0] instanceof JPopupMenu) {
@@ -636,11 +636,11 @@
}
}
} else {
// just select the next item, no path expansion needed
- MenuElement subs[] = path[len-2].getSubElements();
+ MenuElement[] subs = path[len-2].getSubElements();
MenuElement nextChild =
findEnabledChild(subs, path[len-1], direction);
if (nextChild == null) {
nextChild = findEnabledChild(subs, -1, direction);
}
@@ -666,11 +666,11 @@
shortenSelectedPath();
}
}
private void shortenSelectedPath() {
- MenuElement path[] = MenuSelectionManager.defaultManager().getSelectedPath();
+ MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath();
if (path.length <= 2) {
MenuSelectionManager.defaultManager().clearSelectedPath();
return;
}
// unselect MenuItem and its Popup by default
@@ -693,17 +693,17 @@
if (path.length - value <= 2
&& !UIManager.getBoolean("Menu.preserveTopLevelSelection")) {
// clear selection for the topLevelMenu
value = path.length;
}
- MenuElement newPath[] = new MenuElement[path.length - value];
+ MenuElement[] newPath = new MenuElement[path.length - value];
System.arraycopy(path, 0, newPath, 0, path.length - value);
MenuSelectionManager.defaultManager().setSelectedPath(newPath);
}
}
- private static MenuElement nextEnabledChild(MenuElement e[],
+ private static MenuElement nextEnabledChild(MenuElement[] e,
int fromIndex, int toIndex) {
for (int i=fromIndex; i<=toIndex; i++) {
if (e[i] != null) {
Component comp = e[i].getComponent();
if ( comp != null
@@ -714,11 +714,11 @@
}
}
return null;
}
- private static MenuElement previousEnabledChild(MenuElement e[],
+ private static MenuElement previousEnabledChild(MenuElement[] e,
int fromIndex, int toIndex) {
for (int i=fromIndex; i>=toIndex; i--) {
if (e[i] != null) {
Component comp = e[i].getComponent();
if ( comp != null
@@ -729,11 +729,11 @@
}
}
return null;
}
- static MenuElement findEnabledChild(MenuElement e[], int fromIndex,
+ static MenuElement findEnabledChild(MenuElement[] e, int fromIndex,
boolean forward) {
MenuElement result;
if (forward) {
result = nextEnabledChild(e, fromIndex+1, e.length-1);
if (result == null) result = nextEnabledChild(e, 0, fromIndex-1);
@@ -743,11 +743,11 @@
fromIndex+1);
}
return result;
}
- static MenuElement findEnabledChild(MenuElement e[],
+ static MenuElement findEnabledChild(MenuElement[] e,
MenuElement elem, boolean forward) {
for (int i=0; i<e.length; i++) {
if (e[i] == elem) {
return findEnabledChild(e, i, forward);
}
< prev index next >