< prev index next >
src/share/classes/javax/swing/SwingUtilities.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
rev 1566 : 6680988: KeyEvent is still missing VK values for many keyboards
Summary: 2 new methods and some fields added to KeyEvent, plus hash of constants introduced
Reviewed-by: art
@@ -104,15 +104,12 @@
/**
* Return true if <code>a</code> contains <code>b</code>
*/
public static final boolean isRectangleContainingRectangle(Rectangle a,Rectangle b) {
- if (b.x >= a.x && (b.x + b.width) <= (a.x + a.width) &&
- b.y >= a.y && (b.y + b.height) <= (a.y + a.height)) {
- return true;
- }
- return false;
+ return b.x >= a.x && (b.x + b.width) <= (a.x + a.width) &&
+ b.y >= a.y && (b.y + b.height) <= (a.y + a.height);
}
/**
* Return the rectangle (0,0,bounds.width,bounds.height) for the component <code>aComponent</code>
*/
@@ -268,12 +265,11 @@
if (!parent.contains(x, y)) {
return null;
}
if (parent instanceof Container) {
Component components[] = ((Container)parent).getComponents();
- for (int i = 0 ; i < components.length ; i++) {
- Component comp = components[i];
+ for (Component comp : components) {
if (comp != null && comp.isVisible()) {
Point loc = comp.getLocation();
if (comp instanceof Container) {
comp = getDeepestComponentAt(comp, x - loc.x, y - loc.y);
} else {
@@ -372,12 +368,12 @@
Rectangle b;
int x,y;
do {
if(c instanceof JComponent) {
- x = ((JComponent)c).getX();
- y = ((JComponent)c).getY();
+ x = c.getX();
+ y = c.getY();
} else if(c instanceof java.applet.Applet ||
c instanceof java.awt.Window) {
try {
Point pp = c.getLocationOnScreen();
x = pp.x;
@@ -411,12 +407,12 @@
Rectangle b;
int x,y;
do {
if(c instanceof JComponent) {
- x = ((JComponent)c).getX();
- y = ((JComponent)c).getY();
+ x = c.getX();
+ y = c.getY();
} else if(c instanceof java.applet.Applet ||
c instanceof java.awt.Window) {
try {
Point pp = c.getLocationOnScreen();
x = pp.x;
@@ -976,11 +972,11 @@
/* Unless both text and icon are non-null, we effectively ignore
* the value of textIconGap.
*/
int gap;
- View v = null;
+ View v;
if (textIsEmpty) {
textR.width = textR.height = 0;
text = "";
gap = 0;
}
@@ -1244,12 +1240,12 @@
}
else if (c instanceof Container) {
children = ((Container)c).getComponents();
}
if (children != null) {
- for(int i = 0; i < children.length; i++) {
- updateComponentTreeUI0(children[i]);
+ for (Component child : children) {
+ updateComponentTreeUI0(child);
}
}
}
@@ -1589,19 +1585,10 @@
/**
* Returns true if the <code>e</code> is a valid KeyEvent to use in
* processing the key bindings associated with JComponents.
*/
static boolean isValidKeyEventForKeyBindings(KeyEvent e) {
- if (e.getID() == KeyEvent.KEY_TYPED) {
- int mod = e.getModifiers();
- if (((mod & ActionEvent.ALT_MASK) != 0) &&
- ((mod & ActionEvent.CTRL_MASK) == 0)) {
- // filter out typed "alt-?" keys, but not those created
- // with AltGr, and not control characters
- return false;
- }
- }
return true;
}
/**
* Invokes <code>actionPerformed</code> on <code>action</code> if
@@ -1698,11 +1685,11 @@
*
* @since 1.3
*/
public static void replaceUIActionMap(JComponent component,
ActionMap uiActionMap) {
- ActionMap map = component.getActionMap((uiActionMap != null));;
+ ActionMap map = component.getActionMap((uiActionMap != null));
while (map != null) {
ActionMap parent = map.getParent();
if (parent == null || (parent instanceof UIResource)) {
map.setParent(uiActionMap);
@@ -1765,12 +1752,11 @@
/**
* Install window listeners on owned windows to watch for displayability changes
*/
void installListeners() {
Window[] windows = getOwnedWindows();
- for (int ind = 0; ind < windows.length; ind++){
- Window window = windows[ind];
+ for (Window window : windows) {
if (window != null) {
window.removeWindowListener(this);
window.addWindowListener(this);
}
}
@@ -1781,12 +1767,11 @@
* displayable children left.
*/
public void windowClosed(WindowEvent e) {
synchronized(getTreeLock()) {
Window[] windows = getOwnedWindows();
- for (int ind = 0; ind < windows.length; ind++) {
- Window window = windows[ind];
+ for (Window window : windows) {
if (window != null) {
if (window.isDisplayable()) {
return;
}
window.removeWindowListener(this);
@@ -1870,11 +1855,11 @@
static void appContextRemove(Object key) {
AppContext.getAppContext().remove(key);
}
- static Class loadSystemClass(String className) throws ClassNotFoundException {
+ static Class<?> loadSystemClass(String className) throws ClassNotFoundException {
ReflectUtil.checkPackageAccess(className);
return Class.forName(className, true, Thread.currentThread().
getContextClassLoader());
}
< prev index next >