3944N/A/*
3944N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3944N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3944N/A *
3944N/A * This code is free software; you can redistribute it and/or modify it
3944N/A * under the terms of the GNU General Public License version 2 only, as
3944N/A * published by the Free Software Foundation.
3944N/A *
3944N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3944N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3944N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3944N/A * version 2 for more details (a copy is included in the LICENSE file that
3944N/A * accompanied this code).
3944N/A *
3944N/A * You should have received a copy of the GNU General Public License version
3944N/A * 2 along with this work; if not, write to the Free Software Foundation,
3944N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3944N/A *
3944N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3944N/A * or visit www.oracle.com if you need additional information or have any
3944N/A * questions.
3944N/A */
3944N/A
3944N/A/*
3944N/A @test
3944N/A @bug 7027013
3944N/A @summary Dialog.show() should validate the window unconditionally
3944N/A @author anthony.petrov@oracle.com: area=awt.toplevel
3944N/A @run main ValidateOnShow
3944N/A*/
3944N/A
3944N/Aimport java.awt.*;
3944N/A
3944N/Apublic class ValidateOnShow {
3944N/A private static Dialog dialog = new Dialog((Frame)null);
3944N/A private static Panel panel = new Panel() {
3944N/A @Override
3944N/A public boolean isValidateRoot() {
3944N/A return true;
3944N/A }
3944N/A };
3944N/A private static Button button = new Button("Test");
3944N/A
3944N/A private static void sleep() {
3944N/A try { Thread.sleep(500); } catch (Exception e) {}
3944N/A }
3944N/A
3944N/A private static void test() {
3944N/A System.out.println("Before showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid());
3944N/A dialog.setVisible(true);
3944N/A sleep();
3944N/A System.out.println("After showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid());
3944N/A
3944N/A if (!panel.isValid()) {
3944N/A dialog.dispose();
3944N/A throw new RuntimeException("The panel hasn't been validated upon showing the dialog");
3944N/A }
3944N/A
3944N/A dialog.setVisible(false);
3944N/A sleep();
3944N/A }
3944N/A
3944N/A public static void main(String[] args) {
3944N/A // setup
3944N/A dialog.add(panel);
3944N/A panel.add(button);
3944N/A
3944N/A dialog.setBounds(200, 200, 300, 200);
3944N/A
3944N/A // The first test should always succeed since the dialog is invalid initially
3944N/A test();
3944N/A
3944N/A // now invalidate the button and the panel
3944N/A button.setBounds(1, 1, 30, 30);
3944N/A sleep();
3944N/A // since the panel is a validate root, the dialog is still valid
3944N/A
3944N/A // w/o a fix this would fail
3944N/A test();
3944N/A
3944N/A // cleanup
3944N/A dialog.dispose();
3944N/A }
3944N/A}