< prev index next >
src/share/classes/javax/swing/PopupFactory.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
@@ -309,13 +309,13 @@
boolean focusPopup = false;
if(contents != null && contents.isFocusable()) {
if(contents instanceof JPopupMenu) {
JPopupMenu jpm = (JPopupMenu) contents;
Component popComps[] = jpm.getComponents();
- for(int i=0;i<popComps.length;i++) {
- if(!(popComps[i] instanceof MenuElement) &&
- !(popComps[i] instanceof JSeparator)) {
+ for (Component popComp : popComps) {
+ if (!(popComp instanceof MenuElement) &&
+ !(popComp instanceof JSeparator)) {
focusPopup = true;
break;
}
}
}
@@ -353,21 +353,20 @@
* there is no <code>HeavyWeightPopup</code> associated with
* <code>window</code>.
*/
private static HeavyWeightPopup getRecycledHeavyWeightPopup(Window w) {
synchronized (HeavyWeightPopup.class) {
- List cache;
- Map heavyPopupCache = getHeavyWeightPopupCache();
+ List<HeavyWeightPopup> cache;
+ Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();
if (heavyPopupCache.containsKey(w)) {
- cache = (List)heavyPopupCache.get(w);
+ cache = heavyPopupCache.get(w);
} else {
return null;
}
- int c;
- if ((c = cache.size()) > 0) {
- HeavyWeightPopup r = (HeavyWeightPopup)cache.get(0);
+ if (cache.size() > 0) {
+ HeavyWeightPopup r = cache.get(0);
cache.remove(0);
return r;
}
return null;
}
@@ -376,17 +375,17 @@
/**
* Returns the cache to use for heavy weight popups. Maps from
* <code>Window</code> to a <code>List</code> of
* <code>HeavyWeightPopup</code>s.
*/
- private static Map getHeavyWeightPopupCache() {
+ private static Map<Window, List<HeavyWeightPopup>> getHeavyWeightPopupCache() {
synchronized (HeavyWeightPopup.class) {
- Map cache = (Map)SwingUtilities.appContextGet(
+ Map<Window, List<HeavyWeightPopup>> cache = (Map<Window, List<HeavyWeightPopup>>)SwingUtilities.appContextGet(
heavyWeightPopupCacheKey);
if (cache == null) {
- cache = new HashMap(2);
+ cache = new HashMap<Window, List<HeavyWeightPopup>>(2);
SwingUtilities.appContextPut(heavyWeightPopupCacheKey,
cache);
}
return cache;
}
@@ -395,47 +394,46 @@
/**
* Recycles the passed in <code>HeavyWeightPopup</code>.
*/
private static void recycleHeavyWeightPopup(HeavyWeightPopup popup) {
synchronized (HeavyWeightPopup.class) {
- List cache;
- Object window = SwingUtilities.getWindowAncestor(
+ List<HeavyWeightPopup> cache;
+ Window window = SwingUtilities.getWindowAncestor(
popup.getComponent());
- Map heavyPopupCache = getHeavyWeightPopupCache();
+ Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();
if (window instanceof Popup.DefaultFrame ||
- !((Window)window).isVisible()) {
+ !window.isVisible()) {
// If the Window isn't visible, we don't cache it as we
// likely won't ever get a windowClosed event to clean up.
// We also don't cache DefaultFrames as this indicates
// there wasn't a valid Window parent, and thus we don't
// know when to clean up.
popup._dispose();
return;
} else if (heavyPopupCache.containsKey(window)) {
- cache = (List)heavyPopupCache.get(window);
+ cache = heavyPopupCache.get(window);
} else {
- cache = new ArrayList();
+ cache = new ArrayList<HeavyWeightPopup>();
heavyPopupCache.put(window, cache);
// Clean up if the Window is closed
- final Window w = (Window)window;
+ final Window w = window;
w.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
- List popups;
+ List<HeavyWeightPopup> popups;
synchronized(HeavyWeightPopup.class) {
- Map heavyPopupCache2 =
+ Map<Window, List<HeavyWeightPopup>> heavyPopupCache2 =
getHeavyWeightPopupCache();
- popups = (List)heavyPopupCache2.remove(w);
+ popups = heavyPopupCache2.remove(w);
}
if (popups != null) {
for (int counter = popups.size() - 1;
counter >= 0; counter--) {
- ((HeavyWeightPopup)popups.get(counter)).
- _dispose();
+ popups.get(counter)._dispose();
}
}
}
});
}
@@ -530,14 +528,13 @@
return false;
}
Window[] ownedWindows = w.getOwnedWindows();
if(ownedWindows != null) {
Rectangle bnd = component.getBounds();
- for(int i=0; i<ownedWindows.length;i++) {
- Window owned = ownedWindows[i];
- if (owned.isVisible() &&
- bnd.intersects(owned.getBounds())) {
+ for (Window window : ownedWindows) {
+ if (window.isVisible() &&
+ bnd.intersects(window.getBounds())) {
return true;
}
}
}
@@ -663,26 +660,26 @@
}
/**
* Returns the cache to use for heavy weight popups.
*/
- private static List getLightWeightPopupCache() {
- List cache = (List)SwingUtilities.appContextGet(
+ private static List<LightWeightPopup> getLightWeightPopupCache() {
+ List<LightWeightPopup> cache = (List<LightWeightPopup>)SwingUtilities.appContextGet(
lightWeightPopupCacheKey);
if (cache == null) {
- cache = new ArrayList();
+ cache = new ArrayList<LightWeightPopup>();
SwingUtilities.appContextPut(lightWeightPopupCacheKey, cache);
}
return cache;
}
/**
* Recycles the LightWeightPopup <code>popup</code>.
*/
private static void recycleLightWeightPopup(LightWeightPopup popup) {
synchronized (LightWeightPopup.class) {
- List lightPopupCache = getLightWeightPopupCache();
+ List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache();
if (lightPopupCache.size() < MAX_CACHE_SIZE) {
lightPopupCache.add(popup);
}
}
}
@@ -691,15 +688,13 @@
* Returns a previously used <code>LightWeightPopup</code>, or null
* if none of the popups have been recycled.
*/
private static LightWeightPopup getRecycledLightWeightPopup() {
synchronized (LightWeightPopup.class) {
- List lightPopupCache = getLightWeightPopupCache();
- int c;
- if((c = lightPopupCache.size()) > 0) {
- LightWeightPopup r = (LightWeightPopup)lightPopupCache.
- get(0);
+ List<LightWeightPopup> lightPopupCache = getLightWeightPopupCache();
+ if (lightPopupCache.size() > 0) {
+ LightWeightPopup r = lightPopupCache.get(0);
lightPopupCache.remove(0);
return r;
}
return null;
}
@@ -751,12 +746,11 @@
y);
Component component = getComponent();
component.setLocation(p.x, p.y);
if (parent instanceof JLayeredPane) {
- ((JLayeredPane)parent).add(component,
- JLayeredPane.POPUP_LAYER, 0);
+ parent.add(component, JLayeredPane.POPUP_LAYER, 0);
} else {
parent.add(component);
}
}
@@ -821,27 +815,27 @@
}
/**
* Returns the cache to use for medium weight popups.
*/
- private static List getMediumWeightPopupCache() {
- List cache = (List)SwingUtilities.appContextGet(
+ private static List<MediumWeightPopup> getMediumWeightPopupCache() {
+ List<MediumWeightPopup> cache = (List<MediumWeightPopup>)SwingUtilities.appContextGet(
mediumWeightPopupCacheKey);
if (cache == null) {
- cache = new ArrayList();
+ cache = new ArrayList<MediumWeightPopup>();
SwingUtilities.appContextPut(mediumWeightPopupCacheKey, cache);
}
return cache;
}
/**
* Recycles the MediumWeightPopup <code>popup</code>.
*/
private static void recycleMediumWeightPopup(MediumWeightPopup popup) {
synchronized (MediumWeightPopup.class) {
- List mediumPopupCache = getMediumWeightPopupCache();
+ List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache();
if (mediumPopupCache.size() < MAX_CACHE_SIZE) {
mediumPopupCache.add(popup);
}
}
}
@@ -850,16 +844,13 @@
* Returns a previously used <code>MediumWeightPopup</code>, or null
* if none of the popups have been recycled.
*/
private static MediumWeightPopup getRecycledMediumWeightPopup() {
synchronized (MediumWeightPopup.class) {
- java.util.List mediumPopupCache =
- getMediumWeightPopupCache();
- int c;
- if ((c=mediumPopupCache.size()) > 0) {
- MediumWeightPopup r = (MediumWeightPopup)mediumPopupCache.
- get(0);
+ List<MediumWeightPopup> mediumPopupCache = getMediumWeightPopupCache();
+ if (mediumPopupCache.size() > 0) {
+ MediumWeightPopup r = mediumPopupCache.get(0);
mediumPopupCache.remove(0);
return r;
}
return null;
}
@@ -899,11 +890,11 @@
parent = ((RootPaneContainer)parent).getLayeredPane();
Point p = SwingUtilities.convertScreenLocationToParent(parent,
x, y);
component.setVisible(false);
component.setLocation(p.x, p.y);
- ((JLayeredPane)parent).add(component, JLayeredPane.POPUP_LAYER,
+ parent.add(component, JLayeredPane.POPUP_LAYER,
0);
} else {
Point p = SwingUtilities.convertScreenLocationToParent(parent,
x, y);
< prev index next >