0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A @test
0N/A @bug 6518753
0N/A @summary Tests the functionality of modal Swing internal frames
0N/A @author artem.ananiev: area=awt.modal
0N/A @run main/timeout=30 ModalInternalFrameTest
0N/A*/
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/A
0N/Aimport javax.swing.*;
0N/A
0N/Aimport sun.awt.*;
0N/A
0N/Apublic class ModalInternalFrameTest
0N/A{
0N/A private boolean passed = true;
0N/A
0N/A private JDesktopPane pane1;
0N/A private JDesktopPane pane2;
0N/A
0N/A private JFrame frame1;
0N/A private JFrame frame2;
0N/A
0N/A private JButton bn1;
0N/A private JButton bs1;
0N/A private JButton bn2;
0N/A private JButton bs2;
0N/A
0N/A private Point bn1Loc;
0N/A private Point bs1Loc;
0N/A private Point bn2Loc;
0N/A private Point bs2Loc;
0N/A
0N/A private volatile boolean unblocked1 = true;
0N/A private volatile boolean unblocked2 = true;
0N/A
0N/A public ModalInternalFrameTest()
0N/A {
0N/A }
0N/A
0N/A public void init()
0N/A {
0N/A pane1 = new JDesktopPane();
0N/A pane2 = new JDesktopPane();
0N/A
0N/A frame1 = new JFrame("F1");
0N/A frame1.setBounds(100, 100, 320, 240);
0N/A frame1.getContentPane().setLayout(new BorderLayout());
0N/A frame1.getContentPane().add(pane1);
0N/A bn1 = new JButton("Test");
0N/A bn1.addActionListener(new ActionListener()
0N/A {
0N/A public void actionPerformed(ActionEvent ae)
0N/A {
0N/A unblocked1 = true;
0N/A }
0N/A });
0N/A frame1.getContentPane().add(bn1, BorderLayout.NORTH);
0N/A bs1 = new JButton("Show dialog");
0N/A bs1.addActionListener(new ActionListener()
0N/A {
0N/A public void actionPerformed(ActionEvent ae)
0N/A {
0N/A JOptionPane.showInternalMessageDialog(pane1, "Dialog1");
0N/A }
0N/A });
0N/A frame1.getContentPane().add(bs1, BorderLayout.SOUTH);
0N/A
0N/A frame2 = new JFrame("F2");
0N/A frame2.setBounds(100, 400, 320, 240);
0N/A frame2.getContentPane().setLayout(new BorderLayout());
0N/A frame2.getContentPane().add(pane2);
0N/A bn2 = new JButton("Test");
0N/A bn2.addActionListener(new ActionListener()
0N/A {
0N/A public void actionPerformed(ActionEvent ae)
0N/A {
0N/A unblocked2 = true;
0N/A }
0N/A });
0N/A frame2.getContentPane().add(bn2, BorderLayout.NORTH);
0N/A bs2 = new JButton("Show dialog");
0N/A bs2.addActionListener(new ActionListener()
0N/A {
0N/A public void actionPerformed(ActionEvent ae)
0N/A {
0N/A JOptionPane.showInternalMessageDialog(pane2, "Dialog2");
0N/A }
0N/A });
0N/A frame2.getContentPane().add(bs2, BorderLayout.SOUTH);
0N/A
0N/A frame1.setVisible(true);
0N/A frame2.setVisible(true);
0N/A }
0N/A
0N/A private void getLocations()
0N/A {
0N/A bn1Loc = bn1.getLocationOnScreen();
0N/A bn1Loc.translate(bn1.getWidth() / 2, bn1.getHeight() / 2);
0N/A
0N/A bn2Loc = bn2.getLocationOnScreen();
0N/A bn2Loc.translate(bn2.getWidth() / 2, bn2.getHeight() / 2);
0N/A
0N/A bs1Loc = bs1.getLocationOnScreen();
0N/A bs1Loc.translate(bs1.getWidth() / 2, bs1.getHeight() / 2);
0N/A
0N/A bs2Loc = bs2.getLocationOnScreen();
0N/A bs2Loc.translate(bs2.getWidth() / 2, bs2.getHeight() / 2);
0N/A }
0N/A
0N/A private void mouseClick(Robot r, Point p)
0N/A throws Exception
0N/A {
0N/A r.mouseMove(p.x, p.y);
0N/A r.mousePress(InputEvent.BUTTON1_MASK);
0N/A r.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
0N/A }
0N/A
0N/A private void start()
0N/A throws Exception
0N/A {
0N/A Robot r = new Robot();
0N/A r.setAutoDelay(200);
0N/A
0N/A unblocked1 = false;
0N/A mouseClick(r, bn1Loc);
0N/A if (!unblocked1)
0N/A {
0N/A throw new RuntimeException("Test FAILED: frame1 must be unblocked, if no modal internal frames are shown");
0N/A }
0N/A
0N/A unblocked2 = false;
0N/A mouseClick(r, bn2Loc);
0N/A if (!unblocked2)
0N/A {
0N/A throw new RuntimeException("Test FAILED: frame2 must be unblocked, if no modal internal frame is shown in it");
0N/A }
0N/A
0N/A mouseClick(r, bs1Loc);
0N/A
0N/A unblocked1 = false;
0N/A mouseClick(r, bn1Loc);
0N/A if (unblocked1)
0N/A {
0N/A throw new RuntimeException("Test FAILED: frame1 must be blocked, if a modal internal frame is shown in it");
0N/A }
0N/A
0N/A unblocked2 = false;
0N/A mouseClick(r, bn2Loc);
0N/A if (!unblocked2)
0N/A {
0N/A throw new RuntimeException("Test FAILED: frame2 must be unblocked, if no modal internal frame is shown in it");
0N/A }
0N/A
0N/A mouseClick(r, bs2Loc);
0N/A
0N/A unblocked2 = false;
0N/A mouseClick(r, bn2Loc);
0N/A if (unblocked2)
0N/A {
0N/A throw new RuntimeException("Test FAILED: frame2 must be blocked, if a modal internal frame is shown in it");
0N/A }
0N/A }
0N/A
0N/A private static ModalInternalFrameTest test;
0N/A
0N/A public static void main(String[] args)
0N/A throws Exception
0N/A {
0N/A test = new ModalInternalFrameTest();
0N/A SwingUtilities.invokeAndWait(new Runnable()
0N/A {
0N/A public void run()
0N/A {
0N/A test.init();
0N/A }
0N/A });
0N/A ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
0N/A SwingUtilities.invokeAndWait(new Runnable()
0N/A {
0N/A public void run()
0N/A {
0N/A test.getLocations();
0N/A }
0N/A });
0N/A test.start();
0N/A }
0N/A}