diff options
Diffstat (limited to 'libjava/classpath/javax/swing/SwingUtilities.java')
-rw-r--r-- | libjava/classpath/javax/swing/SwingUtilities.java | 104 |
1 files changed, 51 insertions, 53 deletions
diff --git a/libjava/classpath/javax/swing/SwingUtilities.java b/libjava/classpath/javax/swing/SwingUtilities.java index 2d859b7448e..6762ccd804a 100644 --- a/libjava/classpath/javax/swing/SwingUtilities.java +++ b/libjava/classpath/javax/swing/SwingUtilities.java @@ -83,31 +83,6 @@ public class SwingUtilities { // Do nothing. } - - /** - * Calculates the portion of the base rectangle which is inside the - * insets. - * - * @param base The rectangle to apply the insets to - * @param insets The insets to apply to the base rectangle - * @param ret A rectangle to use for storing the return value, or - * <code>null</code> - * - * @return The calculated area inside the base rectangle and its insets, - * either stored in ret or a new Rectangle if ret is <code>null</code> - * - * @see #calculateInnerArea - */ - public static Rectangle calculateInsetArea(Rectangle base, Insets insets, - Rectangle ret) - { - if (ret == null) - ret = new Rectangle(); - ret.setBounds(base.x + insets.left, base.y + insets.top, - base.width - (insets.left + insets.right), - base.height - (insets.top + insets.bottom)); - return ret; - } /** * Calculates the portion of the component's bounds which is inside the @@ -122,13 +97,18 @@ public class SwingUtilities * * @return The calculated area inside the component and its border * insets - * - * @see #calculateInsetArea */ public static Rectangle calculateInnerArea(JComponent c, Rectangle r) { Rectangle b = getLocalBounds(c); - return calculateInsetArea(b, c.getInsets(), r); + if (r == null) + r = new Rectangle(); + Insets i = c.getInsets(); + r.x = b.x + i.left; + r.width = b.width - i.left - i.right; + r.y = b.y + i.top; + r.height = b.height - i.top - i.bottom; + return r; } /** @@ -1021,11 +1001,16 @@ public class SwingUtilities * * @return The common Frame */ - static Frame getOwnerFrame() + static Window getOwnerFrame(Window owner) { - if (ownerFrame == null) - ownerFrame = new OwnerFrame(); - return ownerFrame; + Window result = owner; + if (result == null) + { + if (ownerFrame == null) + ownerFrame = new OwnerFrame(); + result = ownerFrame; + } + return result; } /** @@ -1262,26 +1247,31 @@ public class SwingUtilities } /** - * Calculates the intersection of two rectangles. + * Calculates the intersection of two rectangles. The result is stored + * in <code>rect</code>. This is basically the same + * like {@link Rectangle#intersection(Rectangle)}, only that it does not + * create new Rectangle instances. The tradeoff is that you loose any data in + * <code>rect</code>. * * @param x upper-left x coodinate of first rectangle * @param y upper-left y coodinate of first rectangle * @param w width of first rectangle * @param h height of first rectangle * @param rect a Rectangle object of the second rectangle - * @throws NullPointerException if rect is null. + * + * @throws NullPointerException if rect is null * * @return a rectangle corresponding to the intersection of the - * two rectangles. A zero rectangle is returned if the rectangles - * do not overlap. + * two rectangles. An empty rectangle is returned if the rectangles + * do not overlap */ public static Rectangle computeIntersection(int x, int y, int w, int h, Rectangle rect) { - int x2 = (int) rect.getX(); - int y2 = (int) rect.getY(); - int w2 = (int) rect.getWidth(); - int h2 = (int) rect.getHeight(); + int x2 = (int) rect.x; + int y2 = (int) rect.y; + int w2 = (int) rect.width; + int h2 = (int) rect.height; int dx = (x > x2) ? x : x2; int dy = (y > y2) ? y : y2; @@ -1289,9 +1279,11 @@ public class SwingUtilities int dh = (y + h < y2 + h2) ? (y + h - dy) : (y2 + h2 - dy); if (dw >= 0 && dh >= 0) - return new Rectangle(dx, dy, dw, dh); + rect.setBounds(dx, dy, dw, dh); + else + rect.setBounds(0, 0, 0, 0); - return new Rectangle(0, 0, 0, 0); + return rect; } /** @@ -1308,26 +1300,31 @@ public class SwingUtilities } /** - * Calculates the union of two rectangles. + * Calculates the union of two rectangles. The result is stored in + * <code>rect</code>. This is basically the same as + * {@link Rectangle#union(Rectangle)} except that it avoids creation of new + * Rectangle objects. The tradeoff is that you loose any data in + * <code>rect</code>. * * @param x upper-left x coodinate of first rectangle * @param y upper-left y coodinate of first rectangle * @param w width of first rectangle * @param h height of first rectangle * @param rect a Rectangle object of the second rectangle - * @throws NullPointerException if rect is null. + * + * @throws NullPointerException if rect is null * * @return a rectangle corresponding to the union of the - * two rectangles. A rectangle encompassing both is returned if the - * rectangles do not overlap. + * two rectangles; a rectangle encompassing both is returned if the + * rectangles do not overlap */ public static Rectangle computeUnion(int x, int y, int w, int h, Rectangle rect) { - int x2 = (int) rect.getX(); - int y2 = (int) rect.getY(); - int w2 = (int) rect.getWidth(); - int h2 = (int) rect.getHeight(); + int x2 = (int) rect.x; + int y2 = (int) rect.y; + int w2 = (int) rect.width; + int h2 = (int) rect.height; int dx = (x < x2) ? x : x2; int dy = (y < y2) ? y : y2; @@ -1335,9 +1332,10 @@ public class SwingUtilities int dh = (y + h > y2 + h2) ? (y + h - dy) : (y2 + h2 - dy); if (dw >= 0 && dh >= 0) - return new Rectangle(dx, dy, dw, dh); - - return new Rectangle(0, 0, 0, 0); + rect.setBounds(dx, dy, dw, dh); + else + rect.setBounds(0, 0, 0, 0); + return rect; } /** |