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