/* * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test @bug 8150176 @author a.stepanov @summary Check if correct resolution variant is used for JOptionPane dialog icons. @library ../../../../lib/testlibrary/ @build ExtendedRobot @run main/manual/othervm -Dsun.java2d.uiScale=2 MultiResolutionJOptionPaneIconTest */ import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.*; import javax.swing.*; public class MultiResolutionJOptionPaneIconTest extends JFrame { private static BufferedImage generateImage(int sz, Color c) { BufferedImage img = new BufferedImage(sz, sz, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); g.setColor(c); g.fillRect(0, 0, sz, sz); g.setColor(Color.WHITE); g.fillRect(sz / 3, sz / 3, sz / 3, sz / 3); return img; } private final JDesktopPane parentPane; public MultiResolutionJOptionPaneIconTest() throws Exception { parentPane = new JDesktopPane(); SwingUtilities.invokeAndWait(this::UI); } private void UI() { getContentPane().add(parentPane); setSize(400, 250); setLocation(50, 50); setUndecorated(true); } private void doTest() throws Exception { int sz = 16; BufferedImage img1x = generateImage(sz, Color.RED); BufferedImage img2x = generateImage(2 * sz, Color.GREEN); BaseMultiResolutionImage mri = new BaseMultiResolutionImage( new BufferedImage[]{img1x, img2x}); Icon icon = new ImageIcon(mri); String msg = "..."; int opt = JOptionPane.DEFAULT_OPTION; int info = JOptionPane.INFORMATION_MESSAGE; Object v[] = {"one", "two"}; String instructions[] = {"please check if all the icons", "for the further dialogs", "has green borders"}; ExtendedRobot r = new ExtendedRobot(); r.waitForIdle(); // show instructions SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog(null, instructions, "TEST INSTRUCTIONS", JOptionPane.WARNING_MESSAGE); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JOptionPane.showConfirmDialog(null, msg, "confirm", opt, info, icon); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JOptionPane.showInputDialog(null, msg, "input", info, icon, v, v[0]); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JOptionPane.showMessageDialog(null, msg, "message", info, icon); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JOptionPane.showOptionDialog( null, msg, "option", opt, info, icon, v, v[0]); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { setVisible(true); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JOptionPane.showInternalConfirmDialog( parentPane, msg, "internalConfirm", opt, info, icon); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JOptionPane.showInternalInputDialog( parentPane, msg, "internalInput", info, icon, v, v[0]); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JOptionPane.showInternalMessageDialog( parentPane, msg, "internalMessage", info, icon); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { JOptionPane.showInternalOptionDialog( parentPane, msg, "internalOption", opt, info, icon, v, v[0]); }); r.waitForIdle(); SwingUtilities.invokeAndWait(() -> { setVisible(false); }); r.waitForIdle(); // pass / fail SwingUtilities.invokeAndWait(() -> { if (JOptionPane.showConfirmDialog(null, "were all the icons green-and-white?", "PASS / FAIL", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { throw new RuntimeException("test failed"); } }); dispose(); } private static boolean is2x() { AffineTransform tr = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(). getDefaultTransform(); return (Math.min(tr.getScaleX(), tr.getScaleY()) > 1.001); } public static void main(String[] args) throws Exception { // TODO: remove is2x() check after JDK-8150844 fix if (!is2x()) { return; } (new MultiResolutionJOptionPaneIconTest()).doTest(); } }