Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JToolTip/4644444/bug4644444.java
38918 views
1
/*
2
* Copyright (c) 2001, 2015, 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
import java.awt.*;
25
import javax.swing.*;
26
import java.awt.event.*;
27
28
/*
29
* test
30
* @bug 4644444 8076246
31
*/
32
33
public class bug4644444 extends JApplet {
34
35
JPanel panel;
36
JButton button;
37
38
public bug4644444() throws Exception {
39
java.awt.EventQueue.invokeLater( () -> {
40
panel = new JPanel();
41
button = new JButton("whooo");
42
button.setToolTipText("Somthing really long 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890");
43
panel.add(button);
44
getContentPane().add(panel);
45
});
46
}
47
48
public void init() {
49
String[][] instructionsSet =
50
{
51
{
52
" Note : Incase of Assertion failure,user can enter",
53
" remarks by pressing 'Assertion Fail Remarks ' button",
54
" ",
55
" You would see a testframe with a Button",
56
" ",
57
" ON ALL PLATFORMS",
58
"1. Move the mouse on the button, ",
59
" so that the tooltip attached to it comes up ",
60
"2. Tool tip should get adjusted it-self to show ",
61
" its full length of text. ",
62
"3. If tooltip text gets cut, ",
63
" press 'Assertion Fail' else press 'Assertion Pass'",
64
"4. Similarly, move the applet to different locations of the screen, ",
65
" & see if tooltip works properly everywhere. "
66
}
67
};
68
69
String[] exceptionsSet =
70
{
71
"JToolTip is shown partially when placed very close to screen boundaries",
72
};
73
74
Sysout.setInstructionsWithExceptions(instructionsSet,exceptionsSet);
75
76
}
77
78
public void start (){}
79
80
public void destroy(){
81
if(Sysout.failStatus()) {
82
String failMsg = Sysout.getFailureMessages();
83
failMsg = failMsg.replace('\n',' ');
84
throw new RuntimeException(failMsg);
85
}// End destroy
86
}
87
}
88
89
90
/****************************************************
91
Standard Test Machinery
92
DO NOT modify anything below -- it's a standard
93
chunk of code whose purpose is to make user
94
interaction uniform, and thereby make it simpler
95
to read and understand someone else's test.
96
****************************************************/
97
98
/**
99
This is part of the standard test machinery.
100
It creates a dialog (with the instructions), and is the interface
101
for sending text messages to the user.
102
To print the instructions, send an array of strings to Sysout.createDialog
103
WithInstructions method. Put one line of instructions per array entry.
104
To display a message for the tester to see, simply call Sysout.println
105
with the string to be displayed.
106
This mimics System.out.println but works within the test harness as well
107
as standalone.
108
*/
109
110
class Sysout
111
{
112
private static TestDialog dialog;
113
114
public static void createDialogWithInstructions( String[] instructions )
115
{
116
dialog = new TestDialog( new Frame(), "Instructions" );
117
dialog.printInstructions( instructions );
118
dialog.show();
119
println( "Any messages for the tester will display here." );
120
}
121
122
public static void createDialog( )
123
{
124
dialog = new TestDialog( new Frame(), "Instructions" );
125
String[] defInstr = { "Instructions will appear here. ", "" } ;
126
dialog.printInstructions( defInstr );
127
dialog.show();
128
println( "Any messages for the tester will display here." );
129
}
130
131
132
public static void printInstructions( String[] instructions )
133
{
134
dialog.printInstructions( instructions );
135
}
136
137
138
public static void println( String messageIn )
139
{
140
dialog.displayMessage( messageIn );
141
}
142
143
public static void setInstructionsWithExceptions(String instructionsSet[][],
144
String exceptionsSet[]) {
145
createDialogWithInstructions(instructionsSet[0]);
146
dialog.setInstructions(instructionsSet);
147
dialog.setExceptionMessages(exceptionsSet);
148
}
149
150
public static String getFailureMessages() {
151
return dialog.failureMessages;
152
}
153
154
public static boolean failStatus() {
155
return dialog.failStatus;
156
}
157
158
}// Sysout class
159
160
/**
161
This is part of the standard test machinery. It provides a place for the
162
test instructions to be displayed, and a place for interactive messages
163
to the user to be displayed.
164
To have the test instructions displayed, see Sysout.
165
To have a message to the user be displayed, see Sysout.
166
Do not call anything in this dialog directly.
167
*/
168
class TestDialog extends Dialog
169
{
170
171
TextArea instructionsText;
172
TextArea messageText;
173
int maxStringLength = 70;
174
175
Panel assertPanel;
176
Button assertPass,assertFail,remarks;
177
HandleAssert handleAssert;
178
boolean failStatus=false;
179
int instructionCounter=0;
180
String instructions[][];
181
int exceptionCounter=0;
182
String exceptionMessages[];
183
String failureMessages="<br>";
184
String remarksMessage=null;
185
RemarksDialog remarksDialog;
186
187
//DO NOT call this directly, go through Sysout
188
public TestDialog( Frame frame, String name )
189
{
190
super( frame, name );
191
int scrollBoth = TextArea.SCROLLBARS_BOTH;
192
instructionsText = new TextArea( "", 14, maxStringLength, scrollBoth );
193
add( "North", instructionsText );
194
195
messageText = new TextArea( "", 3, maxStringLength, scrollBoth );
196
add("Center", messageText);
197
198
assertPanel = new Panel(new FlowLayout());
199
assertPass=new Button("Assertion Pass");
200
assertPass.setName("Assertion Pass");
201
assertFail=new Button("Assertion Fail");
202
assertFail.setName("Assertion Fail");
203
remarks = new Button("Assertion Fail Remarks");
204
remarks.setEnabled(false);
205
remarks.setName("Assertion Remarks");
206
assertPanel.add(assertPass);
207
assertPanel.add(assertFail);
208
assertPanel.add(remarks);
209
handleAssert = new HandleAssert();
210
assertPass.addActionListener(handleAssert);
211
assertFail.addActionListener(handleAssert);
212
remarks.addActionListener(handleAssert);
213
add("South",assertPanel);
214
pack();
215
216
show();
217
}// TestDialog()
218
219
//DO NOT call this directly, go through Sysout
220
public void printInstructions( String[] instructions )
221
{
222
//Clear out any current instructions
223
instructionsText.setText( "" );
224
225
//Go down array of instruction strings
226
227
String printStr, remainingStr;
228
for( int i=0; i < instructions.length; i++ )
229
{
230
//chop up each into pieces maxSringLength long
231
remainingStr = instructions[ i ];
232
while( remainingStr.length() > 0 )
233
{
234
//if longer than max then chop off first max chars to print
235
if( remainingStr.length() >= maxStringLength )
236
{
237
//Try to chop on a word boundary
238
int posOfSpace = remainingStr.
239
lastIndexOf( ' ', maxStringLength - 1 );
240
241
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
242
243
printStr = remainingStr.substring( 0, posOfSpace + 1 );
244
remainingStr = remainingStr.substring( posOfSpace + 1 );
245
}
246
//else just print
247
else
248
{
249
printStr = remainingStr;
250
remainingStr = "";
251
}
252
253
instructionsText.append( printStr + "\n" );
254
255
}// while
256
257
}// for
258
259
}//printInstructions()
260
261
//DO NOT call this directly, go through Sysout
262
public void displayMessage( String messageIn )
263
{
264
messageText.append( messageIn + "\n" );
265
}
266
267
public void emptyMessage() {
268
messageText.setText("");
269
}
270
271
public void setInstructions(String insStr[][]) {
272
instructions=insStr;
273
}
274
275
public void setExceptionMessages(String exceptionMessages[]) {
276
this.exceptionMessages=exceptionMessages;
277
}
278
279
class HandleAssert implements ActionListener {
280
public void actionPerformed(ActionEvent ae) {
281
if(ae.getSource()==remarks) {
282
remarksDialog = new RemarksDialog(TestDialog.this,
283
"Assertion Remarks Dialog",true);
284
remarks.setEnabled(false);
285
if(remarksMessage!=null)
286
failureMessages+=". User Remarks : "+remarksMessage;
287
}
288
else {
289
if(instructionCounter<instructions.length-1) {
290
emptyMessage();
291
instructionCounter++;
292
printInstructions(instructions[instructionCounter]);
293
}
294
else {
295
emptyMessage();
296
displayMessage("Testcase Completed");
297
displayMessage("Press 'Done' button in the "+
298
"BaseApplet to close");
299
assertPass.setEnabled(false);
300
assertFail.setEnabled(false);
301
}
302
303
if(ae.getSource()==assertPass) {
304
// anything to be done in future
305
}
306
else if(ae.getSource()==assertFail) {
307
remarks.setEnabled(true);
308
if(!failStatus)
309
failStatus=true;
310
if(exceptionCounter<exceptionMessages.length) {
311
failureMessages = failureMessages + "<br>"+
312
exceptionMessages[exceptionCounter];
313
}
314
}
315
exceptionCounter++;
316
}
317
}
318
}
319
320
class RemarksDialog extends Dialog implements ActionListener{
321
Panel rootPanel,remarksPanel;
322
TextArea textarea;
323
Button addRemarks,cancelRemarks;
324
public RemarksDialog(Dialog owner,String title,boolean modal) {
325
super(owner,title,modal);
326
rootPanel = new Panel(new BorderLayout());
327
remarksPanel = new Panel(new FlowLayout());
328
textarea = new TextArea(5,30);
329
addRemarks=new Button("Add Remarks");
330
addRemarks.addActionListener(this);
331
cancelRemarks = new Button("Cancel Remarks");
332
cancelRemarks.addActionListener(this);
333
remarksPanel.add(addRemarks);
334
remarksPanel.add(cancelRemarks);
335
rootPanel.add(textarea,"Center");
336
rootPanel.add(remarksPanel,"South");
337
add(rootPanel);
338
setBounds(150,150,400,200);
339
setVisible(true);
340
}
341
342
public void actionPerformed(ActionEvent ae) {
343
remarksMessage=null;
344
if(ae.getSource()==addRemarks) {
345
String msg = textarea.getText().trim();
346
if (msg.length()>0)
347
remarksMessage=msg;
348
}
349
dispose();
350
}
351
352
}
353
354
}// TestDialog class
355
356