Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/List/SetFontTest/SetFontTest.java
41153 views
1
/*
2
* Copyright (c) 2005, 2007, 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
24
/*
25
test
26
@bug 5010944 6248072
27
@summary List's rows overlap one another
28
@author Dmitry Cherepanov area=awt-list
29
@run applet/manual=yesno SetFontTest.html
30
*/
31
32
import java.applet.Applet;
33
import java.awt.*;
34
import java.awt.event.*;
35
36
public class SetFontTest extends Applet
37
{
38
List list = new List(8, false);
39
Button button1 = new Button("Enlarge font");
40
Button button2 = new Button("Change mode");
41
42
public void init()
43
{
44
list.add("111");
45
list.add("222");
46
list.add("333");
47
list.add("444");
48
this.add(list);
49
50
this.add(button1);
51
this.add(button2);
52
53
button1.addActionListener(
54
new ActionListener(){
55
public void actionPerformed(ActionEvent ae){
56
list.setFont( new Font( "SansSerif", Font.PLAIN, 30 ) );
57
list.repaint();
58
}
59
});
60
61
button2.addActionListener(
62
new ActionListener(){
63
public void actionPerformed(ActionEvent ae){
64
list.setMultipleMode(true);
65
}
66
});
67
68
this.setLayout (new FlowLayout ());
69
70
String[] instructions =
71
{
72
"1) Click on the 'Enlarge font' button to enlarge font of the list.",
73
"2) If you see that the rows of the list overlap one another "+
74
"then the test failed. Otherwise, goto to the step 3.",
75
"3) Click on the 'Change mode' button to set multiple-selection mode.",
76
"4) If you see that the rows of the list overlap one another "+
77
"then the test failed. Otherwise, the test passed."
78
};
79
Sysout.createDialogWithInstructions( instructions );
80
81
}//End init()
82
83
public void start ()
84
{
85
86
setSize (200,200);
87
setVisible(true);
88
validate();
89
90
}// start()
91
}
92
93
/* Place other classes related to the test after this line */
94
95
96
97
98
99
/****************************************************
100
Standard Test Machinery
101
DO NOT modify anything below -- it's a standard
102
chunk of code whose purpose is to make user
103
interaction uniform, and thereby make it simpler
104
to read and understand someone else's test.
105
****************************************************/
106
107
/**
108
This is part of the standard test machinery.
109
It creates a dialog (with the instructions), and is the interface
110
for sending text messages to the user.
111
To print the instructions, send an array of strings to Sysout.createDialog
112
WithInstructions method. Put one line of instructions per array entry.
113
To display a message for the tester to see, simply call Sysout.println
114
with the string to be displayed.
115
This mimics System.out.println but works within the test harness as well
116
as standalone.
117
*/
118
119
class Sysout
120
{
121
private static TestDialog dialog;
122
123
public static void createDialogWithInstructions( String[] instructions )
124
{
125
dialog = new TestDialog( new Frame(), "Instructions" );
126
dialog.printInstructions( instructions );
127
dialog.setVisible(true);
128
println( "Any messages for the tester will display here." );
129
}
130
131
public static void createDialog( )
132
{
133
dialog = new TestDialog( new Frame(), "Instructions" );
134
String[] defInstr = { "Instructions will appear here. ", "" } ;
135
dialog.printInstructions( defInstr );
136
dialog.setVisible(true);
137
println( "Any messages for the tester will display here." );
138
}
139
140
141
public static void printInstructions( String[] instructions )
142
{
143
dialog.printInstructions( instructions );
144
}
145
146
147
public static void println( String messageIn )
148
{
149
dialog.displayMessage( messageIn );
150
}
151
152
}// Sysout class
153
154
/**
155
This is part of the standard test machinery. It provides a place for the
156
test instructions to be displayed, and a place for interactive messages
157
to the user to be displayed.
158
To have the test instructions displayed, see Sysout.
159
To have a message to the user be displayed, see Sysout.
160
Do not call anything in this dialog directly.
161
*/
162
class TestDialog extends Dialog
163
{
164
165
TextArea instructionsText;
166
TextArea messageText;
167
int maxStringLength = 80;
168
169
//DO NOT call this directly, go through Sysout
170
public TestDialog( Frame frame, String name )
171
{
172
super( frame, name );
173
int scrollBoth = TextArea.SCROLLBARS_BOTH;
174
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
175
add( "North", instructionsText );
176
177
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
178
add("Center", messageText);
179
180
pack();
181
182
setVisible(true);
183
}// TestDialog()
184
185
//DO NOT call this directly, go through Sysout
186
public void printInstructions( String[] instructions )
187
{
188
//Clear out any current instructions
189
instructionsText.setText( "" );
190
191
//Go down array of instruction strings
192
193
String printStr, remainingStr;
194
for( int i=0; i < instructions.length; i++ )
195
{
196
//chop up each into pieces maxSringLength long
197
remainingStr = instructions[ i ];
198
while( remainingStr.length() > 0 )
199
{
200
//if longer than max then chop off first max chars to print
201
if( remainingStr.length() >= maxStringLength )
202
{
203
//Try to chop on a word boundary
204
int posOfSpace = remainingStr.
205
lastIndexOf( ' ', maxStringLength - 1 );
206
207
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
208
209
printStr = remainingStr.substring( 0, posOfSpace + 1 );
210
remainingStr = remainingStr.substring( posOfSpace + 1 );
211
}
212
//else just print
213
else
214
{
215
printStr = remainingStr;
216
remainingStr = "";
217
}
218
219
instructionsText.append( printStr + "\n" );
220
221
}// while
222
223
}// for
224
225
}//printInstructions()
226
227
//DO NOT call this directly, go through Sysout
228
public void displayMessage( String messageIn )
229
{
230
messageText.append( messageIn + "\n" );
231
System.out.println(messageIn);
232
}
233
234
}// TestDialog class
235
236