Hi,

here come some small fixlets with quite nice effect. Most importantly this
moves the revalidate operation itself into the event thread. This makes
some heavy bulk revalidation request more smooth.

I have run extensive tests against Sun's JDK (I'll commit this as soon I
brought them into shape for Mauve), to make sure this is the correct thing
to do. As it seems, most/all operations that effect the GUI structure,
layout or painting are (should be) performed from the event thread. I
suppose there are some more points in our Swing that have to be tuned like
this.

The overall effect is that our Swing is more responsive in the user
experience.

Also included are some small adjustments to Component.show(),
Component.hide() and JComponent.setVisible(), for which I also prepare
some tests, that I only have to bring in shape Mauve.

2005-09-27  Roman Kennke  <[EMAIL PROTECTED]>

        * java/awt/Component.java
        (hide): Repaint component before invalidating the parent.
        (show): Repaint component before invalidating the parent.
        * javax/swing/JComponent.java
        (revalidate): Check if we are in the event thread, and if not,
        then queue a self-request in the event thread.
        (setVisible): Repaint the parent and queue a revalidate.

/Roman
Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.76
diff -u -r1.76 Component.java
--- java/awt/Component.java	23 Sep 2005 20:35:06 -0000	1.76
+++ java/awt/Component.java	27 Sep 2005 13:59:28 -0000
@@ -901,15 +901,15 @@
         if (currentPeer != null)
             currentPeer.setVisible(true);
 
+        // The JDK repaints the component before invalidating the parent.
+        // So do we.
+        repaint();
         // Invalidate the parent if we have one. The component itself must
         // not be invalidated. We also avoid NullPointerException with
         // a local reference here.
         Container currentParent = parent;
         if (currentParent != null)
-          {
-            currentParent.invalidate();
-            currentParent.repaint();
-          }
+          currentParent.invalidate();
 
         ComponentEvent ce =
           new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
@@ -947,16 +947,16 @@
             currentPeer.setVisible(false);
         
         this.visible = false;
-        
+
+        // The JDK repaints the component before invalidating the parent.
+        // So do we.
+        repaint();
         // Invalidate the parent if we have one. The component itself must
         // not be invalidated. We also avoid NullPointerException with
         // a local reference here.
         Container currentParent = parent;
         if (currentParent != null)
-          {
-            currentParent.invalidate();
-            currentParent.repaint();
-          }
+          currentParent.invalidate();
 
         ComponentEvent ce =
           new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.63
diff -u -r1.63 JComponent.java
--- javax/swing/JComponent.java	25 Sep 2005 13:55:07 -0000	1.63
+++ javax/swing/JComponent.java	27 Sep 2005 13:59:28 -0000
@@ -44,6 +44,7 @@
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.Dimension;
+import java.awt.EventQueue;
 import java.awt.FlowLayout;
 import java.awt.FocusTraversalPolicy;
 import java.awt.Font;
@@ -242,7 +243,7 @@
    * The text to show in the tooltip associated with this component.
    * 
    * @see #setToolTipText
-   * @see #getToolTipText
+   * @see #getToolTipText()
    */
    String toolTipText;
 
@@ -322,7 +323,7 @@
    * try to request focus, but the request might fail. Thus it is only 
    * a hint guiding swing's behavior.
    *
-   * @see #requestFocus
+   * @see #requestFocus()
    * @see #isRequestFocusEnabled
    * @see #setRequestFocusEnabled
    */
@@ -1643,7 +1644,7 @@
   /**
    * Performs double buffered repainting.
    *
-   * @param r the area to be repainted
+   * @param g the graphics context to paint to
    */
   void paintDoubleBuffered(Graphics g)
   {
@@ -2095,8 +2096,19 @@
    */
   public void revalidate()
   {
-    invalidate();
-    RepaintManager.currentManager(this).addInvalidComponent(this);
+    if (! EventQueue.isDispatchThread())
+      SwingUtilities.invokeLater(new Runnable()
+        {
+          public void run()
+          {
+            revalidate();
+          }
+        });
+    else
+      {
+        invalidate();
+        RepaintManager.currentManager(this).addInvalidComponent(this);
+      }
   }
 
   /**
@@ -2316,6 +2328,10 @@
   public void setVisible(boolean v)
   {
     super.setVisible(v);
+    Container parent = getParent();
+    if (parent != null)
+      parent.repaint(getX(), getY(), getWidth(), getHeight());
+    revalidate();
   }
 
   /**
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to