1 /*
   2  * Copyright (c) 2013, 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 import java.awt.BorderLayout;
  24 import java.awt.Dialog;
  25 import java.awt.EventQueue;
  26 import java.awt.Frame;
  27 import java.awt.TextArea;
  28 import javax.swing.JApplet;
  29 import javax.swing.JOptionPane;
  30 import jdk.testlibrary.OSInfo;
  31 
  32 /**
  33  * @test
  34  * @bug 8024926 8040279
  35  * @summary [macosx] AquaIcon HiDPI support
  36  * @author Alexander Scherbatiy
  37  * @library ../../../../lib/testlibrary
  38  * @build jdk.testlibrary.OSInfo
  39  * @run applet/manual=yesno bug8024926.html
  40  */
  41 public class bug8024926 extends JApplet {
  42     //Declare things used in the test, like buttons and labels here
  43 
  44     public void init() {
  45         //Create instructions for the user here, as well as set up
  46         // the environment -- set the layout manager, add buttons,
  47         // etc.
  48         this.setLayout(new BorderLayout());
  49 
  50 
  51         if (OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) {
  52             String[] instructions = {
  53                 "Verify that high resolution system icons are used"
  54                 + " in JOptionPane on HiDPI displays.",
  55                 "1) Run the test on Retina display or enable the Quartz Debug"
  56                 + " and select the screen resolution with (HiDPI) label",
  57                 "2) Check that the error icon on the JOptionPane is smooth",
  58                 "If so, press PASS, else press FAIL."
  59             };
  60             Sysout.createDialogWithInstructions(instructions);
  61 
  62         } else {
  63             String[] instructions = {
  64                 "This test is not applicable to the current platform. Press PASS."
  65             };
  66             Sysout.createDialogWithInstructions(instructions);
  67         }
  68 
  69 
  70     }//End  init()
  71 
  72     public void start() {
  73         //Get things going.  Request focus, set size, et cetera
  74         setSize(200, 200);
  75         setVisible(true);
  76         validate();
  77         EventQueue.invokeLater(new Runnable() {
  78 
  79             public void run() {
  80                 createAndShowGUI();
  81             }
  82         });
  83     }// start()
  84 
  85     //The rest of this class is the actions which perform the test...
  86     //Use Sysout.println to communicate with the user NOT System.out!!
  87     //Sysout.println ("Something Happened!");
  88     private static void createAndShowGUI() {
  89         JOptionPane.showMessageDialog(null,
  90                 "Icons should have high resolution.",
  91                 "High resolution icon test.",
  92                 JOptionPane.ERROR_MESSAGE);
  93     }
  94 }// class BlockedWindowTest
  95 
  96 /* Place other classes related to the test after this line */
  97 /**
  98  * **************************************************
  99  * Standard Test Machinery DO NOT modify anything below -- it's a standard chunk
 100  * of code whose purpose is to make user interaction uniform, and thereby make
 101  * it simpler to read and understand someone else's test.
 102  * **************************************************
 103  */
 104 /**
 105  * This is part of the standard test machinery. It creates a dialog (with the
 106  * instructions), and is the interface for sending text messages to the user. To
 107  * print the instructions, send an array of strings to Sysout.createDialog
 108  * WithInstructions method. Put one line of instructions per array entry. To
 109  * display a message for the tester to see, simply call Sysout.println with the
 110  * string to be displayed. This mimics System.out.println but works within the
 111  * test harness as well as standalone.
 112  */
 113 class Sysout {
 114 
 115     private static TestDialog dialog;
 116 
 117     public static void createDialogWithInstructions(String[] instructions) {
 118         dialog = new TestDialog(new Frame(), "Instructions");
 119         dialog.printInstructions(instructions);
 120         dialog.setVisible(true);
 121         println("Any messages for the tester will display here.");
 122     }
 123 
 124     public static void createDialog() {
 125         dialog = new TestDialog(new Frame(), "Instructions");
 126         String[] defInstr = {"Instructions will appear here. ", ""};
 127         dialog.printInstructions(defInstr);
 128         dialog.setVisible(true);
 129         println("Any messages for the tester will display here.");
 130     }
 131 
 132     public static void printInstructions(String[] instructions) {
 133         dialog.printInstructions(instructions);
 134     }
 135 
 136     public static void println(String messageIn) {
 137         dialog.displayMessage(messageIn);
 138     }
 139 }// Sysout  class
 140 
 141 /**
 142  * This is part of the standard test machinery. It provides a place for the test
 143  * instructions to be displayed, and a place for interactive messages to the
 144  * user to be displayed. To have the test instructions displayed, see Sysout. To
 145  * have a message to the user be displayed, see Sysout. Do not call anything in
 146  * this dialog directly.
 147  */
 148 class TestDialog extends Dialog {
 149 
 150     TextArea instructionsText;
 151     TextArea messageText;
 152     int maxStringLength = 80;
 153 
 154     //DO NOT call this directly, go through Sysout
 155     public TestDialog(Frame frame, String name) {
 156         super(frame, name);
 157         int scrollBoth = TextArea.SCROLLBARS_BOTH;
 158         instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
 159         add("North", instructionsText);
 160 
 161         messageText = new TextArea("", 5, maxStringLength, scrollBoth);
 162         add("Center", messageText);
 163 
 164         pack();
 165 
 166         setVisible(true);
 167     }// TestDialog()
 168 
 169     //DO NOT call this directly, go through Sysout
 170     public void printInstructions(String[] instructions) {
 171         //Clear out any current instructions
 172         instructionsText.setText("");
 173 
 174         //Go down array of instruction strings
 175 
 176         String printStr, remainingStr;
 177         for (int i = 0; i < instructions.length; i++) {
 178             //chop up each into pieces maxSringLength long
 179             remainingStr = instructions[ i];
 180             while (remainingStr.length() > 0) {
 181                 //if longer than max then chop off first max chars to print
 182                 if (remainingStr.length() >= maxStringLength) {
 183                     //Try to chop on a word boundary
 184                     int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);
 185 
 186                     if (posOfSpace <= 0) {
 187                         posOfSpace = maxStringLength - 1;
 188                     }
 189 
 190                     printStr = remainingStr.substring(0, posOfSpace + 1);
 191                     remainingStr = remainingStr.substring(posOfSpace + 1);
 192                 } //else just print
 193                 else {
 194                     printStr = remainingStr;
 195                     remainingStr = "";
 196                 }
 197 
 198                 instructionsText.append(printStr + "\n");
 199 
 200             }// while
 201 
 202         }// for
 203 
 204     }//printInstructions()
 205 
 206     //DO NOT call this directly, go through Sysout
 207     public void displayMessage(String messageIn) {
 208         messageText.append(messageIn + "\n");
 209         System.out.println(messageIn);
 210     }
 211 }// TestDialog  class