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