Path: blob/master/test/jdk/java/awt/Modal/ToFront/FrameToFrontModelessTest.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*/222324import java.awt.*;252627public class FrameToFrontModelessTest {2829private volatile TestDialog dialog;30private volatile TestFrame leftFrame, rightFrame;3132private static final int delay = 500;33private final ExtendedRobot robot;3435private boolean isModeless;3637public FrameToFrontModelessTest(boolean modeless) throws Exception {38isModeless = modeless;39robot = new ExtendedRobot();40EventQueue.invokeLater(this::createGUI);41}4243private void createGUI() {4445leftFrame = new TestFrame();46leftFrame.setSize(200, 100);47leftFrame.setLocation(50, 50);48leftFrame.setVisible(true);4950dialog = new TestDialog(leftFrame);51if (isModeless) { dialog.setModalityType(Dialog.ModalityType.MODELESS); }52dialog.setSize(200, 100);53dialog.setLocation(150, 50);54dialog.setVisible(true);5556rightFrame = new TestFrame();57rightFrame.setSize(200, 100);58rightFrame.setLocation(250, 50);59rightFrame.setVisible(true);60}616263public void doTest() throws Exception {6465try {6667robot.waitForIdle(delay);6869EventQueue.invokeAndWait(() -> { leftFrame.toFront(); });70robot.waitForIdle(delay);7172leftFrame.clickDummyButton(73robot, 7, false, "Calling toFront method on the parent " +74"left frame brought it to the top of the child dialog");75robot.waitForIdle(delay);7677// show the right frame appear on top of the dialog78rightFrame.clickDummyButton(robot);79robot.waitForIdle(delay);8081String msg = "The " + (isModeless ? "modeless" : "non-modal") +82" dialog still on top of the right frame" +83" even after a button on the frame is clicked";84dialog.clickDummyButton(robot, 7, false, msg);8586} finally {87EventQueue.invokeAndWait(this::closeAll);88}89}9091private void closeAll() {92if (dialog != null) { dialog.dispose(); }93if (leftFrame != null) { leftFrame.dispose(); }94if (rightFrame != null) { rightFrame.dispose(); }95}96}979899100