Path: blob/master/test/jdk/javax/swing/GraphicsConfigNotifier/TestSingleScreenGConfigNotify.java
41149 views
/*1* Copyright (c) 2018, 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*/2223import java.awt.EventQueue;24import java.awt.GraphicsConfiguration;25import java.util.Objects;26import java.util.concurrent.CountDownLatch;27import java.util.concurrent.TimeUnit;2829import javax.swing.JButton;30import javax.swing.JFrame;3132/**33* @test34* @key headful35* @bug 820155236* @summary Verifies if graphicsConfiguration property notification is sent37* when frame is shown on the screen.38* @run main TestSingleScreenGConfigNotify39* @run main/othervm -Dsun.java2d.uiScale=2.25 TestSingleScreenGConfigNotify40*/41public final class TestSingleScreenGConfigNotify {4243private static String name = "graphicsConfiguration";44private static CountDownLatch go = new CountDownLatch(1);45private static JFrame frame;46private static GraphicsConfiguration after;47private static GraphicsConfiguration before;48private static JButton button;4950public static void main(final String[] args) throws Exception {51EventQueue.invokeAndWait(() -> {52frame = new JFrame();5354frame.setSize(300,300);55frame.setLocationRelativeTo(null);56button = new JButton();57button.addPropertyChangeListener(evt -> {58if (evt.getPropertyName().equals(name)) {59go.countDown();60}61});6263before = button.getGraphicsConfiguration();6465frame.add(button);66frame.setVisible(true);67});6869boolean called = go.await(10, TimeUnit.SECONDS);7071EventQueue.invokeAndWait(() -> {72after = button.getGraphicsConfiguration();73frame.dispose();74});7576if (Objects.equals(before, after) && called) {77throw new RuntimeException("propertyChange() should not be called");78}79if (!Objects.equals(before, after) && !called) {80throw new RuntimeException("propertyChange() should be called");81}82}83}848586