On Fri, 2005-11-04 at 16:23 -0500, Thomas Fitzsimmons wrote:
> (or just finish it completely :-))
I finished It completely. I ran it with a test case using all the
possible locations and sizes for the Component and Window. It runs
exactly like Sun (IBM works slightly different).
2005-11-04 Lillian Angel <[EMAIL PROTECTED]>
* java/awt/Window.java
(setLocationRelativeTo): Implemented case when
component is not null.
Index: java/awt/Window.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Window.java,v
retrieving revision 1.61
diff -u -r1.61 Window.java
--- java/awt/Window.java 1 Nov 2005 23:13:32 -0000 1.61
+++ java/awt/Window.java 4 Nov 2005 22:45:19 -0000
@@ -803,20 +803,79 @@
return isVisible();
}
- public void setLocationRelativeTo (Component c)
+ public void setLocationRelativeTo(Component c)
{
- if (c == null || !c.isShowing ())
+ if (c == null || !c.isShowing())
{
int x = 0;
int y = 0;
- GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment ();
- Point center = ge.getCenterPoint ();
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ Point center = ge.getCenterPoint();
x = center.x - (width / 2);
y = center.y - (height / 2);
- setLocation (x, y);
+ setLocation(x, y);
+ }
+ else
+ {
+ int x = c.getX();
+ int y = c.getY();
+
+ int cWidth = c.getWidth();
+ int cHeight = c.getHeight();
+ Dimension screenSize = getToolkit().getScreenSize();
+
+ // If bottom of component is cut off, window placed
+ // on the left or the right side of component
+ if ((y + cHeight) > screenSize.height)
+ {
+ // If the right side of the component is closer to the center
+ if ((screenSize.width / 2 - x) <= 0)
+ {
+ if ((x - width) >= 0)
+ x -= width;
+ else
+ x = 0;
+ }
+ else
+ {
+ if ((x + cWidth + width) <= screenSize.width)
+ x += cWidth;
+ else
+ x = screenSize.width - width;
+ }
+
+ y = screenSize.height - height;
+ }
+ else if (cWidth > width || cHeight > height)
+ {
+ // If right side of component is cut off
+ if ((x + width) > screenSize.width)
+ x = screenSize.width - width;
+ // If left side of component is cut off
+ else if (x < 0)
+ x = 0;
+ else
+ x += (cWidth - width) / 2;
+
+ y += (cHeight - height) / 2;
+ }
+ else
+ {
+ // If right side of component is cut off
+ if ((x + width) > screenSize.width)
+ x = screenSize.width - width;
+ // If left side of component is cut off
+ else if (x < 0)
+ x = 0;
+ else
+ x -= (width - cWidth) / 2;
+
+ y -= (height - cHeight) / 2;
+ }
+
+ setLocation(x, y);
}
- // FIXME: handle case where component is non-null.
}
/**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches