MaximizedUndecorated.java revision 14851:980da45565c8
1/*
2 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24import java.awt.Frame;
25import javax.swing.JFrame;
26import java.awt.GraphicsEnvironment;
27import java.awt.Toolkit;
28import java.awt.EventQueue;
29import java.awt.FlowLayout;
30import java.awt.Rectangle;
31import java.lang.reflect.InvocationTargetException;
32/*
33 * @test
34 * @key headful
35 * @bug 8022302
36 * @summary Set extendedState Frame.MAXIMIZED_BOTH for undecorated Frame and JFrame.
37 *          Check if resulted size is equal to GraphicsEnvironment.getMaximumWindowBounds().
38 *
39 * @library ../../../../lib/testlibrary
40 * @build ExtendedRobot
41 * @run main MaximizedUndecorated
42 */
43
44
45public class MaximizedUndecorated {
46    private Frame frame;
47    private ExtendedRobot robot;
48    public static void main(String args[]) {
49        if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
50            return;
51        }
52        MaximizedUndecorated test = new MaximizedUndecorated();
53        boolean doPass = true;
54        try{
55            if( !test.doTest(true) ) {
56                System.out.println("Actual bounds differ from Maximum Window Bounds for JFrame");
57                doPass = false;
58            }
59            if( !test.doTest(false) ) {
60                System.out.println("Actual bounds differ from Maximum Window Bounds for Frame");
61                doPass = false;
62            }
63        }catch(Exception ie) {
64            ie.printStackTrace();
65            throw new RuntimeException("Interrupted or InvocationTargetException occured");
66        }
67        if(!doPass) {
68            throw new RuntimeException("Actual bounds of undecorated frame differ from Maximum Windows Bounds for this platform");
69        }
70    }
71    MaximizedUndecorated() {
72        try {
73            robot = new ExtendedRobot();
74        }catch(Exception ex) {
75            ex.printStackTrace();
76            throw new RuntimeException("Cannot create robot");
77        }
78    }
79    boolean doTest(boolean swingFrame) throws InterruptedException, InvocationTargetException {
80        EventQueue.invokeAndWait( () -> {
81            frame = swingFrame? new JFrame("Test Frame") : new Frame("Test Frame");
82            frame.setLayout(new FlowLayout());
83            frame.setBounds(50,50,300,300);
84            frame.setUndecorated(true);
85            frame.setVisible(true);
86        });
87        robot.waitForIdle(2000);
88        EventQueue.invokeAndWait( () -> {
89            frame.setExtendedState(Frame.MAXIMIZED_BOTH);
90        });
91        robot.waitForIdle(2000);
92        Rectangle actualBounds = frame.getBounds();
93        Rectangle expectedBounds = GraphicsEnvironment.
94               getLocalGraphicsEnvironment().getMaximumWindowBounds();
95        EventQueue.invokeAndWait( () -> {
96            frame.dispose();
97        });
98
99        return actualBounds.equals(expectedBounds);
100    }
101}
102