1895N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1895N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1895N/A *
1895N/A * This code is free software; you can redistribute it and/or modify it
1895N/A * under the terms of the GNU General Public License version 2 only, as
1895N/A * published by the Free Software Foundation.
1895N/A *
1895N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1895N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1895N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1895N/A * version 2 for more details (a copy is included in the LICENSE file that
1895N/A * accompanied this code).
1895N/A *
1895N/A * You should have received a copy of the GNU General Public License version
1895N/A * 2 along with this work; if not, write to the Free Software Foundation,
1895N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1895N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1895N/A */
1895N/A
1895N/A/*
1895N/A @test
1895N/A @bug 6852592
1895N/A @summary invalidate() must stop when it encounters a validate root
1895N/A @author anthony.petrov@sun.com
4195N/A @run main/othervm -Djava.awt.smartInvalidate=true InvalidateMustRespectValidateRoots
1895N/A*/
1895N/A
1895N/Aimport javax.swing.*;
1895N/Aimport java.awt.event.*;
1895N/A
1895N/Apublic class InvalidateMustRespectValidateRoots {
1895N/A private static volatile JRootPane rootPane;
1895N/A
1895N/A public static void main(String args[]) throws Exception {
1895N/A SwingUtilities.invokeAndWait(new Runnable() {
1895N/A public void run() {
1895N/A // The JRootPane is a validate root. We'll check if
1895N/A // invalidate() stops on the root pane, or goes further
1895N/A // up to the frame.
1895N/A JFrame frame = new JFrame();
1895N/A final JButton button = new JButton();
1895N/A
1895N/A frame.add(button);
1895N/A
1895N/A // To enable running the test manually: use the Ctrl-Shift-F1
1895N/A // to print the component hierarchy to the console
1895N/A button.addActionListener(new ActionListener() {
1895N/A public void actionPerformed(ActionEvent ev) {
1895N/A if (button.isValid()) {
1895N/A button.invalidate();
1895N/A } else {
1895N/A button.revalidate();
1895N/A }
1895N/A }
1895N/A });
1895N/A
1895N/A rootPane = frame.getRootPane();
1895N/A
1895N/A // Now the component hierarchy looks like:
1895N/A // frame
1895N/A // --> rootPane
1895N/A // --> layered pane
1895N/A // --> content pane
1895N/A // --> button
1895N/A
1895N/A // Make all components valid first via showing the frame
1895N/A // We have to make the frame visible. Otherwise revalidate() is
1895N/A // useless (see RepaintManager.addInvalidComponent()).
1895N/A frame.pack(); // To enable running this test manually
1895N/A frame.setVisible(true);
1895N/A
1895N/A if (!frame.isValid()) {
1895N/A throw new RuntimeException(
1895N/A "setVisible(true) failed to validate the frame");
1895N/A }
1895N/A
1895N/A // Now invalidate the button
1895N/A button.invalidate();
1895N/A
1895N/A // Check if the 'valid' status is what we expect it to be
1895N/A if (rootPane.isValid()) {
1895N/A throw new RuntimeException(
1895N/A "invalidate() failed to invalidate the root pane");
1895N/A }
1895N/A
1895N/A if (!frame.isValid()) {
1895N/A throw new RuntimeException(
1895N/A "invalidate() invalidated the frame");
1895N/A }
1895N/A
1895N/A // Now validate the hierarchy again
1895N/A button.revalidate();
1895N/A
1895N/A // Now let the validation happen on the EDT
1895N/A }
1895N/A });
1895N/A
1895N/A Thread.sleep(1000);
1895N/A
1895N/A SwingUtilities.invokeAndWait(new Runnable() {
1895N/A public void run() {
1895N/A // Check if the root pane finally became valid
1895N/A if (!rootPane.isValid()) {
1895N/A throw new RuntimeException(
1895N/A "revalidate() failed to validate the hierarchy");
1895N/A }
1895N/A }
1895N/A });
1895N/A }
1895N/A}