1 /*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.awt.BorderLayout;
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.Graphics;
28 import java.awt.Point;
29 import java.awt.Robot;
30 import java.awt.event.InputEvent;
31 import java.awt.image.BaseMultiResolutionImage;
32 import java.awt.image.BufferedImage;
33 import javax.swing.Icon;
34 import javax.swing.ImageIcon;
35 import javax.swing.JFrame;
36 import javax.swing.JPanel;
37 import javax.swing.JToggleButton;
38 import javax.swing.SwingUtilities;
39
40 /**
41 * @test
42 * @bug 8151303
43 * @summary [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
44 * @run main/othervm PressedIconTest
45 * @run main/othervm -Dsun.java2d.uiScale=2 PressedIconTest
46 */
47 public class PressedIconTest {
48
49 private final static int IMAGE_SIZE = 300;
50
51 private final static Color COLOR_1X = Color.RED;
52 private final static Color COLOR_2X = Color.BLUE;
53 private static JFrame frame;
54 private static volatile double scale = -1;
55 private static volatile int centerX;
56 private static volatile int centerY;
57
58 public static void main(String[] args) throws Exception {
59 Robot robot = new Robot();
60 robot.setAutoDelay(50);
61
62 SwingUtilities.invokeAndWait(() -> createAndShowGUI());
63 robot.waitForIdle();
64
65 SwingUtilities.invokeAndWait(() -> {
66 scale = frame.getGraphicsConfiguration().getDefaultTransform()
|
1 /*
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.awt.BorderLayout;
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.Graphics;
28 import java.awt.Point;
29 import java.awt.Robot;
30 import java.awt.event.InputEvent;
31 import java.awt.image.BaseMultiResolutionImage;
32 import java.awt.image.BufferedImage;
33 import javax.swing.Icon;
34 import javax.swing.ImageIcon;
35 import javax.swing.JFrame;
36 import javax.swing.JPanel;
37 import javax.swing.JToggleButton;
38 import javax.swing.SwingUtilities;
39
40 /**
41 * @test
42 * @key headful
43 * @bug 8151303
44 * @summary [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
45 * @run main/othervm PressedIconTest
46 * @run main/othervm -Dsun.java2d.uiScale=2 PressedIconTest
47 */
48
49 public class PressedIconTest {
50
51 private final static int IMAGE_SIZE = 300;
52
53 private final static Color COLOR_1X = Color.RED;
54 private final static Color COLOR_2X = Color.BLUE;
55 private static JFrame frame;
56 private static volatile double scale = -1;
57 private static volatile int centerX;
58 private static volatile int centerY;
59
60 public static void main(String[] args) throws Exception {
61 Robot robot = new Robot();
62 robot.setAutoDelay(50);
63
64 SwingUtilities.invokeAndWait(() -> createAndShowGUI());
65 robot.waitForIdle();
66
67 SwingUtilities.invokeAndWait(() -> {
68 scale = frame.getGraphicsConfiguration().getDefaultTransform()
|