Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/RepaintManager/IconifyTest/IconifyTest.java
38853 views
/*1* Copyright (c) 2012, 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*/22/*23* @test24* @bug 466521425* @summary Makes sure that RepaintManager doesn't attempt to repaint26* a frame when it is iconified.27* @author Scott Violet28* @run main IconifyTest29*/30import java.awt.*;31import java.awt.event.*;32import javax.swing.*;3334public class IconifyTest {35private static volatile boolean windowIconifiedIsCalled = false;36private static volatile boolean frameIsRepainted = false;37static JFrame frame;38static JButton button;3940public static void main(String[] args) throws Throwable {41Robot robot = new Robot();42SwingUtilities.invokeAndWait(new Runnable() {43public void run() {44frame = new JFrame();45button = new JButton("HI");46frame.getContentPane().add(button);47frame.addWindowListener(new WindowAdapter() {48public void windowIconified(WindowEvent e) {49windowIconifiedIsCalled = true;50RepaintManager rm = RepaintManager.currentManager(null);51rm.paintDirtyRegions();52button.repaint();53if (!rm.getDirtyRegion(button).isEmpty()) {54frameIsRepainted = true;55}56}57});58frame.pack();59frame.setVisible(true);60}61});62robot.waitForIdle();6364SwingUtilities.invokeAndWait(new Runnable() {65public void run() {66frame.setExtendedState(Frame.ICONIFIED);67}68});69robot.waitForIdle();7071if (!windowIconifiedIsCalled) {72throw new Exception("Test failed: window was not iconified.");73}74if (frameIsRepainted) {75throw new Exception("Test failed: frame was repainted when window was iconified.");76}77}78}798081