|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
26 | 26 | * @bug 6568874
|
27 | 27 | * @key printer
|
28 | 28 | * @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 |
30 | 32 | */
|
31 | 33 |
|
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; |
35 | 42 |
|
36 | 43 | 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. |
37 | 53 |
|
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.) |
48 | 56 |
|
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 | + """; |
50 | 60 |
|
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 | + } |
54 | 73 |
|
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 | + } |
59 | 78 |
|
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 | + } |
74 | 88 | }
|
0 commit comments