Path: blob/master/test/jdk/java/awt/List/SetFontTest/SetFontTest.java
41153 views
/*1* Copyright (c) 2005, 2007, 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*/2223/*24test25@bug 5010944 624807226@summary List's rows overlap one another27@author Dmitry Cherepanov area=awt-list28@run applet/manual=yesno SetFontTest.html29*/3031import java.applet.Applet;32import java.awt.*;33import java.awt.event.*;3435public class SetFontTest extends Applet36{37List list = new List(8, false);38Button button1 = new Button("Enlarge font");39Button button2 = new Button("Change mode");4041public void init()42{43list.add("111");44list.add("222");45list.add("333");46list.add("444");47this.add(list);4849this.add(button1);50this.add(button2);5152button1.addActionListener(53new ActionListener(){54public void actionPerformed(ActionEvent ae){55list.setFont( new Font( "SansSerif", Font.PLAIN, 30 ) );56list.repaint();57}58});5960button2.addActionListener(61new ActionListener(){62public void actionPerformed(ActionEvent ae){63list.setMultipleMode(true);64}65});6667this.setLayout (new FlowLayout ());6869String[] instructions =70{71"1) Click on the 'Enlarge font' button to enlarge font of the list.",72"2) If you see that the rows of the list overlap one another "+73"then the test failed. Otherwise, goto to the step 3.",74"3) Click on the 'Change mode' button to set multiple-selection mode.",75"4) If you see that the rows of the list overlap one another "+76"then the test failed. Otherwise, the test passed."77};78Sysout.createDialogWithInstructions( instructions );7980}//End init()8182public void start ()83{8485setSize (200,200);86setVisible(true);87validate();8889}// start()90}9192/* Place other classes related to the test after this line */939495969798/****************************************************99Standard Test Machinery100DO NOT modify anything below -- it's a standard101chunk of code whose purpose is to make user102interaction uniform, and thereby make it simpler103to read and understand someone else's test.104****************************************************/105106/**107This is part of the standard test machinery.108It creates a dialog (with the instructions), and is the interface109for sending text messages to the user.110To print the instructions, send an array of strings to Sysout.createDialog111WithInstructions method. Put one line of instructions per array entry.112To display a message for the tester to see, simply call Sysout.println113with the string to be displayed.114This mimics System.out.println but works within the test harness as well115as standalone.116*/117118class Sysout119{120private static TestDialog dialog;121122public static void createDialogWithInstructions( String[] instructions )123{124dialog = new TestDialog( new Frame(), "Instructions" );125dialog.printInstructions( instructions );126dialog.setVisible(true);127println( "Any messages for the tester will display here." );128}129130public static void createDialog( )131{132dialog = new TestDialog( new Frame(), "Instructions" );133String[] defInstr = { "Instructions will appear here. ", "" } ;134dialog.printInstructions( defInstr );135dialog.setVisible(true);136println( "Any messages for the tester will display here." );137}138139140public static void printInstructions( String[] instructions )141{142dialog.printInstructions( instructions );143}144145146public static void println( String messageIn )147{148dialog.displayMessage( messageIn );149}150151}// Sysout class152153/**154This is part of the standard test machinery. It provides a place for the155test instructions to be displayed, and a place for interactive messages156to the user to be displayed.157To have the test instructions displayed, see Sysout.158To have a message to the user be displayed, see Sysout.159Do not call anything in this dialog directly.160*/161class TestDialog extends Dialog162{163164TextArea instructionsText;165TextArea messageText;166int maxStringLength = 80;167168//DO NOT call this directly, go through Sysout169public TestDialog( Frame frame, String name )170{171super( frame, name );172int scrollBoth = TextArea.SCROLLBARS_BOTH;173instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );174add( "North", instructionsText );175176messageText = new TextArea( "", 5, maxStringLength, scrollBoth );177add("Center", messageText);178179pack();180181setVisible(true);182}// TestDialog()183184//DO NOT call this directly, go through Sysout185public void printInstructions( String[] instructions )186{187//Clear out any current instructions188instructionsText.setText( "" );189190//Go down array of instruction strings191192String printStr, remainingStr;193for( int i=0; i < instructions.length; i++ )194{195//chop up each into pieces maxSringLength long196remainingStr = instructions[ i ];197while( remainingStr.length() > 0 )198{199//if longer than max then chop off first max chars to print200if( remainingStr.length() >= maxStringLength )201{202//Try to chop on a word boundary203int posOfSpace = remainingStr.204lastIndexOf( ' ', maxStringLength - 1 );205206if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;207208printStr = remainingStr.substring( 0, posOfSpace + 1 );209remainingStr = remainingStr.substring( posOfSpace + 1 );210}211//else just print212else213{214printStr = remainingStr;215remainingStr = "";216}217218instructionsText.append( printStr + "\n" );219220}// while221222}// for223224}//printInstructions()225226//DO NOT call this directly, go through Sysout227public void displayMessage( String messageIn )228{229messageText.append( messageIn + "\n" );230System.out.println(messageIn);231}232233}// TestDialog class234235236