Path: blob/master/test/jdk/javax/swing/JInternalFrame/8145060/TestJInternalFrameMinimize.java
41153 views
/*1* Copyright (c) 2015,2016, 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 814506027* @summary Minimizing a JInternalFrame not shifting focus to frame below it28* @library ../../regtesthelpers29* @build Util30* @run main TestJInternalFrameMinimize31*/3233import java.awt.Point;34import java.awt.Robot;35import java.awt.event.ActionEvent;36import java.awt.event.ActionListener;37import java.awt.event.InputEvent;38import java.beans.PropertyVetoException;39import javax.swing.JFrame;40import javax.swing.JDesktopPane;41import javax.swing.JMenu;42import javax.swing.JMenuBar;43import javax.swing.JMenuItem;44import javax.swing.JInternalFrame;45import javax.swing.SwingUtilities;46import javax.swing.Timer;4748public class TestJInternalFrameMinimize {4950private static JDesktopPane desktopPane;51private static JFrame frame = new JFrame("Test Frame");52private static int count = 0;53private static JMenu menu;54private static JMenuBar menuBar;55private static JMenuItem menuItem;56private static Robot robot;57private static ActionListener listener;58private static Timer timer;59private static int counter;60private static boolean testFailed;6162public static void main(String[] args) throws Exception {63robot = new Robot();64SwingUtilities.invokeAndWait(new Runnable() {65@Override66public void run() {67createUI();68}69});70robot.waitForIdle();71executeTest();72if (testFailed) {73throw new RuntimeException("Test Failed");74}75dispose();76}7778private static void createUI() {7980desktopPane = new JDesktopPane();81frame.getContentPane().add(desktopPane);82frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);8384menuBar = new JMenuBar();85frame.setJMenuBar(menuBar);8687menu = new JMenu("File");88menuBar.add(menu);8990menuItem = new JMenuItem("New Child");91menuItem.addActionListener(92new ActionListener() {93@Override94public void actionPerformed(ActionEvent e) {95JInternalFrame f = new JInternalFrame("Child "96+ (++count), true, true, true, true);97f.setSize(200, 300);98f.setLocation(count * 20, count * 20);99desktopPane.add(f);100f.setVisible(true);101}102});103menu.add(menuItem);104frame.setSize(500, 500);105frame.setLocationRelativeTo(null);106frame.setVisible(true);107}108109private static void executeTest() throws Exception {110111Point point = Util.getCenterPoint(menu);112performMouseOperations(point);113point = Util.getCenterPoint(menuItem);114performMouseOperations(point);115point = Util.getCenterPoint(menu);116performMouseOperations(point);117point = Util.getCenterPoint(menuItem);118performMouseOperations(point);119point = Util.getCenterPoint(menu);120performMouseOperations(point);121point = Util.getCenterPoint(menuItem);122performMouseOperations(point);123point = Util.getCenterPoint(menu);124performMouseOperations(point);125point = Util.getCenterPoint(menuItem);126performMouseOperations(point);127SwingUtilities.invokeAndWait(new Runnable() {128129@Override130public void run() {131listener = new ActionListener() {132@Override133public void actionPerformed(ActionEvent ae) {134JInternalFrame internalFrame135= desktopPane.getSelectedFrame();136if (internalFrame != null) {137try {138internalFrame.setIcon(true);139++counter;140} catch (PropertyVetoException ex) {141}142}143if (counter == 4) {144try {145timer.stop();146JInternalFrame currentSelectedFrame147= desktopPane.getSelectedFrame();148if (internalFrame.equals(currentSelectedFrame)) {149frame.dispose();150testFailed = true;151}152} catch (Exception ex) {153}154}155}156};157}158});159timer = new Timer(1000, listener);160timer.start();161robot.delay(1000);162}163164private static void dispose() throws Exception {165SwingUtilities.invokeAndWait(new Runnable() {166167@Override168public void run() {169frame.dispose();170}171});172}173174private static void performMouseOperations(Point point) {175robot.mouseMove(point.x, point.y);176robot.mousePress(InputEvent.BUTTON1_MASK);177robot.mouseRelease(InputEvent.BUTTON1_MASK);178robot.delay(1000);179robot.waitForIdle();180}181}182183184