Path: blob/master/test/jdk/javax/swing/JOptionPane/8024926/bug8024926.java
41153 views
/*1* Copyright (c) 2013, 2018, 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;2930import jdk.test.lib.Platform;3132/**33* @test34* @bug 8024926 804027935* @summary [macosx] AquaIcon HiDPI support36* @author Alexander Scherbatiy37* @library /test/lib38* @build jdk.test.lib.Platform39* @run applet/manual=yesno bug8024926.html40*/41public class bug8024926 extends JApplet {42//Declare things used in the test, like buttons and labels here4344public void init() {45//Create instructions for the user here, as well as set up46// the environment -- set the layout manager, add buttons,47// etc.48this.setLayout(new BorderLayout());495051if (Platform.isOSX()) {52String[] 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};60Sysout.createDialogWithInstructions(instructions);6162} else {63String[] instructions = {64"This test is not applicable to the current platform. Press PASS."65};66Sysout.createDialogWithInstructions(instructions);67}686970}//End init()7172public void start() {73//Get things going. Request focus, set size, et cetera74setSize(200, 200);75setVisible(true);76validate();77EventQueue.invokeLater(new Runnable() {7879public void run() {80createAndShowGUI();81}82});83}// start()8485//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!");88private static void createAndShowGUI() {89JOptionPane.showMessageDialog(null,90"Icons should have high resolution.",91"High resolution icon test.",92JOptionPane.ERROR_MESSAGE);93}94}// class BlockedWindowTest9596/* 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 chunk100* of code whose purpose is to make user interaction uniform, and thereby make101* 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 the106* instructions), and is the interface for sending text messages to the user. To107* print the instructions, send an array of strings to Sysout.createDialog108* WithInstructions method. Put one line of instructions per array entry. To109* display a message for the tester to see, simply call Sysout.println with the110* string to be displayed. This mimics System.out.println but works within the111* test harness as well as standalone.112*/113class Sysout {114115private static TestDialog dialog;116117public static void createDialogWithInstructions(String[] instructions) {118dialog = new TestDialog(new Frame(), "Instructions");119dialog.printInstructions(instructions);120dialog.setVisible(true);121println("Any messages for the tester will display here.");122}123124public static void createDialog() {125dialog = new TestDialog(new Frame(), "Instructions");126String[] defInstr = {"Instructions will appear here. ", ""};127dialog.printInstructions(defInstr);128dialog.setVisible(true);129println("Any messages for the tester will display here.");130}131132public static void printInstructions(String[] instructions) {133dialog.printInstructions(instructions);134}135136public static void println(String messageIn) {137dialog.displayMessage(messageIn);138}139}// Sysout class140141/**142* This is part of the standard test machinery. It provides a place for the test143* instructions to be displayed, and a place for interactive messages to the144* user to be displayed. To have the test instructions displayed, see Sysout. To145* have a message to the user be displayed, see Sysout. Do not call anything in146* this dialog directly.147*/148class TestDialog extends Dialog {149150TextArea instructionsText;151TextArea messageText;152int maxStringLength = 80;153154//DO NOT call this directly, go through Sysout155public TestDialog(Frame frame, String name) {156super(frame, name);157int scrollBoth = TextArea.SCROLLBARS_BOTH;158instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);159add("North", instructionsText);160161messageText = new TextArea("", 5, maxStringLength, scrollBoth);162add("Center", messageText);163164pack();165166setVisible(true);167}// TestDialog()168169//DO NOT call this directly, go through Sysout170public void printInstructions(String[] instructions) {171//Clear out any current instructions172instructionsText.setText("");173174//Go down array of instruction strings175176String printStr, remainingStr;177for (int i = 0; i < instructions.length; i++) {178//chop up each into pieces maxSringLength long179remainingStr = instructions[ i];180while (remainingStr.length() > 0) {181//if longer than max then chop off first max chars to print182if (remainingStr.length() >= maxStringLength) {183//Try to chop on a word boundary184int posOfSpace = remainingStr.lastIndexOf(' ', maxStringLength - 1);185186if (posOfSpace <= 0) {187posOfSpace = maxStringLength - 1;188}189190printStr = remainingStr.substring(0, posOfSpace + 1);191remainingStr = remainingStr.substring(posOfSpace + 1);192} //else just print193else {194printStr = remainingStr;195remainingStr = "";196}197198instructionsText.append(printStr + "\n");199200}// while201202}// for203204}//printInstructions()205206//DO NOT call this directly, go through Sysout207public void displayMessage(String messageIn) {208messageText.append(messageIn + "\n");209System.out.println(messageIn);210}211}// TestDialog class212213214