Hi,
I did some more AWT cleanup. This was necessary to get an application
working smoothly that uses Espresso, a Swing-like Java-based toolkit
based on AWT. The changes are not so heavy as discussed yesterday on
IRC, so I'm committing this instantly.
2005-08-12 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/Component.java
(reshape): Simplified repainting of parent.
(paint): Don't call peer.paint() here. The paint method is
exclusivly meant to be overridden by subclasses that wish to
perform custom painting and should do nothing by default.
(repaint): Use local variable in null pointer checks to avoid
NullPointerExceptions.
(imageUpdate): Slight formatting adjustments.
(dispatchEvent): Don't call peer.handleEvent() here, this must
be done in dispatchEventImpl().
(dispatchEventImpl): Dispatch PAINT and UPDATE events to the
peer.
* java/awt/Container.java
(paint): Don't call super.paint() here, this method does nothing
anyway. Visit only lightweight children.
(update): Instead of clearing the background only for top-level
containers, clear the background for all heavyweight containers.
/Roman
? java/awt/semantic.cache
Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.69
diff -u -r1.69 Component.java
--- java/awt/Component.java 5 Aug 2005 15:26:08 -0000 1.69
+++ java/awt/Component.java 12 Aug 2005 11:44:51 -0000
@@ -1404,9 +1404,6 @@
// Erase old bounds and repaint new bounds for lightweights.
if (isLightweight() && isShowing ())
{
- boolean shouldRepaintParent = false;
- boolean shouldRepaintSelf = false;
-
if (parent != null)
{
Rectangle parentBounds = parent.getBounds();
@@ -1416,14 +1413,11 @@
Rectangle newBounds = new Rectangle(parent.getX() + x,
parent.getY() + y,
width, height);
- shouldRepaintParent = parentBounds.intersects(oldBounds);
- shouldRepaintSelf = parentBounds.intersects(newBounds);
+ Rectangle destroyed = oldBounds.union(newBounds);
+ if (!destroyed.isEmpty())
+ parent.repaint(0, destroyed.x, destroyed.y, destroyed.width,
+ destroyed.height);
}
-
- if (shouldRepaintParent && parent != null)
- parent.repaint(oldx, oldy, oldwidth, oldheight);
- if (shouldRepaintSelf)
- repaint();
}
// Only post event if this component is visible and has changed size.
@@ -1830,9 +1824,8 @@
*/
public void paint(Graphics g)
{
- // Paint the heavyweight peer
- if (!isLightweight() && peer != null)
- peer.paint(g);
+ // This is a callback method and is meant to be overridden by subclasses
+ // that want to perform custom painting.
}
/**
@@ -1858,7 +1851,8 @@
{
// Tests show that the clearing of the background is only done in
// two cases:
- // - If the component is lightwight (yes this is in contrast to the spec).
+ // - If the component is lightweight (yes this is in contrast to the spec).
+ // or
// - If the component is a toplevel container.
if (isLightweight() || getParent() == null)
{
@@ -1943,14 +1937,18 @@
*/
public void repaint(long tm, int x, int y, int width, int height)
{
- // Handle lightweight repainting by forwarding to native parent
- if (isLightweight() && parent != null)
+ if(!isShowing())
{
- if (parent != null)
- parent.repaint(tm, x + getX(), y + getY(), width, height);
+ Component p = parent;
+ if (p != null)
+ p.repaint(tm, x + getX(), y + getY(), width, height);
+ }
+ else
+ {
+ ComponentPeer p = peer;
+ if (p != null)
+ p.repaint(tm, x, y, width, height);
}
- else if (peer != null)
- peer.repaint(tm, x, y, width, height);
}
/**
@@ -2011,7 +2009,7 @@
public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
{
if ((flags & (FRAMEBITS | ALLBITS)) != 0)
- repaint ();
+ repaint();
else if ((flags & SOMEBITS) != 0)
{
if (incrementalDraw)
@@ -2021,10 +2019,10 @@
long tm = redrawRate.longValue();
if (tm < 0)
tm = 0;
- repaint (tm);
+ repaint(tm);
}
else
- repaint (100);
+ repaint(100);
}
}
return (flags & (ALLBITS | ABORT | ERROR)) == 0;
@@ -2322,8 +2320,6 @@
// Some subclasses in the AWT package need to override this behavior,
// hence the use of dispatchEventImpl().
dispatchEventImpl(e);
- if (peer != null && ! e.consumed)
- peer.handleEvent(e);
}
/**
@@ -4786,7 +4782,7 @@
* @param e the event to dispatch
*/
- void dispatchEventImpl (AWTEvent e)
+ void dispatchEventImpl(AWTEvent e)
{
Event oldEvent = translateEvent (e);
@@ -4820,7 +4816,10 @@
break;
}
}
- processEvent (e);
+ if (e.id == PaintEvent.PAINT || e.id == PaintEvent.UPDATE)
+ peer.handleEvent(e);
+ else
+ processEvent(e);
}
}
Index: java/awt/Container.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Container.java,v
retrieving revision 1.58
diff -u -r1.58 Container.java
--- java/awt/Container.java 10 Aug 2005 12:43:30 -0000 1.58
+++ java/awt/Container.java 12 Aug 2005 11:44:51 -0000
@@ -42,6 +42,7 @@
import java.awt.event.ContainerListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
+import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
import java.beans.PropertyChangeListener;
@@ -757,11 +758,10 @@
{
if (!isShowing())
return;
- // Paint self first.
- super.paint(g);
+
// Visit heavyweights as well, in case they were
// erased when we cleared the background for this container.
- visitChildren(g, GfxPaintVisitor.INSTANCE, true);
+ visitChildren(g, GfxPaintVisitor.INSTANCE, false);
}
/**
@@ -776,17 +776,26 @@
* @specnote The specification suggests that this method forwards the
* update() call to all its lightweight children. Tests show
* that this is not done either in the JDK. The exact behaviour
- * seems to be that top-level container call super.update()
- * (causing the background to be cleared), and all other containers
+ * seems to be that the background is cleared in heavyweight
+ * Containers, and all other containers
* directly call paint(), causing the (lightweight) children to
* be painted.
*/
public void update(Graphics g)
{
- if (getParent() == null)
- super.update(g);
- else
- paint(g);
+ // It seems that the JDK clears the background of containers like Panel
+ // and Window (within this method) but not of 'plain' Containers or
+ // JComponents. This could
+ // lead to the assumption that it only clears heavyweight containers.
+ // However that is not quite true. In a test with a custom Container
+ // that overrides isLightweight() to return false, the background is
+ // also not cleared. So we do a check on !(peer instanceof LightweightPeer)
+ // instead.
+ ComponentPeer p = peer;
+ if (p != null && !(p instanceof LightweightPeer))
+ g.clearRect(0, 0, getWidth(), getHeight());
+
+ paint(g);
}
/**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches