Path: blob/master/test/jdk/java/awt/Modal/ToFront/DialogToFrontModelessTest.java
41153 views
/*1* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.*;2425public class DialogToFrontModelessTest {2627private volatile TestDialog dialog, leftDialog;28private volatile TestFrame rightFrame;29private volatile Frame parent;3031private static final int delay = 500;32private final ExtendedRobot robot;3334private boolean isModeless;3536public DialogToFrontModelessTest(boolean modeless) throws Exception {37isModeless = modeless;38robot = new ExtendedRobot();39EventQueue.invokeLater(this::createGUI);40}4142public DialogToFrontModelessTest() throws Exception { this(true); }4344private void createGUI() {4546parent = new Frame();4748leftDialog = new TestDialog(parent);49leftDialog.setSize(200, 100);50leftDialog.setLocation(50, 50);51leftDialog.setVisible(true);5253dialog = new TestDialog(leftDialog);5455if (isModeless) { dialog.setModalityType(Dialog.ModalityType.MODELESS); }5657dialog.setSize(200, 100);58dialog.setLocation(150, 50);5960rightFrame = new TestFrame();61rightFrame.setSize(200, 100);62rightFrame.setLocation(250, 50);6364dialog.setVisible(true);65rightFrame.setVisible(true);66}6768public void doTest() throws Exception {6970try {71robot.waitForIdle(delay);7273rightFrame.clickCloseButton(robot);74robot.waitForIdle(delay);7576EventQueue.invokeAndWait(() -> { leftDialog.toFront(); });77robot.waitForIdle(delay);7879leftDialog.clickDummyButton(robot, 7, false,80"Calling toFront method for the parent left dialog " +81"brought it to the top of the child dialog.");82robot.waitForIdle(delay);8384rightFrame.clickDummyButton(robot);85robot.waitForIdle(delay);8687String msg = "The " + (isModeless ? "modeless" : "non-modal") +88" dialog still on top of the right frame" +89" even after a button on the frame is clicked.";90dialog.clickDummyButton(robot, 7, false, msg);91robot.waitForIdle(delay);9293} finally {94EventQueue.invokeAndWait(this::closeAll);95}96}9798private void closeAll() {99if (dialog != null) { dialog.dispose(); }100if (parent != null) { parent.dispose(); }101if (leftDialog != null) { leftDialog.dispose(); }102if (rightFrame != null) { rightFrame.dispose(); }103}104}105106107