Skip to content

Commit fff5d8e

Browse files
committed
8274456: Remove jtreg tag manual=yesno java/awt/print/PrinterJob/PageDialogTest.java
Backport-of: d57fb6f684eac5a7e68842dcf3284309e3867521
1 parent 89d73c2 commit fff5d8e

File tree

1 file changed

+91
-137
lines changed

1 file changed

+91
-137
lines changed
Lines changed: 91 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,157 +21,111 @@
2121
* questions.
2222
*/
2323

24-
/* @test
24+
/*
25+
@test
2526
@bug 6302514
26-
@run main/manual=yesno PageDialogTest
27+
@run main/manual PageDialogTest
2728
@summary A toolkit modal dialog should not be blocked by Page/Print dialog.
2829
*/
29-
import java.awt.*;
30-
import java.awt.event.*;
31-
import java.awt.print.*;
3230

33-
import javax.swing.*;
31+
import java.awt.BorderLayout;
32+
import java.awt.Button;
33+
import java.awt.Dialog;
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.awt.Panel;
37+
import java.awt.TextArea;
38+
import java.awt.event.WindowAdapter;
39+
import java.awt.event.WindowEvent;
40+
import java.awt.print.PageFormat;
41+
import java.awt.print.PrinterJob;
42+
import java.util.concurrent.CountDownLatch;
43+
import java.util.concurrent.TimeUnit;
3444

