Path: blob/master/test/jdk/java/awt/Modal/ToFront/DialogToFrontModalBlockedTest.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 DialogToFrontModalBlockedTest {2627private volatile CustomDialog dialog;28private volatile TestDialog leftDialog;29private volatile TestFrame rightFrame;30private volatile Frame parent;3132private static final int delay = 500;33private final ExtendedRobot robot;3435private DialogToFrontModalBlockedTest(Dialog.ModalityType modalityType,36boolean setModal) throws Exception {3738robot = new ExtendedRobot();39EventQueue.invokeLater(() -> {40createGUI(modalityType, setModal);41});42}4344public DialogToFrontModalBlockedTest(Dialog.ModalityType modalityType) throws Exception {45this(modalityType, false);46}4748public DialogToFrontModalBlockedTest() throws Exception {49this(null, true);50}5152private void createGUI(Dialog.ModalityType modalityType,53boolean setModal) {5455parent = new Frame();56leftDialog = new TestDialog(parent);57leftDialog.setSize(200, 100);58leftDialog.setLocation(50, 50);59leftDialog.setVisible(true);6061dialog = new CustomDialog(leftDialog);6263if (setModal) { dialog.setModal(true); }64else if (modalityType != null) {65dialog.setModalityType(modalityType);66}6768dialog.setSize(200, 100);69dialog.setLocation(150, 50);7071rightFrame = new TestFrame();72rightFrame.setSize(200, 100);73rightFrame.setLocation(250, 50);7475if (setModal || modalityType == Dialog.ModalityType.APPLICATION_MODAL) {76rightFrame.setModalExclusionType(77Dialog.ModalExclusionType.APPLICATION_EXCLUDE);78} else if (modalityType == Dialog.ModalityType.TOOLKIT_MODAL) {79rightFrame.setModalExclusionType(80Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);81}8283dialog.setVisible(true);84}8586public void doTest() throws Exception {8788try {89robot.waitForIdle(delay);9091dialog.clickOpenButton(robot);92robot.waitForIdle(delay);9394rightFrame.clickCloseButton(robot);95robot.waitForIdle(delay);9697EventQueue.invokeAndWait(() -> { leftDialog.toFront(); });98robot.waitForIdle(delay);99100rightFrame.clickDummyButton(robot);101102EventQueue.invokeAndWait(() -> { leftDialog.toFront(); });103robot.waitForIdle(delay);104105leftDialog.clickDummyButton(robot, 7, false, "Calling toFront " +106"for Dialog blocked by " + dialog.getModalityType() +107"dialog brought it to the top of the modal dialog");108109robot.waitForIdle(delay);110} finally {111EventQueue.invokeAndWait(this::closeAll);112}113}114115private void closeAll() {116if (dialog != null) { dialog.dispose(); }117if (parent != null) { parent.dispose(); }118if (leftDialog != null) { leftDialog.dispose(); }119if (rightFrame != null) { rightFrame.dispose(); }120}121122class CustomDialog extends TestDialog {123124public CustomDialog(Dialog d) { super(d); }125public CustomDialog(Frame f) { super(f); }126127@Override128public void doOpenAction() {129if (rightFrame != null) {130rightFrame.setVisible(true);131}132}133}134}135136137