After doing some tests on Sun, it seems that getRoot should return the
Window component of an applet. This doesn't seem like a good solution,
but I changed ours back to match it. I added a function to JComponent
and RepaintManager to override this unusual behaviour.
The JApplet still paint correctly.
2006-05-03 Lillian Angel <[EMAIL PROTECTED]>
* javax/swing/JComponent.java
(getRoot): New private function. Gets the root appropriate
for painting. If an applet exists as a parent, then it is
returned.
(paintDoubleBuffered): Changed to use new function.
* javax/swing/RepaintManager.java
(getRoot): New private function. Gets the root appropriate
for painting. If an applet exists as a parent, then it is
returned.
(getOffscreenBuffer): Changed to use new function.
* javax/swing/SwingUtilties.java
(getRoot): Reverted last patch to return Window, even if
an Applet exists.
On Tue, 2006-05-02 at 14:18 -0400, Lillian Angel wrote:
> This fixes the painting problem with JApplets. In most cases, the
> components were being drawn on the Window rather than the actual applet.
>
>
> 2006-05-02 Lillian Angel <[EMAIL PROTECTED]>
>
> * javax/swing/SwingUtilities.java
> (getRoot): Should return the Applet if it exists.
> Only return the Window if an Applet has not been
> encountered.
>
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.117
diff -u -r1.117 JComponent.java
--- javax/swing/JComponent.java 30 Apr 2006 09:24:19 -0000 1.117
+++ javax/swing/JComponent.java 3 May 2006 14:23:00 -0000
@@ -2159,6 +2159,33 @@
}
/**
+ * Gets the root of the component given. If a parent of the
+ * component is an instance of Applet, then the applet is
+ * returned. The applet is considered the root for painting
+ * and adding/removing components. Otherwise, the root Window
+ * is returned if it exists.
+ *
+ * @param comp - The component to get the root for.
+ * @return the parent root. An applet if it is a parent,
+ * or the root window. If neither exist, null is returned.
+ */
+ private Component getRoot(Component comp)
+ {
+ Applet app = null;
+
+ while (comp != null)
+ {
+ if (app == null && comp instanceof Window)
+ return comp;
+ else if (comp instanceof Applet)
+ app = (Applet) comp;
+ comp = comp.getParent();
+ }
+
+ return app;
+ }
+
+ /**
* Performs double buffered repainting.
*/
private void paintDoubleBuffered(Rectangle r)
@@ -2166,7 +2193,7 @@
RepaintManager rm = RepaintManager.currentManager(this);
// Paint on the offscreen buffer.
- Component root = SwingUtilities.getRoot(this);
+ Component root = getRoot(this);
Image buffer = rm.getOffscreenBuffer(this, root.getWidth(),
root.getHeight());
//Rectangle targetClip = SwingUtilities.convertRectangle(this, r, root);
Index: javax/swing/RepaintManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/RepaintManager.java,v
retrieving revision 1.30
diff -u -r1.30 RepaintManager.java
--- javax/swing/RepaintManager.java 18 Apr 2006 12:48:32 -0000 1.30
+++ javax/swing/RepaintManager.java 3 May 2006 14:23:00 -0000
@@ -38,11 +38,13 @@
package javax.swing;
+import java.applet.Applet;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
+import java.awt.Window;
import java.awt.image.VolatileImage;
import java.util.ArrayList;
import java.util.Collections;
@@ -607,7 +609,7 @@
public Image getOffscreenBuffer(Component component, int proposedWidth,
int proposedHeight)
{
- Component root = SwingUtilities.getRoot(component);
+ Component root = getRoot(component);
Image buffer = (Image) offscreenBuffers.get(root);
if (buffer == null
|| buffer.getWidth(null) < proposedWidth
@@ -622,7 +624,33 @@
}
return buffer;
}
-
+
+ /**
+ * Gets the root of the component given. If a parent of the
+ * component is an instance of Applet, then the applet is
+ * returned. The applet is considered the root for painting.
+ * Otherwise, the root Window is returned if it exists.
+ *
+ * @param comp - The component to get the root for.
+ * @return the parent root. An applet if it is a parent,
+ * or the root window. If neither exist, null is returned.
+ */
+ private Component getRoot(Component comp)
+ {
+ Applet app = null;
+
+ while (comp != null)
+ {
+ if (app == null && comp instanceof Window)
+ return comp;
+ else if (comp instanceof Applet)
+ app = (Applet) comp;
+ comp = comp.getParent();
+ }
+
+ return app;
+ }
+
/**
* Blits the back buffer of the specified root component to the screen. If
* the RepaintManager is currently working on a paint request, the commit
Index: javax/swing/SwingUtilities.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/SwingUtilities.java,v
retrieving revision 1.50
diff -u -r1.50 SwingUtilities.java
--- javax/swing/SwingUtilities.java 2 May 2006 19:31:22 -0000 1.50
+++ javax/swing/SwingUtilities.java 3 May 2006 14:23:01 -0000
@@ -376,29 +376,27 @@
public static Component getRoot(Component comp)
{
Applet app = null;
+ Window win = null;
while (comp != null)
{
- // A Window cannot be in an applet, so
- // the Window returned would be encountered
- // after the applet.
- if (app == null && comp instanceof Window)
- return (Window) comp;
+ if (win == null && comp instanceof Window)
+ win = (Window) comp;
else if (comp instanceof Applet)
app = (Applet) comp;
comp = comp.getParent();
}
+ if (win != null)
+ return win;
return app;
}
/**
- * Return true if a descends from b, in other words if b is an
- * ancestor of a.
- *
+ * Return true if a descends from b, in other words if b is an ancestor of a.
+ *
* @param a The child to search the ancestry of
* @param b The potential ancestor to search for
- *
* @return true if a is a descendent of b, false otherwise
*/
public static boolean isDescendingFrom(Component a, Component b)