Path: blob/master/test/jdk/java/awt/Modal/ModalInternalFrameTest/ModalInternalFrameTest.java
41153 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@key headful26@bug 651875327@summary Tests the functionality of modal Swing internal frames28@author artem.ananiev: area=awt.modal29@run main/timeout=30 ModalInternalFrameTest30*/3132import java.awt.*;33import java.awt.event.*;3435import javax.swing.*;3637public class ModalInternalFrameTest38{39private boolean passed = true;40private static Robot r;4142private JDesktopPane pane1;43private JDesktopPane pane2;4445private JFrame frame1;46private JFrame frame2;4748private JButton bn1;49private JButton bs1;50private JButton bn2;51private JButton bs2;5253private Point bn1Loc;54private Point bs1Loc;55private Point bn2Loc;56private Point bs2Loc;5758private volatile boolean unblocked1 = true;59private volatile boolean unblocked2 = true;6061public ModalInternalFrameTest()62{63}6465public void init()66{67pane1 = new JDesktopPane();68pane2 = new JDesktopPane();6970frame1 = new JFrame("F1");71frame1.setBounds(100, 100, 320, 240);72frame1.getContentPane().setLayout(new BorderLayout());73frame1.getContentPane().add(pane1);74bn1 = new JButton("Test");75bn1.addActionListener(new ActionListener()76{77public void actionPerformed(ActionEvent ae)78{79unblocked1 = true;80}81});82frame1.getContentPane().add(bn1, BorderLayout.NORTH);83bs1 = new JButton("Show dialog");84bs1.addActionListener(new ActionListener()85{86public void actionPerformed(ActionEvent ae)87{88JOptionPane.showInternalMessageDialog(pane1, "Dialog1");89}90});91frame1.getContentPane().add(bs1, BorderLayout.SOUTH);9293frame2 = new JFrame("F2");94frame2.setBounds(100, 400, 320, 240);95frame2.getContentPane().setLayout(new BorderLayout());96frame2.getContentPane().add(pane2);97bn2 = new JButton("Test");98bn2.addActionListener(new ActionListener()99{100public void actionPerformed(ActionEvent ae)101{102unblocked2 = true;103}104});105frame2.getContentPane().add(bn2, BorderLayout.NORTH);106bs2 = new JButton("Show dialog");107bs2.addActionListener(new ActionListener()108{109public void actionPerformed(ActionEvent ae)110{111JOptionPane.showInternalMessageDialog(pane2, "Dialog2");112}113});114frame2.getContentPane().add(bs2, BorderLayout.SOUTH);115116frame1.setVisible(true);117frame2.setVisible(true);118}119120private void getLocations()121{122bn1Loc = bn1.getLocationOnScreen();123bn1Loc.translate(bn1.getWidth() / 2, bn1.getHeight() / 2);124125bn2Loc = bn2.getLocationOnScreen();126bn2Loc.translate(bn2.getWidth() / 2, bn2.getHeight() / 2);127128bs1Loc = bs1.getLocationOnScreen();129bs1Loc.translate(bs1.getWidth() / 2, bs1.getHeight() / 2);130131bs2Loc = bs2.getLocationOnScreen();132bs2Loc.translate(bs2.getWidth() / 2, bs2.getHeight() / 2);133}134135private void mouseClick(Robot r, Point p)136throws Exception137{138r.mouseMove(p.x, p.y);139r.mousePress(InputEvent.BUTTON1_MASK);140r.mouseRelease(InputEvent.BUTTON1_MASK);141r.waitForIdle();142}143144private void start()145throws Exception146{147r.setAutoDelay(200);148149unblocked1 = false;150mouseClick(r, bn1Loc);151if (!unblocked1)152{153throw new RuntimeException("Test FAILED: frame1 must be unblocked, if no modal internal frames are shown");154}155156unblocked2 = false;157mouseClick(r, bn2Loc);158if (!unblocked2)159{160throw new RuntimeException("Test FAILED: frame2 must be unblocked, if no modal internal frame is shown in it");161}162163mouseClick(r, bs1Loc);164165unblocked1 = false;166mouseClick(r, bn1Loc);167if (unblocked1)168{169throw new RuntimeException("Test FAILED: frame1 must be blocked, if a modal internal frame is shown in it");170}171172unblocked2 = false;173mouseClick(r, bn2Loc);174if (!unblocked2)175{176throw new RuntimeException("Test FAILED: frame2 must be unblocked, if no modal internal frame is shown in it");177}178179mouseClick(r, bs2Loc);180181unblocked2 = false;182mouseClick(r, bn2Loc);183if (unblocked2)184{185throw new RuntimeException("Test FAILED: frame2 must be blocked, if a modal internal frame is shown in it");186}187}188189private static ModalInternalFrameTest test;190191public static void main(String[] args)192throws Exception193{194r = new Robot();195test = new ModalInternalFrameTest();196SwingUtilities.invokeAndWait(new Runnable()197{198public void run()199{200test.init();201}202});203r.waitForIdle();204SwingUtilities.invokeAndWait(new Runnable()205{206public void run()207{208test.getLocations();209}210});211test.start();212}213}214215216