1 /* 2 * Copyright (c) 2017, 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 * @bug 8178025 27 * @summary Verifies if graphicsConfiguration property notification is sent 28 * when frame is moved from one screen to another in multiscreen 29 * environment. 30 * @key headful 31 * @run main TestMultiScreenGConfigNotify 32 */ 33 34 import java.awt.GraphicsConfiguration; 35 import java.awt.GraphicsDevice; 36 import java.awt.GraphicsEnvironment; 37 import java.beans.PropertyChangeEvent; 38 import java.beans.PropertyChangeListener; 39 import java.util.logging.Level; 40 import java.util.logging.Logger; 41 import javax.swing.JFrame; 42 import javax.swing.SwingUtilities; 43 44 public class TestMultiScreenGConfigNotify { 45 46 static JFrame f; 47 static String propName[]; 48 static int propCount = 0; 49 static boolean result = false; main(String[] args)50 public static void main(String[] args) throws Exception { 51 52 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 53 GraphicsDevice[] gds = ge.getScreenDevices(); 54 if (gds.length < 2) { 55 return; 56 } 57 GraphicsConfiguration gc = gds[0].getDefaultConfiguration(); 58 GraphicsConfiguration gc2 = gds[1].getDefaultConfiguration(); 59 propName = new String[10]; 60 SwingUtilities.invokeAndWait(() -> { 61 f = new JFrame(); 62 f.setSize(300, 300); 63 f.setBounds(gc.getBounds().x, gc.getBounds().y, f.getWidth(), f.getHeight()); 64 f.setVisible(true); 65 66 f.addPropertyChangeListener((PropertyChangeEvent evt) -> { 67 String name = evt.getPropertyName(); 68 System.out.println("propertyChange " + name); 69 propName[propCount] = name; 70 propCount++; 71 }); 72 try { 73 Thread.sleep(2000); 74 } catch (InterruptedException ex) { 75 } 76 f.setBounds(gc2.getBounds().x, gc2.getBounds().y, 77 f.getWidth(), f.getHeight()); 78 }); 79 80 Thread.sleep(1000); 81 for(int i = 0; i < propCount; i++) { 82 if (propName[i].equals("graphicsConfiguration")) { 83 result = true; 84 } 85 } 86 SwingUtilities.invokeAndWait(() -> f.dispose()); 87 if(!result) { 88 throw new RuntimeException("graphicsConfiguration notification not sent"); 89 } 90 } 91 } 92