Path: blob/master/test/jdk/javax/swing/GraphicsConfigNotifier/OrderOfGConfigNotify.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.util.concurrent.atomic.AtomicBoolean;2526import javax.swing.JFrame;27import javax.swing.JPanel;2829/**30* @test31* @key headful32* @bug 820155233* @summary Container should get "graphicsConfiguration" notification when all34* its children are updated35*/36public final class OrderOfGConfigNotify {3738private static String name = "graphicsConfiguration";3940public static void main(final String[] args) throws Exception {41EventQueue.invokeAndWait(() -> {42AtomicBoolean parentCalled = new AtomicBoolean(false);43AtomicBoolean childCalled = new AtomicBoolean(false);4445JFrame frame = new JFrame();4647JPanel parent = new JPanel();48parent.addPropertyChangeListener(evt -> {49if (!evt.getPropertyName().equals(name)) {50return;51}52if (!childCalled.get()) {53throw new RuntimeException("Parent is called/child is not");54}55parentCalled.set(true);56if (parent.getGraphicsConfiguration() == null) {57throw new RuntimeException("GraphicsConfiguration is null");58}59});60JPanel child = new JPanel();61child.addPropertyChangeListener(evt -> {62if (!evt.getPropertyName().equals(name)) {63return;64}65childCalled.set(true);66if (child.getGraphicsConfiguration() == null) {67throw new RuntimeException("GraphicsConfiguration is null");68}69});70parent.add(child);7172// Frame.add() should update graphicsConfiguration for all hierarchy73frame.add(parent);74if (!parentCalled.get() || !childCalled.get()) {75throw new RuntimeException("Property listener was not called");76}77});78}79}808182