Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/print/attribute/ServiceDlgSheetCollateTest.java
41149 views
1
/*
2
* Copyright (c) 2016, 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
* @test
25
* @bug 5080830
26
* @summary Verify if SheetCollate option is disabled for flavors that do not
27
* support SheetCollate
28
* @run main/manual ServiceDlgSheetCollateTest
29
*/
30
import java.awt.BorderLayout;
31
import java.awt.FlowLayout;
32
import javax.print.DocFlavor;
33
import javax.print.PrintService;
34
import javax.print.PrintServiceLookup;
35
import javax.print.ServiceUI;
36
import javax.print.attribute.Attribute;
37
import javax.print.attribute.HashPrintRequestAttributeSet;
38
import javax.print.attribute.standard.SheetCollate;
39
import javax.swing.JButton;
40
import javax.swing.JDialog;
41
import javax.swing.JPanel;
42
import javax.swing.JTextArea;
43
import javax.swing.SwingUtilities;
44
45
public class ServiceDlgSheetCollateTest {
46
private static Thread mainThread;
47
private static boolean testPassed;
48
private static boolean testGeneratedInterrupt;
49
50
/**
51
* Starts the application.
52
*/
53
public static void main(java.lang.String[] args) throws Exception {
54
SwingUtilities.invokeAndWait(() -> {
55
doTest(ServiceDlgSheetCollateTest::printTest);
56
});
57
mainThread = Thread.currentThread();
58
try {
59
Thread.sleep(600000);
60
} catch (InterruptedException e) {
61
if (!testPassed && testGeneratedInterrupt) {
62
throw new RuntimeException("SheetCollate option is not disabled "
63
+ "for flavors that do not support sheetCollate");
64
}
65
}
66
if (!testGeneratedInterrupt) {
67
throw new RuntimeException("user has not executed the test");
68
}
69
}
70
71
private static void printTest() {
72
ServiceDlgSheetCollateTest pd = new ServiceDlgSheetCollateTest();
73
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
74
//DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
75
PrintService defService = null, service[] = null;
76
defService = PrintServiceLookup.lookupDefaultPrintService();
77
service = PrintServiceLookup.lookupPrintServices(flavor, null);
78
79
if ((service == null) || (service.length == 0)) {
80
throw new RuntimeException("No Printer services found");
81
}
82
if (defService != null) {
83
System.out.println("\nDefault print service: " + service );
84
System.out.println("is flavor: "+flavor+" supported? "+
85
defService.isDocFlavorSupported(flavor));
86
System.out.println("is SheetCollate category supported? "+
87
defService.isAttributeCategorySupported(SheetCollate.class));
88
System.out.println("is SheetCollate.COLLATED value supported ? "+
89
defService.isAttributeValueSupported(SheetCollate.COLLATED,
90
flavor, null));
91
}
92
HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
93
try {
94
PrintService selService = ServiceUI.printDialog(null, 200, 200, service, defService, flavor, prSet);
95
} catch (IllegalArgumentException ia) {
96
System.out.println("Exception thrown : " + ia);
97
}
98
99
System.out.println("\nSelected Values\n");
100
Attribute attr[] = prSet.toArray();
101
for (int x = 0; x < attr.length; x ++) {
102
System.out.println("Attribute: " + attr[x].getName() + " Value: " + attr[x]);
103
}
104
105
}
106
107
public static synchronized void pass() {
108
testPassed = true;
109
testGeneratedInterrupt = true;
110
mainThread.interrupt();
111
}
112
113
public static synchronized void fail() {
114
testPassed = false;
115
testGeneratedInterrupt = true;
116
mainThread.interrupt();
117
}
118
119
private static void doTest(Runnable action) {
120
String description
121
= " A print dialog would appear.\n"
122
+ " Increase the no. of copies.\n"
123
+ " If COLLATE checkbox gets enabled, press FAIL else press PASS.\n"
124
+ " Press Cancel to close the dialog.";
125
126
final JDialog dialog = new JDialog();
127
dialog.setTitle("printSelectionTest");
128
JTextArea textArea = new JTextArea(description);
129
textArea.setEditable(false);
130
final JButton testButton = new JButton("Start Test");
131
final JButton passButton = new JButton("PASS");
132
passButton.setEnabled(false);
133
passButton.addActionListener((e) -> {
134
dialog.dispose();
135
pass();
136
});
137
final JButton failButton = new JButton("FAIL");
138
failButton.setEnabled(false);
139
failButton.addActionListener((e) -> {
140
dialog.dispose();
141
fail();
142
});
143
testButton.addActionListener((e) -> {
144
testButton.setEnabled(false);
145
action.run();
146
passButton.setEnabled(true);
147
failButton.setEnabled(true);
148
});
149
JPanel mainPanel = new JPanel(new BorderLayout());
150
mainPanel.add(textArea, BorderLayout.CENTER);
151
JPanel buttonPanel = new JPanel(new FlowLayout());
152
buttonPanel.add(testButton);
153
buttonPanel.add(passButton);
154
buttonPanel.add(failButton);
155
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
156
dialog.add(mainPanel);
157
dialog.pack();
158
dialog.setVisible(true);
159
}
160
}
161
162
163