1 /* 2 * Copyright (c) 2020, 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.Dialog; 25 import java.awt.Frame; 26 import java.awt.GraphicsConfiguration; 27 import java.awt.GraphicsDevice; 28 import java.awt.GraphicsEnvironment; 29 import java.awt.Insets; 30 import java.awt.Point; 31 import java.awt.Rectangle; 32 import java.awt.Robot; 33 import java.awt.Toolkit; 34 import java.awt.Window; 35 36 /** 37 * @test 38 * @key headful 39 * @bug 8211999 40 * @run main/timeout=300 SlowMotion 41 * @summary places the window on the screen outside of any insets, and waits to 42 * catch any strange window moving 43 */ 44 public final class SlowMotion { 45 46 // some additional space, if getScreenInsets() does not work, say on Linux 47 private static final int SAFE = 100; 48 private static final int HEIGHT = 350; 49 private static final int WIDTH = 279; 50 private static Robot robot; 51 52 public static void main(final String[] args) throws Exception { 53 robot = new Robot(); 54 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 55 GraphicsDevice[] sds = ge.getScreenDevices(); 56 57 for (GraphicsDevice sd : sds) { 58 GraphicsConfiguration gc = sd.getDefaultConfiguration(); 59 Rectangle bounds = gc.getBounds(); 60 bounds.translate(SAFE, SAFE); 61 Point point = new Point(bounds.x, bounds.y); 62 Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); 63 while (point.y < bounds.y + bounds.height - insets.bottom - HEIGHT - SAFE * 2) { 64 while (point.x < bounds.x + bounds.width - insets.right - WIDTH - SAFE * 2) { 65 test(point, new Frame()); 66 test(point, new Window(null)); 67 test(point, new Dialog((Dialog) null)); 68 point.translate(bounds.width / 6, 0); 69 } 70 point.setLocation(bounds.x, point.y + bounds.height / 5); 71 } 72 } 73 } 74 75 private static void test(final Point loc, Window window) { 76 try { 77 window.setBounds(loc.x, loc.y, WIDTH, HEIGHT); 78 window.setVisible(true); 79 robot.delay(1000); // intentionally very slow, we try to catch 80 // very very last suspicion event 81 Rectangle bounds = window.getBounds(); 82 if (loc.x != bounds.x || loc.y != bounds.y 83 || bounds.width != WIDTH || bounds.height != HEIGHT) { 84 System.err.println("Component = " + window); 85 System.err.println("Actual bounds = " + bounds); 86 System.err.println("Expected location = " + loc); 87 System.err.println("Expected width = " + WIDTH); 88 System.err.println("Expected height = " + HEIGHT); 89 throw new RuntimeException(); 90 } 91 } finally { 92 window.dispose(); 93 } 94 } 95 }