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