|
| 1 | +/* |
| 2 | + * Copyright (c) 2013, 2024, 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.Color; |
| 25 | +import java.awt.Cursor; |
| 26 | +import java.awt.Graphics2D; |
| 27 | +import java.awt.Image; |
| 28 | +import java.awt.Label; |
| 29 | +import java.awt.Point; |
| 30 | +import java.awt.Toolkit; |
| 31 | +import java.awt.image.BaseMultiResolutionImage; |
| 32 | +import java.awt.image.BufferedImage; |
| 33 | +import java.lang.reflect.InvocationTargetException; |
| 34 | +import javax.swing.JFrame; |
| 35 | + |
| 36 | +/* |
| 37 | + * @test |
| 38 | + * @bug 8028212 |
| 39 | + * @summary [macosx] Custom Cursor HiDPI support |
| 40 | + * @requires (os.family == "mac") |
| 41 | + * @library /java/awt/regtesthelpers |
| 42 | + * @build PassFailJFrame |
| 43 | + * @run main/manual MultiResolutionCursorTest |
| 44 | + */ |
| 45 | +public class MultiResolutionCursorTest { |
| 46 | + static final int sizes[] = {8, 16, 32, 128}; |
| 47 | + |
| 48 | + private static JFrame initialize() { |
| 49 | + final Image image = new BaseMultiResolutionImage( |
| 50 | + createResolutionVariant(0), |
| 51 | + createResolutionVariant(1), |
| 52 | + createResolutionVariant(2), |
| 53 | + createResolutionVariant(3) |
| 54 | + ); |
| 55 | + |
| 56 | + int center = sizes[0] / 2; |
| 57 | + Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor( |
| 58 | + image, new Point(center, center), "multi-resolution cursor"); |
| 59 | + |
| 60 | + JFrame frame = new JFrame("Multi-resolution Cursor Test Frame"); |
| 61 | + frame.setSize(300, 300); |
| 62 | + frame.add(new Label("Move cursor here")); |
| 63 | + frame.setCursor(cursor); |
| 64 | + return frame; |
| 65 | + } |
| 66 | + |
| 67 | + private static BufferedImage createResolutionVariant(int i) { |
| 68 | + BufferedImage resolutionVariant = new BufferedImage(sizes[i], sizes[i], |
| 69 | + BufferedImage.TYPE_INT_RGB); |
| 70 | + Graphics2D g2 = resolutionVariant.createGraphics(); |
| 71 | + Color colors[] = {Color.WHITE, Color.RED, Color.GREEN, Color.BLUE}; |
| 72 | + g2.setColor(colors[i]); |
| 73 | + g2.fillRect(0, 0, sizes[i], sizes[i]); |
| 74 | + g2.dispose(); |
| 75 | + return resolutionVariant; |
| 76 | + } |
| 77 | + |
| 78 | + public static void main(String[] args) throws InterruptedException, |
| 79 | + InvocationTargetException { |
| 80 | + String instructions = """ |
| 81 | + Verify that high resolution custom cursor is used |
| 82 | + on HiDPI displays. |
| 83 | + 1) Run the test on Retina display or enable the Quartz Debug |
| 84 | + and select the screen resolution with (HiDPI) label |
| 85 | + 2) Move the cursor to the Test Frame |
| 86 | + 3) Check that cursor has red, green or blue color |
| 87 | + If so, press Pass, else press Fail. |
| 88 | + """; |
| 89 | + |
| 90 | + PassFailJFrame.builder() |
| 91 | + .title("Multi-resolution Cursor Test Instructions") |
| 92 | + .instructions(instructions) |
| 93 | + .rows((int) instructions.lines().count() + 1) |
| 94 | + .columns(40) |
| 95 | + .testUI(MultiResolutionCursorTest::initialize) |
| 96 | + .build() |
| 97 | + .awaitAndCheck(); |
| 98 | + } |
| 99 | +} |
0 commit comments