This improves the robustness in the Swing painting code against client code doing nasty things with the passed-in Graphics object, like calling create() or modifying the state in some irreversible way.
2006-06-09 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/JComponent.java
(paintChildrenOptimized): Paint component with a new Graphics
object to protect the other painting code from modifications
done in that object, and avoid cleanup ops on possibly
dispose()ed
Graphics object.
/Roman
--
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.123
diff -u -1 -0 -r1.123 JComponent.java
--- javax/swing/JComponent.java 6 Jun 2006 09:19:58 -0000 1.123
+++ javax/swing/JComponent.java 9 Jun 2006 23:24:50 -0000
@@ -2032,33 +2032,24 @@
Rectangle bounds = children[i].getBounds(rectCache);
Rectangle oldClip = g.getClipBounds();
if (oldClip == null)
oldClip = bounds;
if (!g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height))
continue;
boolean translated = false;
- try
- {
- g.clipRect(bounds.x, bounds.y, bounds.width, bounds.height);
- g.translate(bounds.x, bounds.y);
- translated = true;
- children[i].paint(g);
- }
- finally
- {
- if (translated)
- g.translate(-bounds.x, -bounds.y);
- g.setClip(oldClip);
- }
+ Graphics g2 = g.create(bounds.x, bounds.y, bounds.width,
+ bounds.height);
+ children[i].paint(g2);
+ g2.dispose();
}
g.setClip(originalClip);
}
/**
* Paint the component's body. This usually means calling [EMAIL PROTECTED]
* ComponentUI#update} on the [EMAIL PROTECTED] #ui} property of the component, if
* it is non-<code>null</code>. You may override this if you wish to
* customize the component's body-painting behavior. The component's body
* is painted first, before the border and children.
@@ -2177,21 +2168,21 @@
/**
* Performs double buffered repainting.
*/
private void paintDoubleBuffered(Rectangle r)
{
RepaintManager rm = RepaintManager.currentManager(this);
// Paint on the offscreen buffer.
Component root = getRoot(this);
Image buffer = rm.getOffscreenBuffer(this, root.getWidth(),
- root.getHeight());
+ root.getHeight());
//Rectangle targetClip = SwingUtilities.convertRectangle(this, r, root);
Point translation = SwingUtilities.convertPoint(this, 0, 0, root);
Graphics g2 = buffer.getGraphics();
g2.translate(translation.x, translation.y);
g2.setClip(r.x, r.y, r.width, r.height);
g2 = getComponentGraphics(g2);
isPaintingDoubleBuffered = true;
try
{
paint(g2);
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
