|
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 8151590 |
|
26 * @summary All radio button should be selected when we call |
|
27 * setDefaultSelection(JobAttributes.DefaultSelectionType.ALL); |
|
28 * @run main/manual PrintTest |
|
29 */ |
|
30 import java.awt.BorderLayout; |
|
31 import java.awt.FlowLayout; |
|
32 import java.awt.JobAttributes; |
|
33 import java.awt.PageAttributes; |
|
34 import java.awt.PrintJob; |
|
35 import java.awt.Toolkit; |
|
36 import javax.swing.JButton; |
|
37 import javax.swing.JDialog; |
|
38 import javax.swing.JFrame; |
|
39 import javax.swing.JPanel; |
|
40 import javax.swing.JTextArea; |
|
41 import javax.swing.SwingUtilities; |
|
42 |
|
43 public class PrintTest { |
|
44 |
|
45 private static Thread mainThread; |
|
46 private static boolean testPassed; |
|
47 private static boolean testGeneratedInterrupt; |
|
48 |
|
49 public static void main(String[] args) throws Exception { |
|
50 SwingUtilities.invokeAndWait(new Runnable() { |
|
51 @Override |
|
52 public void run() { |
|
53 doTest(PrintTest::printTest); |
|
54 } |
|
55 }); |
|
56 mainThread = Thread.currentThread(); |
|
57 try { |
|
58 mainThread.sleep(30000); |
|
59 } catch (InterruptedException e) { |
|
60 if (!testPassed && testGeneratedInterrupt) { |
|
61 throw new RuntimeException("All radio button is not selected"); |
|
62 } |
|
63 } |
|
64 if (!testGeneratedInterrupt) { |
|
65 throw new RuntimeException("user has not executed the test"); |
|
66 } |
|
67 } |
|
68 |
|
69 private static void printTest() { |
|
70 JobAttributes job = new JobAttributes(); |
|
71 PageAttributes page = new PageAttributes(); |
|
72 job.setDialog(JobAttributes.DialogType.NATIVE); |
|
73 job.setDefaultSelection(JobAttributes.DefaultSelectionType.ALL); |
|
74 job.setFromPage(2); |
|
75 job.setToPage(5); |
|
76 Toolkit tk = Toolkit.getDefaultToolkit(); |
|
77 // setting this dialog to native printdialog |
|
78 if (tk != null) { |
|
79 PrintJob pj = tk.getPrintJob(new JFrame(), |
|
80 "testing the attribute setting ", job, page); |
|
81 } |
|
82 } |
|
83 |
|
84 public static synchronized void pass() { |
|
85 testPassed = true; |
|
86 testGeneratedInterrupt = true; |
|
87 mainThread.interrupt(); |
|
88 } |
|
89 |
|
90 public static synchronized void fail() { |
|
91 testPassed = false; |
|
92 testGeneratedInterrupt = true; |
|
93 mainThread.interrupt(); |
|
94 } |
|
95 |
|
96 private static void doTest(Runnable action) { |
|
97 String description |
|
98 = " Visual inspection of print dialog is required.\n" |
|
99 + " A print dialog will be shown.\n " |
|
100 + " Please verify ALL radio button is selected.\n" |
|
101 + " If ALL radio button is selected,press PASS else press FAIL"; |
|
102 |
|
103 final JDialog dialog = new JDialog(); |
|
104 dialog.setTitle("printSelectionTest"); |
|
105 JTextArea textArea = new JTextArea(description); |
|
106 textArea.setEditable(false); |
|
107 final JButton testButton = new JButton("Start Test"); |
|
108 final JButton passButton = new JButton("PASS"); |
|
109 passButton.setEnabled(false); |
|
110 passButton.addActionListener((e) -> { |
|
111 dialog.dispose(); |
|
112 pass(); |
|
113 }); |
|
114 final JButton failButton = new JButton("FAIL"); |
|
115 failButton.setEnabled(false); |
|
116 failButton.addActionListener((e) -> { |
|
117 dialog.dispose(); |
|
118 fail(); |
|
119 }); |
|
120 testButton.addActionListener((e) -> { |
|
121 testButton.setEnabled(false); |
|
122 action.run(); |
|
123 passButton.setEnabled(true); |
|
124 failButton.setEnabled(true); |
|
125 }); |
|
126 JPanel mainPanel = new JPanel(new BorderLayout()); |
|
127 mainPanel.add(textArea, BorderLayout.CENTER); |
|
128 JPanel buttonPanel = new JPanel(new FlowLayout()); |
|
129 buttonPanel.add(testButton); |
|
130 buttonPanel.add(passButton); |
|
131 buttonPanel.add(failButton); |
|
132 mainPanel.add(buttonPanel, BorderLayout.SOUTH); |
|
133 dialog.add(mainPanel); |
|
134 dialog.pack(); |
|
135 dialog.setVisible(true); |
|
136 } |
|
137 } |