< prev index next >
src/share/classes/javax/swing/MenuSelectionManager.java
Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov
@@ -35,11 +35,11 @@
* A MenuSelectionManager owns the selection in menu hierarchy.
*
* @author Arnaud Weber
*/
public class MenuSelectionManager {
- private Vector selection = new Vector();
+ private Vector<MenuElement> selection = new Vector<MenuElement>();
/* diagnostic aids -- should be false for production builds. */
private static final boolean TRACE = false; // trace creates and disposes
private static final boolean VERBOSE = false; // show reuse hits/misses
private static final boolean DEBUG = false; // show bad params, misc.
@@ -97,18 +97,18 @@
System.out.print("Previous: "); printMenuElementArray(getSelectedPath());
System.out.print("New: "); printMenuElementArray(path);
}
for(i=0,c=path.length;i<c;i++) {
- if(i < currentSelectionCount && (MenuElement)selection.elementAt(i) == path[i])
+ if (i < currentSelectionCount && selection.elementAt(i) == path[i])
firstDifference++;
else
break;
}
for(i=currentSelectionCount - 1 ; i >= firstDifference ; i--) {
- MenuElement me = (MenuElement)selection.elementAt(i);
+ MenuElement me = selection.elementAt(i);
selection.removeElementAt(i);
me.menuSelectionChanged(false);
}
for(i = firstDifference, c = path.length ; i < c ; i++) {
@@ -128,11 +128,11 @@
*/
public MenuElement[] getSelectedPath() {
MenuElement res[] = new MenuElement[selection.size()];
int i,c;
for(i=0,c=selection.size();i<c;i++)
- res[i] = (MenuElement) selection.elementAt(i);
+ res[i] = selection.elementAt(i);
return res;
}
/**
* Tell the menu selection to close and unselect all the menu components. Call this method
@@ -169,12 +169,11 @@
* @return all of the <code>ChangeListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
public ChangeListener[] getChangeListeners() {
- return (ChangeListener[])listenerList.getListeners(
- ChangeListener.class);
+ return listenerList.getListeners(ChangeListener.class);
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type. The event instance
@@ -253,12 +252,12 @@
continue;
mc = subElements[j].getComponent();
if(!mc.isShowing())
continue;
if(mc instanceof JComponent) {
- cWidth = ((JComponent)mc).getWidth();
- cHeight = ((JComponent)mc).getHeight();
+ cWidth = mc.getWidth();
+ cHeight = mc.getHeight();
} else {
r2 = mc.getBounds();
cWidth = r2.width;
cHeight = r2.height;
}
@@ -333,11 +332,11 @@
System.out.println("Path is(");
int i, j;
for(i=0,j=path.length; i<j ;i++){
for (int k=0; k<=i; k++)
System.out.print(" ");
- MenuElement me = (MenuElement) path[i];
+ MenuElement me = path[i];
if(me instanceof JMenuItem) {
System.out.println(((JMenuItem)me).getText() + ", ");
} else if (me instanceof JMenuBar) {
System.out.println("JMenuBar, ");
} else if(me instanceof JPopupMenu) {
@@ -394,12 +393,12 @@
continue;
mc = subElements[j].getComponent();
if(!mc.isShowing())
continue;
if(mc instanceof JComponent) {
- cWidth = ((JComponent)mc).getWidth();
- cHeight = ((JComponent)mc).getHeight();
+ cWidth = mc.getWidth();
+ cHeight = mc.getHeight();
} else {
r2 = mc.getBounds();
cWidth = r2.width;
cHeight = r2.height;
}
@@ -424,11 +423,11 @@
*
* @param e a KeyEvent object
*/
public void processKeyEvent(KeyEvent e) {
MenuElement[] sel2 = new MenuElement[0];
- sel2 = (MenuElement[])selection.toArray(sel2);
+ sel2 = selection.toArray(sel2);
int selSize = sel2.length;
MenuElement[] path;
if (selSize < 1) {
return;
@@ -469,11 +468,11 @@
/**
* Return true if c is part of the currently used menu
*/
public boolean isComponentPartOfCurrentMenu(Component c) {
if(selection.size() > 0) {
- MenuElement me = (MenuElement)selection.elementAt(0);
+ MenuElement me = selection.elementAt(0);
return isComponentPartOfCurrentMenu(me,c);
} else
return false;
}
< prev index next >