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 with some components and zoom the frame and bring 29 * it back to normal state. 30 * @author Aruna Samji 31 * @library ../../../lib/testlibrary 32 * @build ExtendedRobot 33 * @run main TaskZoomFrameRepaint 34 */ 35 36 public class TaskZoomFrameRepaint extends Task<GUIZoomFrame> { 37 38 public static void main (String[] args) throws Exception { 39 new TaskZoomFrameRepaint(GUIZoomFrame.class, new ExtendedRobot()).runTask(); 40 } 41 42 TaskZoomFrameRepaint(Class guiClass, ExtendedRobot robot) throws Exception { 43 super(guiClass, robot); 44 } 45 46 public void task() throws Exception { 47 EventQueue.invokeAndWait(() -> { 48 gui.frame2.setVisible(true); 49 gui.frame2.removeAll(); 50 gui.frame2.add(gui.button); 51 gui.frame2.add(gui.textarea); 52 if (gui.frame2.getExtendedState() != Frame.NORMAL) 53 gui.frame2.setExtendedState(Frame.NORMAL); 54 }); 55 robot.waitForIdle(1000); 56 57 Point buttonOrigin, newbuttonOrigin, newbuttonCenter; 58 Point textareaOrigin, newtextareaOrigin, newtextareaCenter ; 59 60 //to find the lenght and width of the component originally 61 buttonOrigin = gui.button.getLocationOnScreen(); 62 textareaOrigin = gui.textarea.getLocationOnScreen(); 63 64 if (Toolkit.getDefaultToolkit().isFrameStateSupported( 65 Frame.MAXIMIZED_BOTH)){ 66 //Maximising the Frame fully......... 67 EventQueue.invokeAndWait(() -> 68 gui.frame2.setExtendedState(Frame.MAXIMIZED_BOTH) 69 ); 70 robot.waitForIdle(1000); 71 //To check whether the bitwise mask for MAXIMIZED_BOTH state is set... 72 if (gui.frame2.getExtendedState() != Frame.MAXIMIZED_BOTH) 73 throw new RuntimeException("The bitwise mask Frame.MAXIMIZED_BOTH " + 74 "is not set when the frame is in MAXIMIZED_BOTH state"); 75 76 //To check whether the Frame is maximized fully.......... 77 if (gui.maxBoth == false) 78 throw new RuntimeException("Frame is not maximized fully"); 79 } 80 81 //Normalising the Frame.... 82 EventQueue.invokeAndWait(() -> 83 gui.frame2.setExtendedState(Frame.NORMAL) 84 ); 85 robot.waitForIdle(1000); 86 87 //To check whether the bitwise mask for NORMAL state is set... 88 if (gui.frame2.getExtendedState() != Frame.NORMAL) 89 throw new RuntimeException("The bitwise mask Frame.NORMAL is not " + 90 "set when the frame is in NORMAL state"); 91 92 //To check whether the Frame is normalised programmatically.......... 93 if (! gui.normal) 94 throw new RuntimeException("Frame is not restored to normal"); 95 96 //to find the lenght and width of the component after zommed and back to normal 97 newbuttonOrigin = gui.button.getLocationOnScreen(); 98 newtextareaOrigin = gui.textarea.getLocationOnScreen(); 99 newbuttonCenter = gui.button.getLocationOnScreen(); 100 newbuttonCenter.translate(gui.button.getWidth()/2, gui.button.getHeight()/2); 101 newtextareaCenter = gui.textarea.getLocationOnScreen(); 102 newtextareaCenter.translate(gui.textarea.getWidth()/2, gui.textarea.getHeight()/2); 103 104 if((buttonOrigin.x != newbuttonOrigin.x)&(buttonOrigin.y != newbuttonOrigin.y)) 105 throw new RuntimeException("The button is not positioned back to the " + 106 "original place on the screen after iconified"); 107 108 if((textareaOrigin.x != newtextareaOrigin.x)&(textareaOrigin.y != newtextareaOrigin.y)) 109 throw new RuntimeException("The TextArea is not positioned back to the " + 110 "original place on the screen after iconified"); 111 112 EventQueue.invokeAndWait(() -> { 113 gui.frame2.remove(gui.button); 114 gui.frame2.remove(gui.textarea); 115 }); 116 robot.waitForIdle(1000); 117 } 118 }