--- /dev/null 2017-11-09 13:24:28.000000000 +0530 +++ new/test/jdk/javax/swing/GraphicsConfigNotifier/TestMultiScreenGConfigNotify.java 2017-11-09 13:24:27.189461400 +0530 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/* + * @test + * @bug 8178025 + * @summary Verifies if graphicsConfiguration property notification is sent + * when frame is moved from one screen to another in multiscreen + * environment. + * @run main TestMultiScreenGConfigNotify + */ + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +public class TestMultiScreenGConfigNotify { + static Point p; + static JFrame f; + static String propName[]; + static int propCount = 0; + static boolean result = false; + public static void main(String[] args) throws Exception { + + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gds = ge.getScreenDevices(); + if (gds.length < 2) { + return; + } + GraphicsConfiguration gc = gds[0].getDefaultConfiguration(); + propName = new String[10]; + SwingUtilities.invokeAndWait(() -> { + f = new JFrame(); + f.setSize(300, 300); + f.setVisible(true); + p = f.getLocationOnScreen(); + f.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + String name = evt.getPropertyName(); + System.out.println("propertyChange " + name); + propName[propCount] = name; + propCount++; + } + }); + }); + Robot robot = new Robot(); + robot.waitForIdle(); + robot.delay(2000); + + robot.mouseMove(p.x+50, p.y+10); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + robot.mouseMove(gc.getBounds().width, gc.getBounds().height/2); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + + robot.delay(1000); + for(int i = 0; i < propCount; i++) { + if (propName[i].equals("graphicsConfiguration")) + result = true; + } + SwingUtilities.invokeAndWait(() -> f.dispose()); + if(!result) { + throw new RuntimeException("graphicsConfiguration notification not sent"); + } + } + +}