changeset 4366:dde5cc0d768c

7041387: Introduce new boolean system property java.awt.smartInvalidate Summary: The behavior introduced with 6852592 is now enabled by the new system property only Reviewed-by: dcherepanov
author anthony
date Tue, 10 May 2011 18:28:05 +0400
parents 997f464f8446
children bcc961336f77
files src/share/classes/java/awt/Component.java src/share/classes/java/awt/Container.java test/java/awt/Component/Revalidate/Revalidate.java test/java/awt/Container/ValidateRoot/InvalidateMustRespectValidateRoots.java
diffstat 4 files changed, 33 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/Component.java	Tue May 10 17:56:12 2011 +0400
+++ b/src/share/classes/java/awt/Component.java	Tue May 10 18:28:05 2011 +0400
@@ -2887,11 +2887,12 @@
     /**
      * Invalidates this component and its ancestors.
      * <p>
-     * All the ancestors of this component up to the nearest validate root are
-     * marked invalid also. If there is no a validate root container for this
-     * component, all of its ancestors up to the root of the hierarchy are
-     * marked invalid as well. Marking a container <i>invalid</i> indicates
-     * that the container needs to be laid out.
+     * By default, all the ancestors of the component up to the top-most
+     * container of the hierarchy are marked invalid. If the {@code
+     * java.awt.smartInvalidate} system property is set to {@code true},
+     * invalidation stops on the nearest validate root of this component.
+     * Marking a container <i>invalid</i> indicates that the container needs to
+     * be laid out.
      * <p>
      * This method is called automatically when any layout-related information
      * changes (e.g. setting the bounds of the component, or adding the
--- a/src/share/classes/java/awt/Container.java	Tue May 10 17:56:12 2011 +0400
+++ b/src/share/classes/java/awt/Container.java	Tue May 10 18:28:05 2011 +0400
@@ -41,6 +41,8 @@
 import java.io.PrintStream;
 import java.io.PrintWriter;
 
+import java.security.AccessController;
+
 import java.util.Arrays;
 import java.util.EventListener;
 import java.util.HashSet;
@@ -60,6 +62,8 @@
 
 import sun.java2d.pipe.Region;
 
+import sun.security.action.GetBooleanAction;
+
 /**
  * A generic Abstract Window Toolkit(AWT) container object is a component
  * that can contain other AWT components.
@@ -1506,12 +1510,18 @@
      * Layout-related changes, such as bounds of the validate root descendants,
      * do not affect the layout of the validate root parent. This peculiarity
      * enables the {@code invalidate()} method to stop invalidating the
-     * component hierarchy when the method encounters a validate root.
+     * component hierarchy when the method encounters a validate root. However,
+     * to preserve backward compatibility this new optimized behavior is
+     * enabled only when the {@code java.awt.smartInvalidate} system property
+     * value is set to {@code true}.
      * <p>
-     * If a component hierarchy contains validate roots, the {@code validate()}
-     * method must be invoked on the validate root of a previously invalidated
-     * component, rather than on the top-level container (such as a {@code
-     * Frame} object) to restore the validity of the hierarchy later.
+     * If a component hierarchy contains validate roots and the new optimized
+     * {@code invalidate()} behavior is enabled, the {@code validate()} method
+     * must be invoked on the validate root of a previously invalidated
+     * component to restore the validity of the hierarchy later. Otherwise,
+     * calling the {@code validate()} method on the top-level container (such
+     * as a {@code Frame} object) should be used to restore the validity of the
+     * component hierarchy.
      * <p>
      * The {@code Window} class and the {@code Applet} class are the validate
      * roots in AWT.  Swing introduces more validate roots.
@@ -1527,13 +1537,20 @@
         return false;
     }
 
+    private static final boolean isJavaAwtSmartInvalidate;
+    static {
+        // Don't lazy-read because every app uses invalidate()
+        isJavaAwtSmartInvalidate = AccessController.doPrivileged(
+                new GetBooleanAction("java.awt.smartInvalidate"));
+    }
+
     /**
      * Invalidates the parent of the container unless the container
      * is a validate root.
      */
     @Override
     void invalidateParent() {
-        if (!isValidateRoot()) {
+        if (!isJavaAwtSmartInvalidate || !isValidateRoot()) {
             super.invalidateParent();
         }
     }
@@ -1572,9 +1589,8 @@
      * automatically.  Note that the ancestors of the container may be
      * invalidated also (see {@link Component#invalidate} for details.)
      * Therefore, to restore the validity of the hierarchy, the {@code
-     * validate()} method should be invoked on a validate root of an
-     * invalidated component, or on the top-most container if the hierarchy
-     * does not contain validate roots.
+     * validate()} method should be invoked on the top-most invalid
+     * container of the hierarchy.
      * <p>
      * Validating the container may be a quite time-consuming operation. For
      * performance reasons a developer may postpone the validation of the
--- a/test/java/awt/Component/Revalidate/Revalidate.java	Tue May 10 17:56:12 2011 +0400
+++ b/test/java/awt/Component/Revalidate/Revalidate.java	Tue May 10 18:28:05 2011 +0400
@@ -26,7 +26,7 @@
   @bug 7036669
   @summary Test Component.revalidate() method
   @author anthony.petrov@oracle.com: area=awt.component
-  @run main Revalidate
+  @run main/othervm -Djava.awt.smartInvalidate=true Revalidate
 */
 
 import java.awt.*;
--- a/test/java/awt/Container/ValidateRoot/InvalidateMustRespectValidateRoots.java	Tue May 10 17:56:12 2011 +0400
+++ b/test/java/awt/Container/ValidateRoot/InvalidateMustRespectValidateRoots.java	Tue May 10 18:28:05 2011 +0400
@@ -26,7 +26,7 @@
   @bug 6852592
   @summary invalidate() must stop when it encounters a validate root
   @author anthony.petrov@sun.com
-  @run main InvalidateMustRespectValidateRoots
+  @run main/othervm -Djava.awt.smartInvalidate=true InvalidateMustRespectValidateRoots
 */
 
 import javax.swing.*;