jdk/test/java/awt/Cursor/MultiResolutionCursorTest/MultiResolutionCursorTest.java
author alexsch
Thu, 09 Jan 2014 18:41:00 +0400
changeset 23257 5aff11b9c9aa
child 26750 d0d6c64a2e2b
permissions -rw-r--r--
8028212: Custom cursor HiDPI support Reviewed-by: serb, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23257
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     1
/*
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     4
 *
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     8
 *
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    13
 * accompanied this code).
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    14
 *
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    18
 *
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    21
 * questions.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    22
 */
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    23
import java.awt.BorderLayout;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    24
import java.awt.Color;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    25
import java.awt.Cursor;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    26
import java.awt.Dialog;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    27
import java.awt.Frame;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    28
import java.awt.Graphics;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    29
import java.awt.Graphics2D;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    30
import java.awt.Image;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    31
import java.awt.Label;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    32
import java.awt.Point;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    33
import java.awt.TextArea;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    34
import java.awt.Toolkit;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    35
import java.awt.image.BufferedImage;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    36
import java.util.LinkedList;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    37
import java.util.List;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    38
import javax.swing.JApplet;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    39
import sun.awt.OSInfo;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    40
import sun.awt.image.MultiResolutionImage;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    41
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    42
/**
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    43
 * @test
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    44
 * @bug 8028212
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    45
 * @summary [macosx] Custom Cursor HiDPI support
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    46
 * @author Alexander Scherbatiy
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    47
 * @run applet/manual=yesno MultiResolutionCursorTest.html
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    48
 */
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    49
public class MultiResolutionCursorTest extends JApplet {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    50
    //Declare things used in the test, like buttons and labels here
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    51
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    52
    static final int sizes[] = {16, 32, 128};
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    53
    static final Color colors[] = {Color.WHITE, Color.RED, Color.GREEN, Color.BLUE};
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    54
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    55
    public void init() {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    56
        //Create instructions for the user here, as well as set up
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    57
        // the environment -- set the layout manager, add buttons,
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    58
        // etc.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    59
        this.setLayout(new BorderLayout());
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    60
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    61
        if (OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    62
            String[] instructions = {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    63
                "Verify that high resolution custom cursor is used"
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    64
                + " on HiDPI displays.",
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    65
                "1) Run the test on Retina display or enable the Quartz Debug"
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    66
                + " and select the screen resolution with (HiDPI) label",
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    67
                "2) Move the cursor to the Test Frame",
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    68
                "3) Check that cursor has red, green or blue color",
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    69
                "If so, press PASS, else press FAIL."
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    70
            };
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    71
            Sysout.createDialogWithInstructions(instructions);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    72
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    73
        } else {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    74
            String[] instructions = {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    75
                "This test is not applicable to the current platform. Press PASS."
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    76
            };
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    77
            Sysout.createDialogWithInstructions(instructions);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    78
        }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    79
    }//End  init()
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    80
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    81
    public void start() {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    82
        //Get things going.  Request focus, set size, et cetera
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    83
        setSize(200, 200);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    84
        setVisible(true);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    85
        validate();
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    86
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    87
        final Image image = new MultiResolutionCursor();
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    88
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    89
        int center = sizes[0] / 2;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    90
        Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    91
                image, new Point(center, center), "multi-resolution cursor");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    92
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    93
        Frame frame = new Frame("Test Frame");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    94
        frame.setSize(300, 300);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    95
        frame.setLocation(300, 50);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    96
        frame.add(new Label("Move cursor here"));
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    97
        frame.setCursor(cursor);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    98
        frame.setVisible(true);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
    99
    }// start()
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   100
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   101
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   102
    static class MultiResolutionCursor extends BufferedImage implements MultiResolutionImage {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   103
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   104
        List<Image> highResolutionImages;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   105
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   106
        public MultiResolutionCursor() {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   107
            super(sizes[0], sizes[0], BufferedImage.TYPE_INT_RGB);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   108
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   109
            draw(getGraphics(), 0);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   110
            highResolutionImages = new LinkedList<>();
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   111
            highResolutionImages.add(this);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   112
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   113
            for (int i = 1; i < sizes.length; i++) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   114
                BufferedImage highResolutionImage =
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   115
                        new BufferedImage(sizes[i], sizes[i], BufferedImage.TYPE_INT_RGB);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   116
                draw(highResolutionImage.getGraphics(), i);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   117
                highResolutionImages.add(highResolutionImage);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   118
            }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   119
        }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   120
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   121
        @Override
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   122
        public Image getResolutionVariant(int width, int height) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   123
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   124
            for (int i = 0; i < sizes.length; i++) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   125
                Image image = highResolutionImages.get(i);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   126
                int w = image.getWidth(null);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   127
                int h = image.getHeight(null);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   128
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   129
                if (width <= w && height <= h) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   130
                    return image;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   131
                }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   132
            }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   133
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   134
            return highResolutionImages.get(highResolutionImages.size() - 1);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   135
        }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   136
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   137
        void draw(Graphics graphics, int index) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   138
            Graphics2D g2 = (Graphics2D) graphics;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   139
            Color color = colors[index];
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   140
            g2.setColor(color);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   141
            g2.fillRect(0, 0, sizes[index], sizes[index]);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   142
        }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   143
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   144
        @Override
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   145
        public List<Image> getResolutionVariants() {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   146
            return highResolutionImages;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   147
        }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   148
    }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   149
}// class BlockedWindowTest
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   150
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   151
/* Place other classes related to the test after this line */
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   152
/**
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   153
 * **************************************************
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   154
 * Standard Test Machinery DO NOT modify anything below -- it's a standard chunk
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   155
 * of code whose purpose is to make user interaction uniform, and thereby make
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   156
 * it simpler to read and understand someone else's test.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   157
 * **************************************************
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   158
 */
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   159
/**
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   160
 * This is part of the standard test machinery. It creates a dialog (with the
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   161
 * instructions), and is the interface for sending text messages to the user. To
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   162
 * print the instructions, send an array of strings to Sysout.createDialog
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   163
 * WithInstructions method. Put one line of instructions per array entry. To
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   164
 * display a message for the tester to see, simply call Sysout.println with the
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   165
 * string to be displayed. This mimics System.out.println but works within the
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   166
 * test harness as well as standalone.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   167
 */
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   168
class Sysout {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   169
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   170
    private static TestDialog dialog;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   171
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   172
    public static void createDialogWithInstructions(String[] instructions) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   173
        dialog = new TestDialog(new Frame(), "Instructions");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   174
        dialog.printInstructions(instructions);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   175
        dialog.setVisible(true);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   176
        println("Any messages for the tester will display here.");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   177
    }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   178
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   179
    public static void createDialog() {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   180
        dialog = new TestDialog(new Frame(), "Instructions");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   181
        String[] defInstr = {"Instructions will appear here. ", ""};
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   182
        dialog.printInstructions(defInstr);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   183
        dialog.setVisible(true);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   184
        println("Any messages for the tester will display here.");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   185
    }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   186
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   187
    public static void printInstructions(String[] instructions) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   188
        dialog.printInstructions(instructions);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   189
    }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   190
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   191
    public static void println(String messageIn) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   192
        dialog.displayMessage(messageIn);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   193
    }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   194
}// Sysout  class
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   195
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   196
/**
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   197
 * This is part of the standard test machinery. It provides a place for the test
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   198
 * instructions to be displayed, and a place for interactive messages to the
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   199
 * user to be displayed. To have the test instructions displayed, see Sysout. To
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   200
 * have a message to the user be displayed, see Sysout. Do not call anything in
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   201
 * this dialog directly.
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   202
 */
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   203
class TestDialog extends Dialog {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   204
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   205
    TextArea instructionsText;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   206
    TextArea messageText;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   207
    int maxStringLength = 80;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   208
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   209
    //DO NOT call this directly, go through Sysout
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   210
    public TestDialog(Frame frame, String name) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   211
        super(frame, name);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   212
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   213
        instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   214
        add("North", instructionsText);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   215
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   216
        messageText = new TextArea("", 5, maxStringLength, scrollBoth);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   217
        add("Center", messageText);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   218
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   219
        pack();
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   220
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   221
        setVisible(true);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   222
    }// TestDialog()
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   223
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   224
    //DO NOT call this directly, go through Sysout
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   225
    public void printInstructions(String[] instructions) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   226
        //Clear out any current instructions
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   227
        instructionsText.setText("");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   228
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   229
        //Go down array of instruction strings
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   230
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   231
        String printStr, remainingStr;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   232
        for (int i = 0; i < instructions.length; i++) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   233
            //chop up each into pieces maxSringLength long
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   234
            remainingStr = instructions[ i];
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   235
            while (remainingStr.length() > 0) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   236
                //if longer than max then chop off first max chars to print
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   237
                if (remainingStr.length() >= maxStringLength) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   238
                    //Try to chop on a word boundary
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   239
                    int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   240
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   241
                    if (posOfSpace <= 0) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   242
                        posOfSpace = maxStringLength - 1;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   243
                    }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   244
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   245
                    printStr = remainingStr.substring(0, posOfSpace + 1);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   246
                    remainingStr = remainingStr.substring(posOfSpace + 1);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   247
                } //else just print
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   248
                else {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   249
                    printStr = remainingStr;
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   250
                    remainingStr = "";
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   251
                }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   252
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   253
                instructionsText.append(printStr + "\n");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   254
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   255
            }// while
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   256
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   257
        }// for
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   258
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   259
    }//printInstructions()
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   260
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   261
    //DO NOT call this directly, go through Sysout
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   262
    public void displayMessage(String messageIn) {
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   263
        messageText.append(messageIn + "\n");
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   264
        System.out.println(messageIn);
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   265
    }
5aff11b9c9aa 8028212: Custom cursor HiDPI support
alexsch
parents:
diff changeset
   266
}// Te