1 /*
   2  * Copyright (c) 2007, 2014, 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 
  24 import java.awt.Frame;
  25 import javax.swing.JFrame;
  26 import java.awt.GraphicsEnvironment;
  27 import java.awt.Toolkit;
  28 import java.awt.EventQueue;
  29 import java.awt.FlowLayout;
  30 import java.awt.Rectangle;
  31 import java.lang.reflect.InvocationTargetException;
  32 /*
  33  * @test
  34  * @bug 8022302
  35  * @summary Set extendedState Frame.MAXIMIZED_BOTH for undecorated Frame and JFrame.
  36  *          Check if resulted size is equal to GraphicsEnvironment.getMaximumWindowBounds().
  37  *
  38  * @library ../../../../lib/testlibrary
  39  * @build ExtendedRobot
  40  * @run main MaximizedUndecorated
  41  */
  42 
  43 
  44 public class MaximizedUndecorated {
  45     private Frame frame;
  46     private ExtendedRobot robot;
  47     public static void main(String args[]) {
  48         if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
  49             return;
  50         }
  51         MaximizedUndecorated test = new MaximizedUndecorated();
  52         boolean doPass = true;
  53         try{
  54             if( !test.doTest(true) ) {
  55                 System.out.println("Actual bounds differ from Maximum Window Bounds for JFrame");
  56                 doPass = false;
  57             }
  58             if( !test.doTest(false) ) {
  59                 System.out.println("Actual bounds differ from Maximum Window Bounds for Frame");
  60                 doPass = false;
  61             }
  62         }catch(Exception ie) {
  63             ie.printStackTrace();
  64             throw new RuntimeException("Interrupted or InvocationTargetException occured");
  65         }
  66         if(!doPass) {
  67             throw new RuntimeException("Actual bounds of undecorated frame differ from Maximum Windows Bounds for this platform");
  68         }
  69     }
  70     MaximizedUndecorated() {
  71         try {
  72             robot = new ExtendedRobot();
  73         }catch(Exception ex) {
  74             ex.printStackTrace();
  75             throw new RuntimeException("Cannot create robot");
  76         }
  77     }
  78     boolean doTest(boolean swingFrame) throws InterruptedException, InvocationTargetException {
  79         EventQueue.invokeAndWait( () -> {
  80             frame = swingFrame? new JFrame("Test Frame") : new Frame("Test Frame");
  81             frame.setLayout(new FlowLayout());
  82             frame.setBounds(50,50,300,300);
  83             frame.setUndecorated(true);
  84             frame.setVisible(true);
  85         });
  86         robot.waitForIdle(2000);
  87         EventQueue.invokeAndWait( () -> {
  88             frame.setExtendedState(Frame.MAXIMIZED_BOTH);
  89         });
  90         robot.waitForIdle(2000);
  91         Rectangle actualBounds = frame.getBounds();
  92         Rectangle expectedBounds = GraphicsEnvironment.
  93                getLocalGraphicsEnvironment().getMaximumWindowBounds();
  94         EventQueue.invokeAndWait( () -> {
  95             frame.dispose();
  96         });
  97 
  98         return actualBounds.equals(expectedBounds);
  99     }
 100 }