Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/ModalInternalFrameTest/ModalInternalFrameTest.java
38821 views
/*1* Copyright (c) 2007, 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 651875326@summary Tests the functionality of modal Swing internal frames27@author artem.ananiev: area=awt.modal28@run main/timeout=30 ModalInternalFrameTest29*/3031import java.awt.*;32import java.awt.event.*;3334import javax.swing.*;3536public class ModalInternalFrameTest37{38private boolean passed = true;39private static Robot r;4041private JDesktopPane pane1;42private JDesktopPane pane2;4344private JFrame frame1;45private JFrame frame2;4647private JButton bn1;48private JButton bs1;49private JButton bn2;50private JButton bs2;5152private Point bn1Loc;53private Point bs1Loc;54private Point bn2Loc;55private Point bs2Loc;5657private volatile boolean unblocked1 = true;58private volatile boolean unblocked2 = true;5960public ModalInternalFrameTest()61{62}6364public void init()65{66pane1 = new JDesktopPane();67pane2 = new JDesktopPane();6869frame1 = new JFrame("F1");70frame1.setBounds(100, 100, 320, 240);71frame1.getContentPane().setLayout(new BorderLayout());72frame1.getContentPane().add(pane1);73bn1 = new JButton("Test");74bn1.addActionListener(new ActionListener()75{76public void actionPerformed(ActionEvent ae)77{78unblocked1 = true;79}80});81frame1.getContentPane().add(bn1, BorderLayout.NORTH);82bs1 = new JButton("Show dialog");83bs1.addActionListener(new ActionListener()84{85public void actionPerformed(ActionEvent ae)86{87JOptionPane.showInternalMessageDialog(pane1, "Dialog1");88}89});90frame1.getContentPane().add(bs1, BorderLayout.SOUTH);9192frame2 = new JFrame("F2");93frame2.setBounds(100, 400, 320, 240);94frame2.getContentPane().setLayout(new BorderLayout());95frame2.getContentPane().add(pane2);96bn2 = new JButton("Test");97bn2.addActionListener(new ActionListener()98{99public void actionPerformed(ActionEvent ae)100{101unblocked2 = true;102}103});104frame2.getContentPane().add(bn2, BorderLayout.NORTH);105bs2 = new JButton("Show dialog");106bs2.addActionListener(new ActionListener()107{108public void actionPerformed(ActionEvent ae)109{110JOptionPane.showInternalMessageDialog(pane2, "Dialog2");111}112});113frame2.getContentPane().add(bs2, BorderLayout.SOUTH);114115frame1.setVisible(true);116frame2.setVisible(true);117}118119private void getLocations()120{121bn1Loc = bn1.getLocationOnScreen();122bn1Loc.translate(bn1.getWidth() / 2, bn1.getHeight() / 2);123124bn2Loc = bn2.getLocationOnScreen();125bn2Loc.translate(bn2.getWidth() / 2, bn2.getHeight() / 2);126127bs1Loc = bs1.getLocationOnScreen();128bs1Loc.translate(bs1.getWidth() / 2, bs1.getHeight() / 2);129130bs2Loc = bs2.getLocationOnScreen();131bs2Loc.translate(bs2.getWidth() / 2, bs2.getHeight() / 2);132}133134private void mouseClick(Robot r, Point p)135throws Exception136{137r.mouseMove(p.x, p.y);138r.mousePress(InputEvent.BUTTON1_MASK);139r.mouseRelease(InputEvent.BUTTON1_MASK);140r.waitForIdle();141}142143private void start()144throws Exception145{146r.setAutoDelay(200);147148unblocked1 = false;149mouseClick(r, bn1Loc);150if (!unblocked1)151{152throw new RuntimeException("Test FAILED: frame1 must be unblocked, if no modal internal frames are shown");153}154155unblocked2 = false;156mouseClick(r, bn2Loc);157if (!unblocked2)158{159throw new RuntimeException("Test FAILED: frame2 must be unblocked, if no modal internal frame is shown in it");160}161162mouseClick(r, bs1Loc);163164unblocked1 = false;165mouseClick(r, bn1Loc);166if (unblocked1)167{168throw new RuntimeException("Test FAILED: frame1 must be blocked, if a modal internal frame is shown in it");169}170171unblocked2 = false;172mouseClick(r, bn2Loc);173if (!unblocked2)174{175throw new RuntimeException("Test FAILED: frame2 must be unblocked, if no modal internal frame is shown in it");176}177178mouseClick(r, bs2Loc);179180unblocked2 = false;181mouseClick(r, bn2Loc);182if (unblocked2)183{184throw new RuntimeException("Test FAILED: frame2 must be blocked, if a modal internal frame is shown in it");185}186}187188private static ModalInternalFrameTest test;189190public static void main(String[] args)191throws Exception192{193r = new Robot();194test = new ModalInternalFrameTest();195SwingUtilities.invokeAndWait(new Runnable()196{197public void run()198{199test.init();200}201});202r.waitForIdle();203SwingUtilities.invokeAndWait(new Runnable()204{205public void run()206{207test.getLocations();208}209});210test.start();211}212}213214215