Path: blob/master/test/jdk/javax/swing/JLightweightFrame/ResizedMovedEvents.java
41149 views
/*1* Copyright (c) 2020, 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* @key headful26* @bug 823695327* @summary JavaFX SwingNode is not rendered on macOS28* @modules java.desktop/sun.swing29*/3031import java.awt.EventQueue;32import java.awt.event.ComponentAdapter;33import java.awt.event.ComponentEvent;34import java.util.concurrent.atomic.AtomicInteger;3536import javax.swing.JComponent;37import javax.swing.JPanel;3839import sun.swing.JLightweightFrame;40import sun.swing.LightweightContent;4142public final class ResizedMovedEvents {4344private static final AtomicInteger resized = new AtomicInteger();45private static final AtomicInteger moved = new AtomicInteger();46private static JLightweightFrame jLightweightFrame;4748public static void main(String[] args) throws Exception {49emulateSwingNode(true); // emulate visible node50emulateSwingNode(false); // emulate invisible node51}5253private static void emulateSwingNode(boolean visible) throws Exception {54try {55EventQueue.invokeAndWait(() -> {56jLightweightFrame = new JLightweightFrame();57jLightweightFrame.setContent(new XLightweightContent());58jLightweightFrame.addComponentListener(new ComponentAdapter() {59@Override60public void componentResized(ComponentEvent e) {61resized.incrementAndGet();62}6364@Override65public void componentMoved(ComponentEvent e) {66moved.incrementAndGet();67}68});69jLightweightFrame.setVisible(visible);70});7172// Some dummy initial location73setBounds(10, 10, 10, 10);7475// resize and move76resetFlags();77setBounds(100, 100, 100, 100);78checkFlags(1, 1);7980// resize only81resetFlags();82setBounds(100, 100, 200, 200);83checkFlags(1, 0);8485// move only86resetFlags();87setBounds(200, 200, 200, 200);88checkFlags(0, 1);89} finally {90if (jLightweightFrame != null) jLightweightFrame.dispose();91}92}9394private static void setBounds(int x, int y, int w, int h) throws Exception {95EventQueue.invokeAndWait(() -> {96jLightweightFrame.setBounds(x, y, w, h);97});98EventQueue.invokeAndWait(() -> {99// dummy event to flush the EventQueue100});101}102103private static void resetFlags() {104resized.set(0);105moved.set(0);106}107108private static void checkFlags(int expectedR, int expectedM) {109int actualR = resized.get();110int actualM = moved.get();111//112if (actualR < expectedR) {113System.err.println("Expected: " + expectedR);114System.err.println("Actual: " + actualR);115throw new RuntimeException("Wrong number of COMPONENT_RESIZED");116}117if (actualM < expectedM) {118System.err.println("Expected: " + expectedM);119System.err.println("Actual: " + actualM);120throw new RuntimeException("Wrong number of COMPONENT_MOVED");121}122}123124static final class XLightweightContent implements LightweightContent {125@Override126public JComponent getComponent() {127return new JPanel();128}129130@Override131public void paintLock() {132}133134@Override135public void paintUnlock() {136}137138@Override139public void imageBufferReset(int[] data, int x, int y, int width,140int height, int linestride,141double scaleX,142double scaleY) {143}144145@Override146public void imageReshaped(int x, int y, int width, int height) {147}148149@Override150public void imageUpdated(int dirtyX, int dirtyY, int dirtyWidth,151int dirtyHeight) {152}153154@Override155public void focusGrabbed() {156}157158@Override159public void focusUngrabbed() {160}161162@Override163public void preferredSizeChanged(int width, int height) {164}165166@Override167public void maximumSizeChanged(int width, int height) {168}169170@Override171public void minimumSizeChanged(int width, int height) {172}173}174}175176177