39518
|
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 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 8152419
|
|
27 |
* @summary To Verify JColorChooser tab selection
|
|
28 |
* @run main/manual Test8152419
|
|
29 |
*/
|
|
30 |
|
|
31 |
import java.awt.Color;
|
|
32 |
import java.awt.GridBagConstraints;
|
|
33 |
import java.awt.GridBagLayout;
|
|
34 |
import java.awt.event.ActionEvent;
|
|
35 |
import java.awt.event.ActionListener;
|
|
36 |
import java.util.concurrent.CountDownLatch;
|
|
37 |
import javax.swing.JButton;
|
|
38 |
import javax.swing.JColorChooser;
|
|
39 |
import javax.swing.JFrame;
|
|
40 |
import javax.swing.JPanel;
|
|
41 |
import javax.swing.JTextArea;
|
|
42 |
import javax.swing.SwingUtilities;
|
|
43 |
import javax.swing.UIManager;
|
|
44 |
import javax.swing.border.EmptyBorder;
|
|
45 |
|
|
46 |
public class Test8152419 {
|
|
47 |
|
|
48 |
public static void main(String args[]) throws Exception {
|
|
49 |
final CountDownLatch latch = new CountDownLatch(1);
|
|
50 |
|
|
51 |
JColorChooserTest test = new JColorChooserTest(latch);
|
|
52 |
Thread T1 = new Thread(test);
|
|
53 |
T1.start();
|
|
54 |
|
|
55 |
// wait for latch to complete
|
|
56 |
try {
|
|
57 |
latch.await();
|
|
58 |
} catch (InterruptedException ie) {
|
|
59 |
throw ie;
|
|
60 |
}
|
|
61 |
|
|
62 |
if (test.testResult == false) {
|
|
63 |
throw new RuntimeException("User Clicked Fail!");
|
|
64 |
}
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
class JColorChooserTest implements Runnable {
|
|
69 |
|
|
70 |
private static GridBagLayout layout;
|
|
71 |
private static JPanel mainControlPanel;
|
|
72 |
private static JPanel resultButtonPanel;
|
|
73 |
private static JTextArea instructionTextArea;
|
|
74 |
private static JButton passButton;
|
|
75 |
private static JButton failButton;
|
|
76 |
private static JFrame mainFrame;
|
|
77 |
private static JColorChooser colorChooser;
|
|
78 |
private final CountDownLatch latch;
|
|
79 |
public volatile boolean testResult = false;
|
|
80 |
|
|
81 |
public JColorChooserTest(CountDownLatch latch) throws Exception {
|
|
82 |
this.latch = latch;
|
|
83 |
}
|
|
84 |
|
|
85 |
@Override
|
|
86 |
public void run() {
|
|
87 |
|
|
88 |
try {
|
|
89 |
createUI();
|
|
90 |
} catch (Exception ex) {
|
|
91 |
if (mainFrame != null) {
|
|
92 |
mainFrame.dispose();
|
|
93 |
}
|
|
94 |
latch.countDown();
|
|
95 |
throw new RuntimeException("createUI Failed: " + ex.getMessage());
|
|
96 |
}
|
|
97 |
|
|
98 |
}
|
|
99 |
|
|
100 |
public final void createUI() throws Exception {
|
|
101 |
|
|
102 |
SwingUtilities.invokeAndWait(new Runnable() {
|
|
103 |
@Override
|
|
104 |
public void run() {
|
|
105 |
mainFrame = new JFrame("JColorChooser Test");
|
|
106 |
layout = new GridBagLayout();
|
|
107 |
mainControlPanel = new JPanel(layout);
|
|
108 |
resultButtonPanel = new JPanel(layout);
|
|
109 |
|
|
110 |
GridBagConstraints gbc = new GridBagConstraints();
|
|
111 |
String instructions
|
|
112 |
= "INSTRUCTIONS:"
|
|
113 |
+ "\n Select HSV, HSL, RGB or CMYK tab."
|
|
114 |
+ "\n If able to shift and view JColorChooser tabs"
|
|
115 |
+ "\n then click Pass, else Fail.";
|
|
116 |
|
|
117 |
instructionTextArea = new JTextArea();
|
|
118 |
instructionTextArea.setText(instructions);
|
|
119 |
instructionTextArea.setEnabled(true);
|
|
120 |
|
|
121 |
gbc.gridx = 0;
|
|
122 |
gbc.gridy = 0;
|
|
123 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
124 |
mainControlPanel.add(instructionTextArea, gbc);
|
|
125 |
|
|
126 |
UIManager.put("FormattedTextField.border",
|
|
127 |
new EmptyBorder(0, 10, 0, 10));
|
|
128 |
colorChooser = new JColorChooser(Color.BLUE);
|
|
129 |
gbc.gridx = 0;
|
|
130 |
gbc.gridy = 1;
|
|
131 |
mainControlPanel.add(colorChooser, gbc);
|
|
132 |
|
|
133 |
passButton = new JButton("Pass");
|
|
134 |
passButton.setActionCommand("Pass");
|
|
135 |
passButton.addActionListener((ActionEvent e) -> {
|
|
136 |
testResult = true;
|
|
137 |
mainFrame.dispose();
|
|
138 |
latch.countDown();
|
|
139 |
|
|
140 |
});
|
|
141 |
failButton = new JButton("Fail");
|
|
142 |
failButton.setActionCommand("Fail");
|
|
143 |
failButton.addActionListener(new ActionListener() {
|
|
144 |
@Override
|
|
145 |
public void actionPerformed(ActionEvent e) {
|
|
146 |
testResult = false;
|
|
147 |
mainFrame.dispose();
|
|
148 |
latch.countDown();
|
|
149 |
}
|
|
150 |
});
|
|
151 |
gbc.gridx = 0;
|
|
152 |
gbc.gridy = 0;
|
|
153 |
resultButtonPanel.add(passButton, gbc);
|
|
154 |
gbc.gridx = 1;
|
|
155 |
gbc.gridy = 0;
|
|
156 |
resultButtonPanel.add(failButton, gbc);
|
|
157 |
|
|
158 |
gbc.gridx = 0;
|
|
159 |
gbc.gridy = 2;
|
|
160 |
mainControlPanel.add(resultButtonPanel, gbc);
|
|
161 |
|
|
162 |
mainFrame.add(mainControlPanel);
|
|
163 |
mainFrame.pack();
|
|
164 |
mainFrame.setVisible(true);
|
|
165 |
}
|
|
166 |
});
|
|
167 |
|
|
168 |
}
|
|
169 |
}
|
|
170 |
|