提交 085f3bd5 编写于 作者: A anthony

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
上级 325f8ed1
......@@ -2887,11 +2887,12 @@ public abstract class Component implements ImageObserver, MenuContainer,
/**
* 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
......
......@@ -41,6 +41,8 @@ import java.io.ObjectStreamField;
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.awt.dnd.SunDropTargetEvent;
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 @@ public class Container extends Component {
* 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 @@ public class Container extends Component {
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 @@ public class Container extends Component {
* 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
......
......@@ -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.*;
......
......@@ -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.*;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册