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