Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JOptionPane/8024926/bug8024926.java
38918 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.awt.BorderLayout;23import java.awt.Dialog;24import java.awt.EventQueue;25import java.awt.Frame;26import java.awt.TextArea;27import javax.swing.JApplet;28import javax.swing.JOptionPane;29import sun.awt.OSInfo;3031/**32* @test33* @bug 8024926 804027934* @summary [macosx] AquaIcon HiDPI support35* @author Alexander Scherbatiy36* @run applet/manual=yesno bug8024926.html37*/38public class bug8024926 extends JApplet {39//Declare things used in the test, like buttons and labels here4041public void init() {42//Create instructions for the user here, as well as set up43// the environment -- set the layout manager, add buttons,44// etc.45this.setLayout(new BorderLayout());464748if (OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) {49String[] instructions = {50"Verify that high resolution system icons are used"51+ " in JOptionPane on HiDPI displays.",52"1) Run the test on Retina display or enable the Quartz Debug"53+ " and select the screen resolution with (HiDPI) label",54"2) Check that the error icon on the JOptionPane is smooth",55"If so, press PASS, else press FAIL."56};57Sysout.createDialogWithInstructions(instructions);5859} else {60String[] instructions = {61"This test is not applicable to the current platform. Press PASS."62};63Sysout.createDialogWithInstructions(instructions);64}656667}//End init()6869public void start() {70//Get things going. Request focus, set size, et cetera71setSize(200, 200);72setVisible(true);73validate();74EventQueue.invokeLater(new Runnable() {7576public void run() {77createAndShowGUI();78}79});80}// start()8182//The rest of this class is the actions which perform the test...83//Use Sysout.println to communicate with the user NOT System.out!!84//Sysout.println ("Something Happened!");85private static void createAndShowGUI() {86JOptionPane.showMessageDialog(null,87"Icons should have high resolution.",88"High resolution icon test.",89JOptionPane.ERROR_MESSAGE);90}91}// class BlockedWindowTest9293/* Place other classes related to the test after this line */94/**95* **************************************************96* Standard Test Machinery DO NOT modify anything below -- it's a standard chunk97* of code whose purpose is to make user interaction uniform, and thereby make98* it simpler to read and understand someone else's test.99* **************************************************100*/101/**102* This is part of the standard test machinery. It creates a dialog (with the103* instructions), and is the interface for sending text messages to the user. To104* print the instructions, send an array of strings to Sysout.createDialog105* WithInstructions method. Put one line of instructions per array entry. To106* display a message for the tester to see, simply call Sysout.println with the107* string to be displayed. This mimics System.out.println but works within the108* test harness as well as standalone.109*/110class Sysout {111112private static TestDialog dialog;113114public static void createDialogWithInstructions(String[] instructions) {115dialog = new TestDialog(new Frame(), "Instructions");116dialog.printInstructions(instructions);117dialog.setVisible(true);118println("Any messages for the tester will display here.");119}120121public static void createDialog() {122dialog = new TestDialog(new Frame(), "Instructions");123String[] defInstr = {"Instructions will appear here. ", ""};124dialog.printInstructions(defInstr);125dialog.setVisible(true);126println("Any messages for the tester will display here.");127}128129public static void printInstructions(String[] instructions) {130dialog.printInstructions(instructions);131}132133public static void println(String messageIn) {134dialog.displayMessage(messageIn);135}136}// Sysout class137138/**139* This is part of the standard test machinery. It provides a place for the test140* instructions to be displayed, and a place for interactive messages to the141* user to be displayed. To have the test instructions displayed, see Sysout. To142* have a message to the user be displayed, see Sysout. Do not call anything in143* this dialog directly.144*/145class TestDialog extends Dialog {146147TextArea instructionsText;148TextArea messageText;149int maxStringLength = 80;150151//DO NOT call this directly, go through Sysout152public TestDialog(Frame frame, String name) {153super(frame, name);154int scrollBoth = TextArea.SCROLLBARS_BOTH;155instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);156add("North", instructionsText);157158messageText = new TextArea("", 5, maxStringLength, scrollBoth);159add("Center", messageText);160161pack();162163setVisible(true);164}// TestDialog()165166//DO NOT call this directly, go through Sysout167public void printInstructions(String[] instructions) {168//Clear out any current instructions169instructionsText.setText("");170171//Go down array of instruction strings172173String printStr, remainingStr;174for (int i = 0; i < instructions.length; i++) {175//chop up each into pieces maxSringLength long176remainingStr = instructions[ i];177while (remainingStr.length() > 0) {178//if longer than max then chop off first max chars to print179if (remainingStr.length() >= maxStringLength) {180//Try to chop on a word boundary181int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);182183if (posOfSpace <= 0) {184posOfSpace = maxStringLength - 1;185}186187printStr = remainingStr.substring(0, posOfSpace + 1);188remainingStr = remainingStr.substring(posOfSpace + 1);189} //else just print190else {191printStr = remainingStr;192remainingStr = "";193}194195instructionsText.append(printStr + "\n");196197}// while198199}// for200201}//printInstructions()202203//DO NOT call this directly, go through Sysout204public void displayMessage(String messageIn) {205messageText.append(messageIn + "\n");206System.out.println(messageIn);207}208}// TestDialog class209210211