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.*;
  25 
  26 /*
  27  * @test
  28  * @summary When Frame.setExtendedState(Frame.MAXIMIZED_BOTH)
  29  *          is called for a Frame after been called setMaximizedBounds() with
  30  *          certain value, Frame bounds must equal to this value.
  31  *
  32  * @library ../../../../lib/testlibrary
  33  * @build ExtendedRobot
  34  * @run main SetMaximizedBounds
  35  */
  36 
  37 public class SetMaximizedBounds {
  38 
  39     Frame frame;
  40     Rectangle bound;
  41     boolean supported;
  42     ExtendedRobot robot;
  43     static Rectangle max = new Rectangle(100,100,400,400);
  44 
  45     public void doTest() throws Exception {
  46         robot = new ExtendedRobot();
  47 
  48         EventQueue.invokeAndWait( () -> {
  49             frame = new Frame( "TestFrame ");
  50             frame.setLayout(new FlowLayout());
  51 
  52             if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
  53                 supported = true;
  54                 frame.setMaximizedBounds(max);
  55             } else {
  56                 supported = false;
  57             }
  58 
  59             frame.setSize(200, 200);
  60             frame.setVisible(true);
  61         });
  62 
  63         robot.waitForIdle(2000);
  64         if (supported) {
  65             EventQueue.invokeAndWait( () -> {
  66                 frame.setExtendedState(Frame.MAXIMIZED_BOTH);
  67             });
  68             robot.waitForIdle(2000);
  69             bound = frame.getBounds();
  70             if(!bound.equals(max))
  71                 throw new RuntimeException("The bounds of the Frame do not equal to what"
  72                     + " is specified when the frame is in Frame.MAXIMIZED_BOTH state");
  73         } else {
  74             System.out.println("Frame.MAXIMIZED_BOTH not supported");
  75         }
  76 
  77         frame.dispose();
  78     }
  79 
  80     public static void main(String[] args) throws Exception {
  81         String os = System.getProperty("os.name").toLowerCase();
  82         System.out.println(os);
  83         if (os.contains("windows") || os.contains("os x"))
  84             new SetMaximizedBounds().doTest();
  85         else
  86             System.out.println("Platform "+os+" is not supported. Supported platforms are Windows and OS X.");
  87     }
  88 }