Hi Audrius,

The repaint() change has caused your problems with JTable and
performance. I reverted this. I still think that this should be done in
the RepaintManager (if it isn't yet), because some class (user
application) may call RepaintManager.addDirtyRegion() directly,
bypassing repaint() and thus not getting this optimization. Anyway, I
put it back in repaint() for now and will investigate this further.

However, I have added some optimizations to the old code, in repaint(),
getVisibleRect and computeVisibleRect() that avoids the creation of lots
of Rectangles and double calculations on ints. This should also help
performance.

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

        * javax/swing/JComponent.java
        (rectCache): Made field non-static to avoid nasty interferences.
        (computeVisibleRect): Avoid creation of new Rectangles and
double
        calculations on ints by using Swing.computeIntersection()
instead
        of Rectangle2D.intersect().
        (repaint): Interect the dirty region with the visible rectangle
        of this component to avoid unnecessary painting.


/Roman

Am Donnerstag, den 16.02.2006, 11:23 +0100 schrieb Roman Kennke:
> Hi Audrius,
> 
> Am Mittwoch, den 15.02.2006, 23:26 +0100 schrieb Audrius Meskauskas:
> > Roman Kennke wrote:
> > 
> > >Index: javax/swing/JComponent.java
> > >  
> > >
> > @@ -2206,12 +2205,8 @@
> > 
> > >    */
> > >   public void repaint(long tm, int x, int y, int width, int height)
> > >   {
> > >-    Rectangle dirty = new Rectangle(x, y, width, height);
> > >-    Rectangle vis = getVisibleRect();
> > >-    dirty = dirty.intersection(vis);
> > >-    RepaintManager.currentManager(this).addDirtyRegion(this, dirty.x, 
> > >dirty.y,
> > >-                                                       dirty.width,
> > >-                                                       dirty.height);
> > >+    RepaintManager.currentManager(this).addDirtyRegion(this, x, y, width,
> > >+                                                       height);
> > >   }
> > > 
> > >  
> > >
> > This change causes the following exception message to appear:
> 
> I wasn't sure about the above piece. Is that repaint thing also causing
> the JTable problems? Maybe we can revert this. However, we should not
> revert the visibility check in paintChildren, if that really breaks
> JTable editing, then something must be seriously wrong with the JTable
> rendering.
> 
> /Roman
> 
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.103
diff -u -r1.103 JComponent.java
--- javax/swing/JComponent.java	15 Feb 2006 21:58:28 -0000	1.103
+++ javax/swing/JComponent.java	16 Feb 2006 10:51:27 -0000
@@ -64,7 +64,6 @@
 import java.awt.event.FocusListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
-import java.awt.geom.Rectangle2D;
 import java.awt.peer.LightweightPeer;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
@@ -555,7 +554,7 @@
    * so that it doesn't get modified in another context within the same
    * method call chain.
    */
-  private static transient Rectangle rectCache;
+  private transient Rectangle rectCache;
 
   /**
    * The default locale of the component.
@@ -1379,9 +1378,8 @@
       {
         ((JComponent) c).computeVisibleRect(rect);
         rect.translate(-getX(), -getY());
-        Rectangle2D.intersect(rect,
-                              new Rectangle(0, 0, getWidth(), getHeight()),
-                              rect);
+        rect = SwingUtilities.computeIntersection(0, 0, getWidth(),
+                                                  getHeight(), rect);
       }
     else
       rect.setRect(0, 0, getWidth(), getHeight());
@@ -1397,9 +1395,10 @@
    */
   public Rectangle getVisibleRect()
   {
-    Rectangle r = new Rectangle();
-    computeVisibleRect(r);
-    return r;
+    if (rectCache == null)
+      rectCache = new Rectangle();
+    computeVisibleRect(rectCache);
+    return rectCache;
   }
 
   /**
@@ -2205,8 +2204,12 @@
    */
   public void repaint(long tm, int x, int y, int width, int height)
   {
-    RepaintManager.currentManager(this).addDirtyRegion(this, x, y, width,
-                                                       height);
+    // TODO: Maybe add this visibleRect stuff to RepaintManager.
+     Rectangle r = getVisibleRect();
+     Rectangle dirty = SwingUtilities.computeIntersection(x, y, width, height, r);
+     RepaintManager.currentManager(this).addDirtyRegion(this, dirty.x, dirty.y,
+                                                        dirty.width,
+                                                        dirty.height);
   }
 
   /**

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to