Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/MultipleDialogs/MultipleDialogs1Test.java
38828 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*/2223/*24* @test25* @bug 805435826* @summary Check whether a set of dialogs created with a toolkit excluded Frame27* parent has a proper modal blocking behavior. Also show a document modal28* dialog and check if it blocks the document properly.29*30* @library ../helpers ../../../../lib/testlibrary/31* @build ExtendedRobot32* @build Flag33* @build TestDialog34* @build TestFrame35* @run main/timeout=500 MultipleDialogs1Test36*/373839import java.awt.*;40import java.util.ArrayList;41import java.util.List;42import java.util.Collections;43import java.util.Iterator;4445public class MultipleDialogs1Test {4647private volatile CustomFrame frame;48private List<CustomDialog> dialogList;4950private static int delay = 500;51private int dialogCount = -1;5253public void createGUI() {5455final int n = 8;56dialogList = new ArrayList<>();5758frame = new CustomFrame();59frame.setLocation(50, 50);60frame.setModalExclusionType(Dialog.ModalExclusionType.TOOLKIT_EXCLUDE);61frame.setVisible(true);6263int x = 250, y = 50;6465CustomDialog dlg;6667for (int i = 0; i < n - 1; ++i) {6869dlg = new CustomDialog(frame);70dlg.setLocation(x, y);71x += 200;7273if (x > 600) {74x = 50;75y += 200;76}7778Dialog.ModalityType type;7980if (i % 3 == 0) {81type = Dialog.ModalityType.MODELESS;82} else if (i % 3 == 1) {83type = Dialog.ModalityType.APPLICATION_MODAL;84} else {85type = Dialog.ModalityType.TOOLKIT_MODAL;86}8788dlg.setModalityType(type);89dialogList.add(dlg);90}9192dlg = new CustomDialog(frame);93dlg.setLocation(x, y);94dlg.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);95dialogList.add(dlg);96}9798public void doTest() throws Exception {99100try {101EventQueue.invokeAndWait(this::createGUI);102103ExtendedRobot robot = new ExtendedRobot();104robot.waitForIdle(delay);105106List<CustomDialog> dialogs = Collections.synchronizedList(dialogList);107108final int n = dialogs.size();109110synchronized(dialogs) {111for (int i = 0; i < n - 1; ++i) {112113frame.clickOpenButton(robot);114robot.waitForIdle(delay);115116dialogs.get(i).checkUnblockedDialog(117robot, i + ": This is " + getType(i) + ".");118119frame.checkUnblockedFrame(robot, i + ": Other dialogs are visible.");120121if (i > 0) {122for (int j = 0; j < i; j++) {123dialogs.get(j).checkUnblockedDialog(robot, j + ": A toolkit modality " +124"excluded frame is a parent of this dialog.");125}126}127} // i128129frame.clickOpenButton(robot);130robot.waitForIdle(delay);131132dialogs.get(n - 1).checkUnblockedDialog(133robot, (n - 1) + ": This is " + getType(n - 1) + ".");134135frame.checkBlockedFrame(robot,136"A document modal dialog with Frame parent is visible.");137138for (int i = 0; i < n - 1; ++i) {139dialogs.get(i).checkUnblockedDialog(robot,140i + ": A document modal dialog should not block " +141"this dialog. The parent is modality excluded.");142}143144dialogs.get(n - 1).clickCloseButton(robot);145robot.waitForIdle(delay);146147for (int i = 0; i < n - 1; ++i) {148dialogs.get(i).checkUnblockedDialog(robot, i + ": A document modal " +149"dialog which blocked this dialog was closed.");150}151frame.checkUnblockedFrame(robot,152"A blocking document modal dialog was closed.");153robot.waitForIdle(delay);154} // synchronized155156} finally {157EventQueue.invokeAndWait(this::closeAll);158}159}160161private String getType(int i) {162163switch (dialogList.get(i).getModalityType()) {164case APPLICATION_MODAL:165return "an application modal dialog";166case DOCUMENT_MODAL:167return "a document modal dialog";168case TOOLKIT_MODAL:169return "a toolkit modal dialog";170}171return "a modeless dialog";172}173174private void closeAll() {175176if (frame != null) { frame.dispose(); }177if (dialogList != null) {178Iterator<CustomDialog> it = dialogList.iterator();179while (it.hasNext()) { it.next().dispose(); }180}181}182183class CustomFrame extends TestFrame {184185@Override186public void doOpenAction() {187if ((dialogList != null) && (dialogList.size() > dialogCount)) {188dialogCount++;189CustomDialog d = dialogList.get(dialogCount);190if (d != null) { d.setVisible(true); }191}192}193}194195class CustomDialog extends TestDialog {196197public CustomDialog(Frame f) { super(f); }198public CustomDialog(Dialog d) { super(d); }199200@Override201public void doCloseAction() { this.dispose(); }202}203204205public static void main(String[] args) throws Exception {206(new MultipleDialogs1Test()).doTest();207}208}209210211