1 /*
   2  * Copyright (c) 2004, 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 Construct a Frame, zoom it from the normal state and back forth
  29  *          using Frame.ZOOMED and Frame.NORMAL. Iconofy from the zoomed
  30  *          state and back forth using Frame.ICONIFIED and Frame.NORMAL and
  31  *          check the zoomed size is same as the screen size. Check the
  32  *          location of the frame after restoration from zoom or icon.
  33  * @author Aruna Samji
  34  * @library ../../../lib/testlibrary
  35  * @build ExtendedRobot
  36  * @run main TaskZoomFrameChangeState
  37  */
  38 
  39 public class TaskZoomFrameChangeState extends Task<GUIZoomFrame> {
  40 
  41     public static void main (String[] args) throws Exception {
  42         new TaskZoomFrameChangeState(new GUIZoomFrame(), new ExtendedRobot()).runTask();
  43     }
  44 
  45     TaskZoomFrameChangeState(GUIZoomFrame gui, ExtendedRobot robot) {
  46         super(gui, robot);
  47     }
  48 
  49     public void task() throws Exception {
  50         gui.frame1.setLayout(null);
  51         gui.frame1.setVisible(true);
  52         gui.frame1.removeAll();
  53         gui.frame1.add(gui.icon);
  54         if( gui.frame1.getExtendedState() != Frame.NORMAL )
  55             gui.frame1.setExtendedState(Frame.NORMAL);
  56 
  57         robot.waitForIdle(1000);
  58 
  59         Point buttonOrigin;
  60         Point buttonCenter;
  61 
  62         Point frameOrigin = gui.frame1.getLocationOnScreen();
  63         Point newposition;
  64 
  65         gui.frame1.setExtendedState(Frame.ICONIFIED);
  66         robot.waitForIdle(1000);
  67 
  68         //To check whether the bitwise mask for ICONIFIED state is set...
  69         if (gui.frame1.getExtendedState() != Frame.ICONIFIED)
  70             throw new RuntimeException("The bitwise mask Frame.ICONIFIED is " +
  71                     "not set when the frame is in ICONIFIED state");
  72 
  73         //To check whether the Frame is iconified programmatically..........
  74         if (! gui.iconify)
  75             throw new RuntimeException("Frame is not Iconified");
  76 
  77         //Normalising the Frame....
  78         gui.frame1.setExtendedState(Frame.NORMAL);
  79         robot.waitForIdle(1000);
  80 
  81         //To check whether the bitwise mask for NORMAL state is set...
  82         if (gui.frame1.getExtendedState() != Frame.NORMAL)
  83             throw new RuntimeException("The bitwise mask Frame.NORMAL is not " +
  84                     "set when the frame is in NORMAL state after Iconofied");
  85 
  86         //To check whether the Frame is normalised programmatically..........
  87         if (! gui.normal)
  88             throw new RuntimeException("Frame is not restored to normal after" +
  89                     " Iconofied");
  90 
  91         newposition = gui.frame1.getLocationOnScreen();
  92 
  93         if((frameOrigin.x != newposition.x)&(frameOrigin.y != newposition.y))
  94             throw new RuntimeException("The frame is not positioned back " +
  95                     "to the original place on the screen after Iconified");
  96 
  97         gui.frame1.remove(gui.icon);
  98         robot.waitForIdle(1000);
  99 
 100         //To check whether the state is supported in the platform....
 101         if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_HORIZ)) {
 102             //System.out.println("Frame.MAXIMIZED_HORIZ is supported");
 103             //Maximising the Frame horizontally.........
 104             gui.frame1.setExtendedState(Frame.MAXIMIZED_HORIZ);
 105             robot.waitForIdle(1000);
 106 
 107             //To check whether the bitwise mask for MAXIMIZED_HORIZ state is set...
 108             if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_HORIZ)
 109                 throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_HOR " +
 110                         "is not set when the frame is in MAXIMIZED_HOR state");
 111 
 112             //To check whether the Frame is maximized horizontally..........
 113             if (! gui.maxHor)
 114                 throw new RuntimeException("Frame is not maximized horizontally");
 115 
 116             gui.frame1.setExtendedState(Frame.NORMAL);
 117             robot.waitForIdle(1000);
 118         }
 119 
 120         //To check whether the state is supported in the platform....
 121         if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_VERT)) {
 122             //System.out.println("Frame.MAXIMIZED_VERT is supported");
 123             //Maximising the Frame vertically.........
 124             gui.frame1.setExtendedState(Frame.MAXIMIZED_VERT);
 125             robot.waitForIdle(1000);
 126             //To check whether the bitwise mask for MAXIMIZED_VERT state is set...
 127             if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_VERT)
 128                 throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_VERT " +
 129                         "is not set when the frame is in MAXIMIZED_VERT state");
 130 
 131             //To check whether the Frame is maximized vertically..........
 132             if (! gui.maxVer)
 133                 throw new RuntimeException("Frame is not maximized vertically");
 134 
 135             gui.frame1.setExtendedState(Frame.NORMAL);
 136             robot.waitForIdle(1000);
 137         }
 138 
 139         if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)){
 140             //Maximising the Frame fully
 141             gui.frame1.setExtendedState(Frame.MAXIMIZED_BOTH);
 142         }
 143         robot.waitForIdle(1000);
 144 
 145         //To check whether the state is supported in the platform....
 146         if (Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
 147             //To check whether the bitwise mask for MAXIMIZED_BOTH state is set...
 148             if (gui.frame1.getExtendedState() != Frame.MAXIMIZED_BOTH)
 149                 throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_BOTH " +
 150                         "is not set when the frame is in MAXIMIZED_BOTH state");
 151 
 152             //To check whether the Frame is maximized fully..........
 153             if (! gui.maxBoth)
 154                 throw new RuntimeException("Frame is not maximized fully");
 155         }
 156 
 157         //Normalising the Frame....
 158         gui.frame1.setExtendedState(Frame.NORMAL);
 159         robot.waitForIdle(10000);
 160 
 161         //To check whether the bitwise mask for NORMAL state is set...
 162         if (gui.frame1.getExtendedState() != Frame.NORMAL)
 163             throw new RuntimeException("The bitwise mask Frame.NORMAL " +
 164                     "is not set when the frame is in NORMAL state after Zoomed");
 165 
 166         //To check whether the Frame is normalised programmatically..........
 167         if (! gui.normal)
 168             throw new RuntimeException("Frame is not restored to normal after Zoomed");
 169 
 170         gui.frame1.remove(gui.maximize);
 171         robot.waitForIdle(1000);
 172     }
 173 }