Path: blob/master/test/jdk/java/awt/Frame/SetMaximizedBounds/MaximizedMovedWindow.java
41153 views
/*1* Copyright (c) 2015, 2017, 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*/22import java.awt.*;2324/**25* @test26* @key headful27* @bug 806573928* @summary Moved window is maximazed to new screen29* @author Alexandr Scherbatiy30*31* @run main MaximizedMovedWindow32*/3334public class MaximizedMovedWindow {3536public static void main(String[] args) throws Exception {3738//Supported platforms are Windows and OS X.39String os = System.getProperty("os.name").toLowerCase();40if (!os.contains("os x")) {41return;42}4344if (!Toolkit.getDefaultToolkit().45isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {46return;47}4849GraphicsEnvironment ge = GraphicsEnvironment.50getLocalGraphicsEnvironment();5152if (ge.isHeadlessInstance()) {53return;54}5556GraphicsDevice[] devices = ge.getScreenDevices();5758if (devices.length < 2) {59return;60}6162Frame frame = null;63try {6465GraphicsConfiguration gc1 = devices[0].getDefaultConfiguration();66GraphicsConfiguration gc2 = devices[1].getDefaultConfiguration();6768Robot robot = new Robot();69robot.setAutoDelay(50);7071frame = new Frame();72Rectangle maxArea1 = getMaximizedScreenArea(gc1);73frame.setBounds(getSmallerRectangle(maxArea1));74frame.setVisible(true);75robot.waitForIdle();7677frame.setExtendedState(Frame.MAXIMIZED_BOTH);78robot.waitForIdle();79robot.delay(1000);8081Rectangle bounds = frame.getBounds();82if (!bounds.equals(maxArea1)) {83throw new RuntimeException("The bounds of the Frame do not equal"84+ " to screen 1 size");85}8687frame.setExtendedState(Frame.NORMAL);88robot.waitForIdle();89robot.delay(1000);9091Rectangle maxArea2 = getMaximizedScreenArea(gc2);92frame.setBounds(getSmallerRectangle(maxArea2));93robot.waitForIdle();94robot.delay(1000);9596frame.setExtendedState(Frame.MAXIMIZED_BOTH);97robot.waitForIdle();98robot.delay(1000);99100bounds = frame.getBounds();101if (!bounds.equals(maxArea2)) {102throw new RuntimeException("The bounds of the Frame do not equal"103+ " to screen 2 size");104}105} finally {106if (frame != null) {107frame.dispose();108}109}110}111112static Rectangle getSmallerRectangle(Rectangle rect) {113return new Rectangle(114rect.x + rect.width / 6,115rect.y + rect.height / 6,116rect.width / 3,117rect.height / 3);118}119static Rectangle getMaximizedScreenArea(GraphicsConfiguration gc) {120Rectangle bounds = gc.getBounds();121Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);122return new Rectangle(123bounds.x + insets.left,124bounds.y + insets.top,125bounds.width - insets.left - insets.right,126bounds.height - insets.top - insets.bottom);127}128}129130131