Path: blob/master/test/jdk/javax/swing/JInternalFrame/DockIconRepaint/DockIconRepaint.java
41152 views
/*1* Copyright (c) 2016, 2017, 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.Color;24import java.awt.EventQueue;25import java.awt.Graphics;26import java.awt.Point;27import java.awt.Rectangle;28import java.awt.Robot;29import java.beans.PropertyVetoException;3031import javax.swing.JDesktopPane;32import javax.swing.JFrame;33import javax.swing.JInternalFrame;34import javax.swing.JPanel;3536/**37* @test38* @key headful39* @bug 814416640* @requires (os.family == "mac")41*/4243public final class DockIconRepaint {4445private static volatile Color color;4647private static JFrame frame;4849private static JInternalFrame jif;5051private static Robot robot;5253private static Point iconLoc;5455private static Rectangle iconBounds;5657public static void main(final String[] args) throws Exception {58robot = new Robot();59EventQueue.invokeAndWait(DockIconRepaint::createUI);60try {61robot.waitForIdle();62color = Color.BLUE;63test();64color = Color.RED;65test();66color = Color.GREEN;67test();68} finally {69frame.dispose();70}71}7273private static void test() throws Exception {74// maximize the frame to force repaint75EventQueue.invokeAndWait(() -> {76try {77jif.setIcon(false);78jif.setMaximum(true);79} catch (PropertyVetoException e) {80throw new RuntimeException(e);81}82});83robot.waitForIdle();84Thread.sleep(1000);85// minimize the frame to dock, the icon should be up2date86EventQueue.invokeAndWait(() -> {87try {88jif.setIcon(true);89} catch (PropertyVetoException e) {90throw new RuntimeException(e);91}92iconLoc = jif.getDesktopIcon().getLocationOnScreen();93iconBounds = jif.getDesktopIcon().getBounds();94});95robot.waitForIdle();96Thread.sleep(1000);9798final Color c = robot.getPixelColor(iconLoc.x + iconBounds.width / 2,99iconLoc.y + iconBounds.height / 2);100if (c.getRGB() != color.getRGB()) {101System.err.println("Exp: " + Integer.toHexString(color.getRGB()));102System.err.println("Actual: " + Integer.toHexString(c.getRGB()));103throw new RuntimeException("Wrong color.");104}105}106107private static void createUI() {108frame = new JFrame();109frame.setUndecorated(true);110frame.setSize(300, 300);111frame.setLocationRelativeTo(null);112final JDesktopPane pane = new JDesktopPane();113final JPanel panel = new JPanel() {114@Override115protected void paintComponent(Graphics g) {116g.setColor(color);117g.fillRect(0, 0, getWidth(), getHeight());118}119};120jif = new JInternalFrame();121jif.add(panel);122jif.setVisible(true);123jif.setSize(300, 300);124pane.add(jif);125frame.add(pane);126frame.setVisible(true);127}128}129130131