Path: blob/master/test/jdk/java/awt/Modal/ModalFocusTransferTests/FocusTransferFDWTest.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.*;2425// FDW: Frame -> Dialog -> Window26public class FocusTransferFDWTest {2728class CustomFrame extends TestFrame {2930@Override31public void doOpenAction() {32if (dialog != null) {33dialog.setVisible(true);34}35}36}3738class CustomWindow extends TestWindow {3940public CustomWindow(Dialog d) {41super(d);42}4344@Override45public void doCloseAction() {46this.dispose();47}48}4950class CustomDialog extends TestDialog {5152public CustomDialog(Frame f) {53super(f);54}5556@Override57public void doOpenAction() {58if (window != null) {59window.setVisible(true);60}61}6263@Override64public void doCloseAction() {65this.dispose();66}67}6869private TestDialog dialog;70private TestFrame frame;71private TestWindow window;7273private static final int delay = 1000;7475private final ExtendedRobot robot;7677private final Dialog.ModalityType modalityType;7879FocusTransferFDWTest(Dialog.ModalityType modType) throws Exception {8081modalityType = modType;8283robot = new ExtendedRobot();84EventQueue.invokeLater(this::createGUI);85}8687private void createGUI() {8889frame = new CustomFrame();90frame.setLocation(50, 50);91dialog = new CustomDialog((Frame) null);92if (modalityType != null) {93dialog.setModalityType(modalityType);94}95dialog.setLocation(250, 50);96window = new CustomWindow(dialog);97window.setLocation(450, 50);98frame.setVisible(true);99}100101private void closeAll() {102if (dialog != null) { dialog.dispose(); }103if ( frame != null) { frame.dispose(); }104if (window != null) { window.dispose(); }105}106107public void doTest() throws Exception {108109robot.waitForIdle(delay);110111try {112113frame.checkCloseButtonFocusGained(true);114115frame.clickOpenButton(robot);116robot.waitForIdle(delay);117118dialog.checkCloseButtonFocusGained(true);119120frame.checkOpenButtonFocusLost(true);121122dialog.clickOpenButton(robot);123robot.waitForIdle(delay);124125window.checkCloseButtonFocusGained(true);126dialog.checkOpenButtonFocusLost(true);127128dialog.openGained.reset();129window.clickCloseButton(robot);130131dialog.checkOpenButtonFocusGained(true);132133frame.openGained.reset();134dialog.clickCloseButton(robot);135136frame.checkOpenButtonFocusGained(true);137138} catch (Exception e) {139140// make screenshot before exit141Rectangle rect = new Rectangle(0, 0, 650, 250);142java.awt.image.BufferedImage img = robot.createScreenCapture(rect);143javax.imageio.ImageIO.write(img, "jpg", new java.io.File("NOK.jpg"));144145throw e;146}147148robot.waitForIdle(delay);149EventQueue.invokeAndWait(this::closeAll);150}151}152153154