Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTabbedPane/4666224/bug4666224.java
41155 views
1
/*
2
* Copyright (c) 2001, 2020, 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 java.awt.event.*;
26
import javax.swing.*;
27
/*
28
* test
29
* @bug 4666224
30
*/
31
32
public class bug4666224 extends JApplet {
33
final static int placements[] = { JTabbedPane.LEFT, JTabbedPane.RIGHT, JTabbedPane.TOP, JTabbedPane.BOTTOM };
34
private JTabbedPane tabPane;
35
private JPanel mainPanel;
36
37
public bug4666224() throws Exception {
38
java.awt.EventQueue.invokeAndWait( () -> {
39
tabPane = new JTabbedPane();
40
tabPane.addMouseListener(new MouseAdapter() {
41
public void mouseClicked(MouseEvent e) {
42
Point pt = e.getPoint();
43
System.out.println("Index at location: "
44
+ tabPane.indexAtLocation(pt.x, pt.y));
45
}
46
});
47
InputMap inputMap = createInputMap();
48
SwingUtilities.replaceUIInputMap(getRootPane(), JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);
49
ActionMap actionMap = createActionMap();
50
SwingUtilities.replaceUIActionMap(getRootPane(), actionMap);
51
52
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53
tabPane.setTabPlacement(JTabbedPane.TOP);
54
tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
55
JPanel panel = new JPanel();
56
panel.setPreferredSize(new Dimension(200, 300));
57
tabPane.addTab("Number Zero", panel);
58
panel = new JPanel();
59
//panel.requestFocus();
60
panel.setPreferredSize(new Dimension(200, 300));
61
tabPane.addTab("Number One", panel);
62
panel = new JPanel();
63
panel.setPreferredSize(new Dimension(200, 300));
64
tabPane.addTab("Number Two", panel);
65
panel = new JPanel();
66
panel.setPreferredSize(new Dimension(200, 300));
67
tabPane.addTab("Number Three", new JColorChooser());
68
panel = new JPanel();
69
panel.setPreferredSize(new Dimension(200, 300));
70
tabPane.addTab("Number Four", panel);
71
panel = new JPanel();
72
panel.setPreferredSize(new Dimension(200, 300));
73
tabPane.addTab("Number Five", panel);
74
panel = new JPanel();
75
panel.setPreferredSize(new Dimension(200, 300));
76
tabPane.addTab("Number Six", panel);
77
panel = new JPanel();
78
panel.setPreferredSize(new Dimension(200, 300));
79
tabPane.addTab("Number Seven", panel);
80
panel = new JPanel();
81
panel.setPreferredSize(new Dimension(200, 300));
82
tabPane.addTab("Number Eight", panel);
83
panel = new JPanel();
84
panel.setPreferredSize(new Dimension(200, 300));
85
tabPane.addTab("Number Nine", panel);
86
panel = new JPanel();
87
panel.setPreferredSize(new Dimension(200, 300));
88
tabPane.addTab("Number Ten", panel);
89
mainPanel = new JPanel();
90
mainPanel.add(tabPane);
91
92
getContentPane().add(mainPanel);
93
tabPane.requestFocus();
94
95
96
//pack();
97
//setVisible(true);
98
});
99
}
100
101
public void init() {
102
String[][] instructionsSet =
103
{
104
{
105
" Note : Incase of Assertion failure,user can enter",
106
" remarks by pressing 'Assertion Fail Remarks ' button",
107
" ",
108
" You would see an applet with JTabbedPane. Keep the size of applet variable.",
109
" ",
110
" ON ALL PLATFORMS",
111
"1. Click on any of the tabs, focus indicator is visible",
112
"2. Lose focus on the window by clicking on some other window ",
113
"3. Focus indicator should disappear",
114
"4. Regain focus on the window the focus indicator should reappear." ,
115
" If focus doesn't behave as above, ",
116
" press 'Assertion Fail' else press 'Assertion Pass'",
117
},
118
{
119
" Note : Incase of Assertion failure,user can enter",
120
" remarks by pressing 'Assertion Fail Remarks ' button",
121
" ",
122
" You would see an applet with JTabbedPane. Keep the size of applet variable.",
123
" ",
124
" ON ALL PLATFORMS",
125
"1. type 'C' to change the tab layout to WRAP_TAB_LAYOUT ",
126
"2. Lose focus on the window by clicking on some other window ",
127
"3. Focus indicator should disappear",
128
"4. Regain focus on the window the focus indicator should reappear." ,
129
" If focus doesn't behave as above, ",
130
" press 'Assertion Fail' else press 'Assertion Pass'",
131
},
132
133
{
134
" Note : Incase of Assertion failure,user can enter",
135
" remarks by pressing 'Assertion Fail Remarks ' button",
136
" ",
137
" You would see an applet with JTabbedPane. Keep the size of applet variable.",
138
" ",
139
" ON ALL PLATFORMS",
140
"1. type 'R' to align the tabs to the right side ",
141
"2. Lose focus on the window by clicking on some other window ",
142
"3. Focus indicator should disappear",
143
"4. Regain focus on the window the focus indicator should reappear." ,
144
" If focus doesn't behave as above, ",
145
" press 'Assertion Fail' else press 'Assertion Pass'",
146
},
147
148
{
149
" Note : Incase of Assertion failure,user can enter",
150
" remarks by pressing 'Assertion Fail Remarks ' button",
151
" ",
152
" You would see an applet with JTabbedPane. Keep the size of applet variable.",
153
" ",
154
" ON ALL PLATFORMS",
155
"1. type 'B' to align the tabs to the bottom side ",
156
"2. Lose focus on the window by clicking on some other window ",
157
"3. Focus indicator should disappear",
158
"4. Regain focus on the window the focus indicator should reappear." ,
159
" If focus doesn't behave as above, ",
160
" press 'Assertion Fail' else press 'Assertion Pass'",
161
},
162
163
{
164
" Note : Incase of Assertion failure,user can enter",
165
" remarks by pressing 'Assertion Fail Remarks ' button",
166
" ",
167
" You would see an applet with JTabbedPane. Keep the size of applet variable.",
168
" ",
169
" ON ALL PLATFORMS",
170
"1. type 'L' to align the tabs to the left side ",
171
"2. Lose focus on the window by clicking on some other window ",
172
"3. Focus indicator should disappear",
173
"4. Regain focus on the window the focus indicator should reappear." ,
174
" If focus doesn't behave as above, ",
175
" press 'Assertion Fail' else press 'Assertion Pass'",
176
},
177
178
179
{
180
" Note : Incase of Assertion failure,user can enter",
181
" remarks by pressing 'Assertion Fail Remarks ' button",
182
" ",
183
" You would see an applet with JTabbedPane. Keep the size of applet variable.",
184
" ",
185
" ON ALL PLATFORMS",
186
"1. type 'T' to align the tabs to the top side ",
187
"2. Lose focus on the window by clicking on some other window ",
188
"3. Focus indicator should disappear",
189
"4. Regain focus on the window the focus indicator should reappear." ,
190
" If focus doesn't behave as above, ",
191
" press 'Assertion Fail' else press 'Assertion Pass'",
192
},
193
194
{
195
" Note : Incase of Assertion failure,user can enter",
196
" remarks by pressing 'Assertion Fail Remarks ' button",
197
" ",
198
" You would see an applet with JTabbedPane. Keep the size of applet variable.",
199
" ",
200
" ON ALL PLATFORMS",
201
"1. type 'B' to align the tabs to the bottom side ",
202
"2. Lose focus on the window by clicking on some other window ",
203
"3. Focus indicator should disappear",
204
"4. Regain focus on the window the focus indicator should reappear." ,
205
" If focus doesn't behave as above, ",
206
" press 'Assertion Fail' else press 'Assertion Pass'",
207
},
208
209
{
210
" Note : Incase of Assertion failure,user can enter",
211
" remarks by pressing 'Assertion Fail Remarks ' button",
212
" ",
213
" You would see an applet with JTabbedPane. Keep the size of applet variable.",
214
" ",
215
" ON ALL PLATFORMS",
216
"1. type 'R' to align the tabs to the right side ",
217
"2. Lose focus on the window by clicking on some other window ",
218
"3. Focus indicator should disappear",
219
"4. Regain focus on the window the focus indicator should reappear." ,
220
" If focus doesn't behave as above, ",
221
" press 'Assertion Fail' else press 'Assertion Pass'",
222
}
223
};
224
225
String[] exceptionsSet =
226
{
227
"Focus painted incorrectly in tabbed pane(SCROLL_TAB_LAYOUT) when tabs aligned to the TOP of the window",
228
"Focus painted incorrectly in tabbed pane(SCROLL_TAB_LAYOUT) when tabs aligned to the RIGHT of the window",
229
"Focus painted incorrectly in tabbed pane(SCROLL_TAB_LAYOUT) when tabs aligned to the BOTTOM of the window",
230
"Focus painted incorrectly in tabbed pane(SCROLL_TAB_LAYOUT) when tabs aligned to the LEFT of the window",
231
"Focus painted incorrectly in tabbed pane(WRAP_TAB_LAYOUT) when tabs aligned to the LEFT of the window",
232
"Focus painted incorrectly in tabbed pane(WRAP_TAB_LAYOUT) when tabs aligned to the TOP of the window",
233
"Focus painted incorrectly in tabbed pane(WRAP_TAB_LAYOUT) when tabs aligned to the BOTTOM of the window",
234
"Focus painted incorrectly in tabbed pane(WRAP_TAB_LAYOUT) when tabs aligned to the RIGHT of the window"
235
};
236
237
Sysout.setInstructionsWithExceptions(instructionsSet,exceptionsSet);
238
239
}
240
241
public void start (){}
242
243
public void destroy(){
244
if(Sysout.failStatus()) {
245
String failMsg = Sysout.getFailureMessages();
246
failMsg = failMsg.replace('\n',' ');
247
throw new RuntimeException(failMsg);
248
}// End destroy
249
}
250
251
protected InputMap createInputMap() {
252
return LookAndFeel.makeComponentInputMap(getRootPane(), new Object[] {
253
"R", "right",
254
"L", "left",
255
"T", "top",
256
"B", "bottom",
257
"C", "changeLayout",
258
"D", "dump"
259
});
260
}
261
262
protected ActionMap createActionMap() {
263
ActionMap map = new ActionMap();
264
map.put("right", new RotateAction(JTabbedPane.RIGHT));
265
map.put("left", new RotateAction(JTabbedPane.LEFT));
266
map.put("top", new RotateAction(JTabbedPane.TOP));
267
map.put("bottom", new RotateAction(JTabbedPane.BOTTOM));
268
map.put("changeLayout", new ChangeLayoutAction());
269
map.put("dump", new DumpAction());
270
return map;
271
}
272
273
private class RotateAction extends AbstractAction {
274
private int placement;
275
public RotateAction(int placement) {
276
this.placement = placement;
277
}
278
279
public void actionPerformed(ActionEvent e) {
280
tabPane.setTabPlacement(placement);
281
}
282
}
283
284
private class ChangeLayoutAction extends AbstractAction {
285
private boolean a = true;
286
public void actionPerformed(ActionEvent e) {
287
if (a) {
288
tabPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
289
a = false;
290
} else {
291
tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
292
a = true;
293
}
294
}
295
}
296
297
private class DumpAction extends AbstractAction {
298
public void actionPerformed(ActionEvent e) {
299
for (int i = 0; i < tabPane.getTabCount(); i++) {
300
System.out.println("Tab: " + i + " "
301
+ tabPane.getUI().getTabBounds(tabPane, i));
302
}
303
}
304
}
305
}
306
307
308
/****************************************************
309
Standard Test Machinery
310
DO NOT modify anything below -- it's a standard
311
chunk of code whose purpose is to make user
312
interaction uniform, and thereby make it simpler
313
to read and understand someone else's test.
314
****************************************************/
315
316
/**
317
This is part of the standard test machinery.
318
It creates a dialog (with the instructions), and is the interface
319
for sending text messages to the user.
320
To print the instructions, send an array of strings to Sysout.createDialog
321
WithInstructions method. Put one line of instructions per array entry.
322
To display a message for the tester to see, simply call Sysout.println
323
with the string to be displayed.
324
This mimics System.out.println but works within the test harness as well
325
as standalone.
326
*/
327
328
class Sysout
329
{
330
private static TestDialog dialog;
331
332
public static void createDialogWithInstructions( String[] instructions )
333
{
334
dialog = new TestDialog( new Frame(), "Instructions" );
335
dialog.printInstructions( instructions );
336
dialog.show();
337
println( "Any messages for the tester will display here." );
338
}
339
340
public static void createDialog( )
341
{
342
dialog = new TestDialog( new Frame(), "Instructions" );
343
String[] defInstr = { "Instructions will appear here. ", "" } ;
344
dialog.printInstructions( defInstr );
345
dialog.show();
346
println( "Any messages for the tester will display here." );
347
}
348
349
350
public static void printInstructions( String[] instructions )
351
{
352
dialog.printInstructions( instructions );
353
}
354
355
356
public static void println( String messageIn )
357
{
358
dialog.displayMessage( messageIn );
359
}
360
361
public static void setInstructionsWithExceptions(String instructionsSet[][],
362
String exceptionsSet[]) {
363
createDialogWithInstructions(instructionsSet[0]);
364
dialog.setInstructions(instructionsSet);
365
dialog.setExceptionMessages(exceptionsSet);
366
}
367
368
public static String getFailureMessages() {
369
return dialog.failureMessages;
370
}
371
372
public static boolean failStatus() {
373
return dialog.failStatus;
374
}
375
376
}// Sysout class
377
378
/**
379
This is part of the standard test machinery. It provides a place for the
380
test instructions to be displayed, and a place for interactive messages
381
to the user to be displayed.
382
To have the test instructions displayed, see Sysout.
383
To have a message to the user be displayed, see Sysout.
384
Do not call anything in this dialog directly.
385
*/
386
class TestDialog extends Dialog
387
{
388
389
TextArea instructionsText;
390
TextArea messageText;
391
int maxStringLength = 70;
392
393
Panel assertPanel;
394
Button assertPass,assertFail,remarks;
395
HandleAssert handleAssert;
396
boolean failStatus=false;
397
int instructionCounter=0;
398
String instructions[][];
399
int exceptionCounter=0;
400
String exceptionMessages[];
401
String failureMessages="<br>";
402
String remarksMessage=null;
403
RemarksDialog remarksDialog;
404
405
//DO NOT call this directly, go through Sysout
406
public TestDialog( Frame frame, String name )
407
{
408
super( frame, name );
409
int scrollBoth = TextArea.SCROLLBARS_BOTH;
410
instructionsText = new TextArea( "", 14, maxStringLength, scrollBoth );
411
add( "North", instructionsText );
412
413
messageText = new TextArea( "", 3, maxStringLength, scrollBoth );
414
add("Center", messageText);
415
416
assertPanel = new Panel(new FlowLayout());
417
assertPass=new Button("Assertion Pass");
418
assertPass.setName("Assertion Pass");
419
assertFail=new Button("Assertion Fail");
420
assertFail.setName("Assertion Fail");
421
remarks = new Button("Assertion Fail Remarks");
422
remarks.setEnabled(false);
423
remarks.setName("Assertion Remarks");
424
assertPanel.add(assertPass);
425
assertPanel.add(assertFail);
426
assertPanel.add(remarks);
427
handleAssert = new HandleAssert();
428
assertPass.addActionListener(handleAssert);
429
assertFail.addActionListener(handleAssert);
430
remarks.addActionListener(handleAssert);
431
add("South",assertPanel);
432
pack();
433
434
show();
435
}// TestDialog()
436
437
//DO NOT call this directly, go through Sysout
438
public void printInstructions( String[] instructions )
439
{
440
//Clear out any current instructions
441
instructionsText.setText( "" );
442
443
//Go down array of instruction strings
444
445
String printStr, remainingStr;
446
for( int i=0; i < instructions.length; i++ )
447
{
448
//chop up each into pieces maxSringLength long
449
remainingStr = instructions[ i ];
450
while( remainingStr.length() > 0 )
451
{
452
//if longer than max then chop off first max chars to print
453
if( remainingStr.length() >= maxStringLength )
454
{
455
//Try to chop on a word boundary
456
int posOfSpace = remainingStr.
457
lastIndexOf( ' ', maxStringLength - 1 );
458
459
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
460
461
printStr = remainingStr.substring( 0, posOfSpace + 1 );
462
remainingStr = remainingStr.substring( posOfSpace + 1 );
463
}
464
//else just print
465
else
466
{
467
printStr = remainingStr;
468
remainingStr = "";
469
}
470
471
instructionsText.append( printStr + "\n" );
472
473
}// while
474
475
}// for
476
477
}//printInstructions()
478
479
//DO NOT call this directly, go through Sysout
480
public void displayMessage( String messageIn )
481
{
482
messageText.append( messageIn + "\n" );
483
}
484
485
public void emptyMessage() {
486
messageText.setText("");
487
}
488
489
public void setInstructions(String insStr[][]) {
490
instructions=insStr;
491
}
492
493
public void setExceptionMessages(String exceptionMessages[]) {
494
this.exceptionMessages=exceptionMessages;
495
}
496
497
class HandleAssert implements ActionListener {
498
public void actionPerformed(ActionEvent ae) {
499
if(ae.getSource()==remarks) {
500
remarksDialog = new RemarksDialog(TestDialog.this,
501
"Assertion Remarks Dialog",true);
502
remarks.setEnabled(false);
503
if(remarksMessage!=null)
504
failureMessages+=". User Remarks : "+remarksMessage;
505
}
506
else {
507
if(instructionCounter<instructions.length-1) {
508
emptyMessage();
509
instructionCounter++;
510
printInstructions(instructions[instructionCounter]);
511
}
512
else {
513
emptyMessage();
514
displayMessage("Testcase Completed");
515
displayMessage("Press 'Done' button in the "+
516
"BaseApplet to close");
517
assertPass.setEnabled(false);
518
assertFail.setEnabled(false);
519
}
520
521
if(ae.getSource()==assertPass) {
522
// anything to be done in future
523
}
524
else if(ae.getSource()==assertFail) {
525
remarks.setEnabled(true);
526
if(!failStatus)
527
failStatus=true;
528
if(exceptionCounter<exceptionMessages.length) {
529
failureMessages = failureMessages + "<br>"+
530
exceptionMessages[exceptionCounter];
531
}
532
}
533
exceptionCounter++;
534
}
535
}
536
}
537
538
class RemarksDialog extends Dialog implements ActionListener{
539
Panel rootPanel,remarksPanel;
540
TextArea textarea;
541
Button addRemarks,cancelRemarks;
542
public RemarksDialog(Dialog owner,String title,boolean modal) {
543
super(owner,title,modal);
544
rootPanel = new Panel(new BorderLayout());
545
remarksPanel = new Panel(new FlowLayout());
546
textarea = new TextArea(5,30);
547
addRemarks=new Button("Add Remarks");
548
addRemarks.addActionListener(this);
549
cancelRemarks = new Button("Cancel Remarks");
550
cancelRemarks.addActionListener(this);
551
remarksPanel.add(addRemarks);
552
remarksPanel.add(cancelRemarks);
553
rootPanel.add(textarea,"Center");
554
rootPanel.add(remarksPanel,"South");
555
add(rootPanel);
556
setBounds(150,150,400,200);
557
setVisible(true);
558
}
559
560
public void actionPerformed(ActionEvent ae) {
561
remarksMessage=null;
562
if(ae.getSource()==addRemarks) {
563
String msg = textarea.getText().trim();
564
if (msg.length()>0)
565
remarksMessage=msg;
566
}
567
dispose();
568
}
569
570
}
571
572
}// TestDialog class
573
574