Path: blob/master/test/jdk/java/awt/Frame/MaximizedToIconified/MaximizedToIconified.java
41153 views
/*1* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 4977491 816076727* @summary State changes should always be reported as events28* @run main MaximizedToIconified29*/3031/*32* MaximizedToIconified.java33*34* summary: Invoking setExtendedState(ICONIFIED) on a maximized35* frame should not combine the maximized and iconified36* states in the newState of the state change event.37*/3839import java.awt.Frame;40import java.awt.Robot;41import java.awt.Toolkit;42import java.awt.event.WindowEvent;43import java.awt.event.WindowStateListener;4445public class MaximizedToIconified46{47static volatile int lastFrameState = Frame.NORMAL;48static volatile boolean failed = false;49static volatile Toolkit myKit;50private static Robot robot;5152private static void checkState(Frame frame, int state) {53frame.setExtendedState(state);54robot.waitForIdle();55robot.delay(100);5657System.out.println("state = " + state + "; getExtendedState() = " + frame.getExtendedState());5859if (failed) {60frame.dispose();61throw new RuntimeException("getOldState() != previous getNewState() in WINDOW_STATE_CHANGED event.");62}63if (lastFrameState != frame.getExtendedState()) {64frame.dispose();65throw new RuntimeException("getExtendedState() != last getNewState() in WINDOW_STATE_CHANGED event.");66}67if (frame.getExtendedState() != state) {68frame.dispose();69throw new RuntimeException("getExtendedState() != " + state + " as expected.");70}71}7273private static void examineStates(int states[]) {7475Frame frame = new Frame("test");76frame.setSize(200, 200);77frame.setVisible(true);7879robot.waitForIdle();8081frame.addWindowStateListener(new WindowStateListener() {82public void windowStateChanged(WindowEvent e) {83System.out.println("last = " + lastFrameState + "; getOldState() = " + e.getOldState() +84"; getNewState() = " + e.getNewState());85if (e.getOldState() == lastFrameState) {86lastFrameState = e.getNewState();87} else {88System.out.println("Wrong getOldState(): expected = " + lastFrameState + "; received = " +89e.getOldState());90failed = true;91}92}93});9495for (int state : states) {96if (myKit.isFrameStateSupported(state)) {97checkState(frame, state);98} else {99System.out.println("Frame state = " + state + " is NOT supported by the native system. The state is skipped.");100}101}102103if (frame != null) {104frame.dispose();105}106}107108private static void doTest() {109110myKit = Toolkit.getDefaultToolkit();111112// NOTE! Compound states (like MAXIMIZED_BOTH | ICONIFIED) CANNOT be used,113// because Toolkit.isFrameStateSupported() method reports these states114// as not supported. And such states will simply be skipped.115examineStates(new int[] {Frame.MAXIMIZED_BOTH, Frame.ICONIFIED, Frame.NORMAL});116examineStates(new int[] {Frame.ICONIFIED, Frame.MAXIMIZED_BOTH, Frame.NORMAL});117118}119120public static void main( String args[] ) throws Exception121{122robot = new Robot();123doTest();124125}126127}128129130