Skip to content

Commit 71806ba

Browse files
Maheshkumar BollapragadaPaul Hohensee
authored andcommitted
8359687: Use PassFailJFrame for java/awt/print/Dialog/DialogType.java
Backport-of: de34bb8e66253cef90ba79831dadec0252595b35
1 parent 0c02f7a commit 71806ba

File tree

1 file changed

+51
-37
lines changed

1 file changed

+51
-37
lines changed
Lines changed: 51 additions & 37 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, 2025, 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
@@ -26,49 +26,63 @@
2626
* @bug 6568874
2727
* @key printer
2828
* @summary Verify the native dialog works with attribute sets.
29-
* @run main/manual=yesno DialogType
29+
* @library /java/awt/regtesthelpers /test/lib
30+
* @build PassFailJFrame
31+
* @run main/manual DialogType
3032
*/
3133

32-
import java.awt.print.*;
33-
import javax.print.attribute.*;
34-
import javax.print.attribute.standard.*;
34+
import java.awt.print.PrinterJob;
35+
36+
import javax.print.attribute.Attribute;
37+
import javax.print.attribute.HashPrintRequestAttributeSet;
38+
import javax.print.attribute.PrintRequestAttributeSet;
39+
import javax.print.attribute.standard.DialogTypeSelection;
40+
41+
import jtreg.SkippedException;
3542

3643
public class DialogType {
44+
private static PrinterJob job;
45+
46+
private static final String INSTRUCTIONS = """
47+
Two print dialogs are shown in succession.
48+
Click Cancel in the dialogs to close them.
49+
50+
On macOS & on Windows, the first dialog is a native
51+
dialog provided by the OS, the second dialog is
52+
implemented in Swing, the dialogs differ in appearance.
3753
38-
static String[] instructions = {
39-
"This test assumes and requires that you have a printer installed",
40-
"It verifies that the dialogs behave properly when using new API",
41-
"to optionally select a native dialog where one is present.",
42-
"Two dialogs are shown in succession.",
43-
"The test passes as long as no exceptions are thrown, *AND*",
44-
"if running on Windows only, the first dialog is a native windows",
45-
"control which differs in appearance from the second dialog",
46-
""
47-
};
54+
The test passes as long as no exceptions are thrown.
55+
(If there's an exception, the test will fail automatically.)
4856
49-
public static void main(String[] args) {
57+
The test verifies that the dialogs behave properly when using new API
58+
to optionally select a native dialog where one is present.
59+
""";
5060

51-
for (int i=0;i<instructions.length;i++) {
52-
System.out.println(instructions[i]);
53-
}
61+
public static void main(String[] args) throws Exception {
62+
job = PrinterJob.getPrinterJob();
63+
if (job.getPrintService() == null) {
64+
throw new SkippedException("Test skipped, printer is unavailable");
65+
}
66+
PassFailJFrame passFailJFrame = PassFailJFrame.builder()
67+
.instructions(INSTRUCTIONS)
68+
.columns(40)
69+
.build();
70+
testDialogType();
71+
passFailJFrame.awaitAndCheck();
72+
}
5473

55-
PrinterJob job = PrinterJob.getPrinterJob();
56-
if (job.getPrintService() == null) {
57-
return;
58-
}
74+
private static void testDialogType() {
75+
setPrintDialogAttributes(DialogTypeSelection.NATIVE);
76+
setPrintDialogAttributes(DialogTypeSelection.COMMON);
77+
}
5978

60-
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
61-
aset.add(DialogTypeSelection.NATIVE);
62-
job.printDialog(aset);
63-
Attribute[] attrs = aset.toArray();
64-
for (int i=0;i<attrs.length;i++) {
65-
System.out.println(attrs[i]);
66-
}
67-
aset.add(DialogTypeSelection.COMMON);
68-
job.printDialog(aset);
69-
attrs = aset.toArray();
70-
for (int i=0;i<attrs.length;i++) {
71-
System.out.println(attrs[i]);
72-
}
73-
}
79+
private static void setPrintDialogAttributes(DialogTypeSelection selection) {
80+
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
81+
aset.add(selection);
82+
job.printDialog(aset);
83+
Attribute[] attrs = aset.toArray();
84+
for (int i = 0; i < attrs.length; i++) {
85+
System.out.println(attrs[i]);
86+
}
87+
}
7488
}

0 commit comments

Comments
 (0)