Path: blob/master/test/jdk/javax/swing/GraphicsConfigNotifier/TestMultiScreenGConfigNotify.java
41149 views
/*1* Copyright (c) 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*/2223/**24* @test25* @bug 817802526* @summary Verifies if graphicsConfiguration property notification is sent27* when frame is moved from one screen to another in multiscreen28* environment.29* @key headful30* @run main TestMultiScreenGConfigNotify31*/3233import java.awt.GraphicsConfiguration;34import java.awt.GraphicsDevice;35import java.awt.GraphicsEnvironment;36import java.beans.PropertyChangeEvent;37import java.beans.PropertyChangeListener;38import java.util.logging.Level;39import java.util.logging.Logger;40import javax.swing.JFrame;41import javax.swing.SwingUtilities;4243public class TestMultiScreenGConfigNotify {4445static JFrame f;46static String propName[];47static int propCount = 0;48static boolean result = false;49public static void main(String[] args) throws Exception {5051GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();52GraphicsDevice[] gds = ge.getScreenDevices();53if (gds.length < 2) {54return;55}56GraphicsConfiguration gc = gds[0].getDefaultConfiguration();57GraphicsConfiguration gc2 = gds[1].getDefaultConfiguration();58propName = new String[10];59SwingUtilities.invokeAndWait(() -> {60f = new JFrame();61f.setSize(300, 300);62f.setBounds(gc.getBounds().x, gc.getBounds().y, f.getWidth(), f.getHeight());63f.setVisible(true);6465f.addPropertyChangeListener((PropertyChangeEvent evt) -> {66String name = evt.getPropertyName();67System.out.println("propertyChange " + name);68propName[propCount] = name;69propCount++;70});71try {72Thread.sleep(2000);73} catch (InterruptedException ex) {74}75f.setBounds(gc2.getBounds().x, gc2.getBounds().y,76f.getWidth(), f.getHeight());77});7879Thread.sleep(1000);80for(int i = 0; i < propCount; i++) {81if (propName[i].equals("graphicsConfiguration")) {82result = true;83}84}85SwingUtilities.invokeAndWait(() -> f.dispose());86if(!result) {87throw new RuntimeException("graphicsConfiguration notification not sent");88}89}90}919293