3545
public class PageDialogTest {
3646

37-
public static void main(String[] args) {
38-
String[] instructions =
39-
{
40-
"The test shows a Toolkit modal dialog. ",
41-
"Click the 'Open' button. It opens a page dialog.",
42-
"The test fails if the page dialog blocks the toolkit",
43-
"modal dialog, otherwise it passes."
44-
};
45-
46-
Sysout.createDialog( );
47-
Sysout.printInstructions( instructions );
48-
49-
Dialog td = new Dialog((Frame) null, "Toolkit modal dialog",
50-
Dialog.ModalityType.TOOLKIT_MODAL);
51-
td.setLayout(new FlowLayout());
52-
td.add(new Button("Dummy"));
53-
Button tdb = new Button("Open");
54-
tdb.addActionListener(new ActionListener() {
55-
public void actionPerformed(ActionEvent event) {
56-
PrinterJob.getPrinterJob().pageDialog(new PageFormat());
57-
}
47+
public static Frame frame;
48+
public static Dialog dialog;
49+
public static volatile boolean testResult;
50+
public static final CountDownLatch countDownLatch = new CountDownLatch(1);
51+
52+
public static void createUI() {
53+
frame = new Frame("Test 6302514");
54+
String instructions =
55+
"1. Click on the 'Show Dialog' button to show a 'Toolkit Modal Dialog' \n" +
56+
"2. Click on the 'Open PageDialog' button to show 'Page Dialog'.\n" +
57+
"3. The test fails if the page dialog blocks the toolkit\n"+
58+
" else test pass.\n" +
59+
"4. Close Page dialog and 'Toolkit modal dialog'\n" +
60+
"5. Click appropriate button to mark the test case pass or fail.\n" ;
61+
62+
TextArea instructionsTextArea = new TextArea( instructions, 8,
63+
50, TextArea.SCROLLBARS_NONE );
64+
instructionsTextArea.setEditable(false);
65+
frame.add(BorderLayout.NORTH, instructionsTextArea);
66+
67+
Panel buttonPanel = new Panel(new FlowLayout());
68+
Button passButton = new Button("pass");
69+
passButton.setActionCommand("pass");
70+
passButton.addActionListener(e -> {
71+
testResult = true;
72+
countDownLatch.countDown();
73+
dialog.dispose();
74+
frame.dispose();
5875
});
59-
td.add(tdb);
60-
td.setSize(250, 150);
61-
td.setVisible(true);
62-
}
63-
}
64-
65-
class Sysout {
66-
private static TestDialog dialog;
67-
68-
public static void createDialogWithInstructions( String[] instructions )
69-
{
70-
dialog = new TestDialog( new Frame(), "Instructions" );
71-
dialog.printInstructions( instructions );
72-
dialog.show();
73-
println( "Any messages for the tester will display here." );
74-
}
7576

76-
public static void createDialog( )
77-
{
78-
dialog = new TestDialog( new Frame(), "Instructions" );
79-
String[] defInstr = { "Instructions will appear here. ", "" } ;
80-
dialog.printInstructions( defInstr );
81-
dialog.show();
82-
println( "Any messages for the tester will display here." );
83-
}
77+
Button failButton = new Button("fail");
78+
failButton.addActionListener(e->{
79+
testResult = false;
80+
countDownLatch.countDown();
81+
dialog.dispose();
82+
frame.dispose();
83+
});
8484

85+
Button showDialog = new Button("Show Dialog");
86+
showDialog.addActionListener(e->{
87+
createToolkitModalDialog();
88+
});
8589

86-
public static void printInstructions( String[] instructions )
87-
{
88-
dialog.printInstructions( instructions );
90+
buttonPanel.add(showDialog);
91+
buttonPanel.add(passButton);
92+
buttonPanel.add(failButton);
93+
frame.add(BorderLayout.SOUTH, buttonPanel);
94+
frame.pack();
95+
frame.setVisible(true);
8996
}
9097

98+
public static void createToolkitModalDialog() {
99+
dialog = new Dialog((Frame) null, "Toolkit modal dialog",
100+
Dialog.ModalityType.TOOLKIT_MODAL);
101+
dialog.setLayout(new FlowLayout());
102+
dialog.addWindowListener(new WindowAdapter() {
103+
@Override
104+
public void windowClosing(WindowEvent e) {
105+
super.windowClosing(e);
106+
dialog.dispose();
107+
}
108+
});
91109

92-
public static void println( String messageIn )
93-
{
94-
dialog.displayMessage( messageIn );
110+
Button openPageDialogButton = new Button("Open PageDialog");
111+
openPageDialogButton.addActionListener(e->{
112+
PrinterJob.getPrinterJob().pageDialog(new PageFormat());
113+
});
114+
dialog.add(openPageDialogButton);
115+
dialog.setSize(250, 150);
116+
dialog.setLocationRelativeTo(null);
117+
dialog.setVisible(true);
95118
}
96119

97-
}// Sysout class
98-
99-
/**
100-
This is part of the standard test machinery. It provides a place for the
101-
test instructions to be displayed, and a place for interactive messages
102-
to the user to be displayed.
103-
To have the test instructions displayed, see Sysout.
104-
To have a message to the user be displayed, see Sysout.
105-
Do not call anything in this dialog directly.
106-
*/
107-
class TestDialog extends Dialog {
108-
109-
TextArea instructionsText;
110-
TextArea messageText;
111-
int maxStringLength = 80;
112-
113-
//DO NOT call this directly, go through Sysout
114-
public TestDialog( Frame frame, String name )
115-
{
116-
super( frame, name );
117-
int scrollBoth = TextArea.SCROLLBARS_BOTH;
118-
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
119-
add( "North", instructionsText );
120-
121-
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
122-
add("Center", messageText);
123-
124-
pack();
125-
126-
show();
127-
}// TestDialog()
128-
129-
//DO NOT call this directly, go through Sysout
130-
public void printInstructions( String[] instructions )
131-
{
132-
//Clear out any current instructions
133-
instructionsText.setText( "" );
134-
135-
//Go down array of instruction strings
136-
137-
String printStr, remainingStr;
138-
for( int i=0; i < instructions.length; i++ )
139-
{
140-
//chop up each into pieces maxSringLength long
141-
remainingStr = instructions[ i ];
142-
while( remainingStr.length() > 0 )
143-
{
144-
//if longer than max then chop off first max chars to print
145-
if( remainingStr.length() >= maxStringLength )
146-
{
147-
//Try to chop on a word boundary
148-
int posOfSpace = remainingStr.
149-
lastIndexOf( ' ', maxStringLength - 1 );
150-
151-
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
152-
153-
printStr = remainingStr.substring( 0, posOfSpace + 1 );
154-
remainingStr = remainingStr.substring( posOfSpace + 1 );
155-
}
156-
//else just print
157-
else
158-
{
159-
printStr = remainingStr;
160-
remainingStr = "";
161-
}
162-
163-
instructionsText.append( printStr + "\n" );
164-
165-
}// while
166-
167-
}// for
168-
169-
}//printInstructions()
170-
171-
//DO NOT call this directly, go through Sysout
172-
public void displayMessage( String messageIn )
173-
{
174-
messageText.append( messageIn + "\n" );
120+
public static void main(String []args) throws InterruptedException {
121+
createUI();
122+
if ( !countDownLatch.await(5, TimeUnit.MINUTES)) {
123+
throw new RuntimeException("Timeout : user did not perform any " +
124+
"action on the UI.");
125+
}
126+
if ( !testResult) {
127+
throw new RuntimeException("Test failed");
128+
}
175129
}
130+
}
176131

177-
}// TestDialog class

0 commit comments

Comments
 (0)