This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui] [PATCH] Fix Component.reshape()
- From: David Jee <djee at redhat dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Fri, 25 Jun 2004 13:19:44 -0400
- Subject: [gui] [PATCH] Fix Component.reshape()
Hello,
I committed the following patch to the java-gui-branch. It fixes
Component.reshape(), so that a component will repaint the parent and
itself only when it is necessary. For example, even if the size of the
component has been changed, if the component is not within the visible
bounds of the parent, then there is no point repainting the component.
Also, this patch fixes resize() and move() methods, so that they
delegate to setBounds(). This eliminates some duplicate code in
Component class.
-David Jee
2004-06-25 David Jee <djee@redhat.com>
* java/awt/Component.java
(move): Delegate to setBounds().
(resize): Likewise.
(reshape): Fix so it repaints parent and self only when necessary.
Index: java/awt/Component.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Component.java,v
retrieving revision 1.37.2.12
diff -u -r1.37.2.12 Component.java
--- java/awt/Component.java 24 Jun 2004 05:30:15 -0000 1.37.2.12
+++ java/awt/Component.java 25 Jun 2004 17:06:14 -0000
@@ -1175,30 +1175,7 @@
*/
public void move(int x, int y)
{
- int oldx = this.x;
- int oldy = this.y;
-
- if (this.x == x && this.y == y)
- return;
- invalidate ();
- this.x = x;
- this.y = y;
- if (peer != null)
- peer.setBounds (x, y, width, height);
-
- // Erase old bounds and repaint new bounds for lightweights.
- if (isLightweight() && width != 0 && height !=0)
- {
- parent.repaint(oldx, oldy, width, height);
- repaint();
- }
-
- if (oldx != x || oldy != y)
- {
- ComponentEvent ce = new ComponentEvent(this,
- ComponentEvent.COMPONENT_MOVED);
- getToolkit().getSystemEventQueue().postEvent(ce);
- }
+ setBounds(x, y, this.width, this.height);
}
/**
@@ -1262,32 +1239,7 @@
*/
public void resize(int width, int height)
{
- int oldwidth = this.width;
- int oldheight = this.height;
-
- if (this.width == width && this.height == height)
- return;
- invalidate ();
- this.width = width;
- this.height = height;
- if (peer != null)
- peer.setBounds (x, y, width, height);
-
- // Erase old bounds and repaint new bounds for lightweights.
- if (isLightweight())
- {
- if (oldwidth != 0 && oldheight != 0 && parent != null)
- parent.repaint(x, y, oldwidth, oldheight);
- if (width != 0 && height != 0)
- repaint();
- }
-
- if (oldwidth != width || oldheight != height)
- {
- ComponentEvent ce =
- new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED);
- getToolkit().getSystemEventQueue().postEvent(ce);
- }
+ setBounds(this.x, this.y, width, height);
}
/**
@@ -1395,9 +1347,25 @@
// Erase old bounds and repaint new bounds for lightweights.
if (isLightweight())
{
- if (oldwidth != 0 && oldheight != 0 && parent != null)
+ boolean shouldRepaintParent = false;
+ boolean shouldRepaintSelf = false;
+
+ if (parent != null)
+ {
+ Rectangle parentBounds = parent.getBounds();
+ Rectangle oldBounds = new Rectangle(parent.getX() + oldx,
+ parent.getY() + oldy,
+ oldwidth, oldheight);
+ Rectangle newBounds = new Rectangle(parent.getX() + x,
+ parent.getY() + y,
+ width, height);
+ shouldRepaintParent = parentBounds.intersects(oldBounds);
+ shouldRepaintSelf = parentBounds.intersects(newBounds);
+ }
+
+ if (shouldRepaintParent)
parent.repaint(oldx, oldy, oldwidth, oldheight);
- if (width != 0 && height != 0)
+ if (shouldRepaintSelf)
repaint();
}