1 /* 2 * Copyright (c) 2005, 2018, 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 /* 25 @test 26 @key headful 27 @bug 4868278 28 @summary Tests that GraphicsConfig for invisible (peerless) windows is 29 updated after showing the window 30 @library ../../regtesthelpers 31 @build Util 32 @run main WindowGCChangeTest 33 */ 34 35 import java.awt.*; 36 import java.awt.event.*; 37 38 import test.java.awt.regtesthelpers.Util; 39 40 public class WindowGCChangeTest { 41 42 public static void main(final String[] args) { 43 Robot robot = null; 44 try 45 { 46 robot = new Robot(); 47 } 48 catch (Exception z) 49 { 50 z.printStackTrace(System.err); 51 throw new RuntimeException("Test FAILED: couldn't create Robot instance", z); 52 } 53 Util.waitForIdle(robot); 54 55 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 56 GraphicsDevice[] gds = ge.getScreenDevices(); 57 // check 2-screens systems only 58 if (gds.length != 2) 59 { 60 return; 61 } 62 63 int defGDNo = 0; 64 int nondefGDNo = 0; 65 boolean isVirtualScreen = false; 66 GraphicsDevice defgd = ge.getDefaultScreenDevice(); 67 for (int i = 0; i < gds.length; i++) 68 { 69 Rectangle r = gds[i].getDefaultConfiguration().getBounds(); 70 if ((r.x != 0) || (r.y != 0)) 71 { 72 isVirtualScreen = true; 73 } 74 if (gds[i] == defgd) 75 { 76 defGDNo = i; 77 } 78 else 79 { 80 nondefGDNo = i; 81 } 82 } 83 84 // doesn't test separate screens 85 if (!isVirtualScreen) 86 { 87 return; 88 } 89 90 GraphicsDevice defGD = gds[defGDNo]; 91 GraphicsDevice nondefGD = gds[nondefGDNo]; 92 93 final GraphicsConfiguration defGC = defGD.getDefaultConfiguration(); 94 final GraphicsConfiguration nondefGC = nondefGD.getDefaultConfiguration(); 95 96 final Frame f = new Frame(defGC); 97 f.setBounds(nondefGC.getBounds().x + 100, nondefGC.getBounds().y + 100, 100, 100); 98 f.addWindowListener(new WindowAdapter() 99 { 100 public void windowActivated(WindowEvent ev) 101 { 102 GraphicsConfiguration gcf = f.getGraphicsConfiguration(); 103 if (gcf != nondefGC) 104 { 105 throw new RuntimeException("Test FAILED: graphics config is not updated"); 106 } 107 f.dispose(); 108 } 109 }); 110 f.setVisible(true); 111 Util.waitForIdle(robot); 112 113 // paranoia - change def to nondef and vice versa 114 final Frame g = new Frame(nondefGC); 115 g.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100); 116 g.addWindowListener(new WindowAdapter() 117 { 118 public void windowActivated(WindowEvent ev) 119 { 120 GraphicsConfiguration gcg = g.getGraphicsConfiguration(); 121 if (gcg != defGC) 122 { 123 throw new RuntimeException("Test FAILED: graphics config is not updated"); 124 } 125 g.dispose(); 126 } 127 }); 128 g.setVisible(true); 129 Util.waitForIdle(robot); 130 131 // test fullscreen changes 132 final Frame h = new Frame(defGC); 133 h.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100); 134 h.addWindowListener(new WindowAdapter() 135 { 136 public void windowActivated(WindowEvent ev) 137 { 138 GraphicsConfiguration gch = h.getGraphicsConfiguration(); 139 if (gch != nondefGC) 140 { 141 throw new RuntimeException("Test FAILED: graphics config is not updated"); 142 } 143 h.dispose(); 144 } 145 }); 146 h.setUndecorated(true); 147 nondefGD.setFullScreenWindow(h); 148 Util.waitForIdle(robot); 149 } 150 }