Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java
38853 views
/*1* Copyright (c) 2013, 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.Rectangle;24import java.awt.Toolkit;25import java.awt.image.BufferedImage;2627import javax.swing.JFrame;28import javax.swing.SwingUtilities;29import jdk.testlibrary.OSInfo;3031/**32* @test33* @bug 712451334* @summary We should support NSTexturedBackgroundWindowMask style on OSX.35* @author Sergey Bylokhov36* @library ../../../../lib/testlibrary37* @build ExtendedRobot jdk.testlibrary.OSInfo38* @run main NSTexturedJFrame39*/40public final class NSTexturedJFrame {4142private static final String BRUSH = "apple.awt.brushMetalLook";43private static final String STYLE = "Window.style";44private static final BufferedImage[] images = new BufferedImage[3];45private static Rectangle bounds;46private static volatile int step;47private static JFrame frame;48private static ExtendedRobot robot;4950public static void main(final String[] args) throws Exception {51if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {52System.out.println("This test is for OSX, considered passed.");53return;54}55robot = new ExtendedRobot();56robot.setAutoDelay(50);57// Default window appearance58showFrame();59step++;60// apple.awt.brushMetalLook appearance61showFrame();62step++;63// Window.style appearance64showFrame();6566// images on step 1 and 2 should be same67testImages(images[1], images[2], false);68// images on step 1 and 2 should be different from default69testImages(images[0], images[1], true);70testImages(images[0], images[2], true);71}7273private static void testImages(BufferedImage img1, BufferedImage img2,74boolean shouldbeDifferent) {75boolean different = false;76for (int x = 0; x < img1.getWidth(); ++x) {77for (int y = 0; y < img1.getHeight(); ++y) {78if (img1.getRGB(x, y) != img2.getRGB(x, y)) {79different = true;80}81}82}83if (different != shouldbeDifferent) {84throw new RuntimeException("Textured property does not work");85}86}8788private static void showFrame() throws Exception {89createUI();90images[step] = robot.createScreenCapture(bounds);91SwingUtilities.invokeAndWait(frame::dispose);92robot.waitForIdle(1000);93}9495private static void createUI() throws Exception {96SwingUtilities.invokeAndWait(() -> {97frame = new JFrame();98frame.setUndecorated(true);99frame.setSize(400, 400);100frame.setLocationRelativeTo(null);101switch (step) {102case 1:103frame.getRootPane().putClientProperty(BRUSH, true);104break;105case 2:106frame.getRootPane().putClientProperty(STYLE, "textured");107}108frame.setVisible(true);109});110robot.waitForIdle(1000);111SwingUtilities.invokeAndWait(() -> {112bounds = frame.getBounds();113});114robot.waitForIdle(1000);115}116117}118119120