jdk/test/java/awt/Component/Revalidate/Revalidate.java
author anthony
Tue, 10 May 2011 18:28:05 +0400
changeset 9658 5484189eeabb
parent 9471 a0139be72f1d
child 40128 e635645d2a8a
permissions -rw-r--r--
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9471
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     1
/*
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     4
 *
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     8
 *
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    13
 * accompanied this code).
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    14
 *
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    18
 *
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    21
 * questions.
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    22
 */
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    23
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    24
/*
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    25
  @test
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    26
  @bug 7036669
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    27
  @summary Test Component.revalidate() method
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    28
  @author anthony.petrov@oracle.com: area=awt.component
9658
5484189eeabb 7041387: Introduce new boolean system property java.awt.smartInvalidate
anthony
parents: 9471
diff changeset
    29
  @run main/othervm -Djava.awt.smartInvalidate=true Revalidate
9471
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    30
*/
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    31
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    32
import java.awt.*;
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    33
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    34
public class Revalidate {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    35
    private static Frame frame = new Frame();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    36
    private static Panel panel = new Panel() {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    37
        @Override
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    38
        public boolean isValidateRoot() {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    39
            return true;
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    40
        }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    41
    };
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    42
    private static Button button = new Button("Test");
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    43
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    44
    private static void sleep() {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    45
        try { Thread.sleep(500); } catch (Exception e) {}
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    46
    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    47
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    48
    private static void printState(String str) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    49
        System.out.println(str + " isValid state: ");
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    50
        System.out.println("         frame: " + frame.isValid());
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    51
        System.out.println("         panel: " + panel.isValid());
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    52
        System.out.println("        button: " + button.isValid());
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    53
    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    54
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    55
    private static void fail(String msg) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    56
        frame.dispose();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    57
        throw new RuntimeException(msg);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    58
    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    59
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    60
    private static void check(String n, Component c, boolean v) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    61
        if (c.isValid() != v) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    62
            fail(n + ".isValid() = " + c.isValid() + ";   expected: " + v);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    63
        }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    64
    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    65
    private static void check(String str, boolean f, boolean p, boolean b) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    66
        printState(str);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    67
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    68
        check("frame", frame, f);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    69
        check("panel", panel, p);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    70
        check("button", button, b);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    71
    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    72
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    73
    public static void main(String[] args) {
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    74
        // setup
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    75
        frame.add(panel);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    76
        panel.add(button);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    77
        frame.setBounds(200, 200, 300, 200);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    78
        frame.setVisible(true);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    79
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    80
        check("Upon showing", true, true, true);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    81
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    82
        button.setBounds(1, 1, 30, 30);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    83
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    84
        check("button.setBounds():", true, false, false);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    85
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    86
        button.revalidate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    87
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    88
        check("button.revalidate():", true, true, true);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    89
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    90
        button.setBounds(1, 1, 30, 30);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    91
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    92
        check("button.setBounds():", true, false, false);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    93
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    94
        panel.revalidate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    95
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    96
        // because the panel's validate root is actually OK
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    97
        check("panel.revalidate():", true, false, false);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    98
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
    99
        button.revalidate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   100
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   101
        check("button.revalidate():", true, true, true);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   102
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   103
        panel.setBounds(2, 2, 125, 130);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   104
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   105
        check("panel.setBounds():", false, false, true);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   106
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   107
        button.revalidate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   108
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   109
        check("button.revalidate():", false, true, true);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   110
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   111
        panel.setBounds(3, 3, 152, 121);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   112
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   113
        check("panel.setBounds():", false, false, true);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   114
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   115
        panel.revalidate();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   116
        sleep();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   117
        check("panel.revalidate():", true, true, true);
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   118
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   119
        // cleanup
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   120
        frame.dispose();
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   121
    }
a0139be72f1d 7036669: Simplify revalidating component hierarchy with multiple validate roots
anthony
parents:
diff changeset
   122
}