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