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