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