I enclosed the actual painting/translating/etc in
CellRendererPane.paintComponent() in a try-finally block to properly
cleanup when something goes wrong. While this does not add super much
value, it is still a little nicer than before.

2006-02-07  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/CellRendererPane.java
        (paintComponent): Enclosed painting in try finally to properly
        clean up even when throwing an exception.

/Roman
Index: javax/swing/CellRendererPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/CellRendererPane.java,v
retrieving revision 1.12
diff -u -r1.12 CellRendererPane.java
--- javax/swing/CellRendererPane.java	19 Oct 2005 15:45:03 -0000	1.12
+++ javax/swing/CellRendererPane.java	7 Feb 2006 15:43:09 -0000
@@ -169,24 +169,32 @@
     addImpl(c, null, 0);
 
     Rectangle oldClip = graphics.getClipBounds();
-    // translate to (x,y)
-    graphics.translate(x, y);
-    graphics.clipRect(0, 0, w, h);
-    // set bounds of c
-    c.setBounds(0, 0, w, h);
+    boolean translated = false;
+    try
+      {
+        // translate to (x,y)
+        graphics.translate(x, y);
+        translated = true;
+        graphics.clipRect(0, 0, w, h);
+        // set bounds of c
+        c.setBounds(0, 0, w, h);
+
+        // validate if necessary
+        if (shouldValidate)
+          {
+            c.validate();
+          }
 
-    // validate if necessary
-    if (shouldValidate)
+        // paint component
+        c.paint(graphics);
+      }
+    finally
       {
-        c.validate();
+        // untranslate g
+        if (translated)
+          graphics.translate(-x, -y);
+        graphics.setClip(oldClip);
       }
-
-    // paint component
-    c.paint(graphics);
-
-    // untranslate g
-    graphics.translate(-x, -y);
-    graphics.setClip(oldClip);
   }
 
   /**

Reply via email to