1 /* |
|
2 * Copyright 2008-2009 Sun Microsystems, Inc. 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. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 /* |
|
27 * @test %I% %E% |
|
28 * @bug 6655001 6670649 6687141 |
|
29 * @summary Tests that hw acceleration doesn't affect translucent/shaped windows |
|
30 * @author Dmitri.Trembovetski@sun.com: area=Graphics |
|
31 * @compile -XDignore.symbol.file=true TranslucentShapedFrameTest.java |
|
32 * @compile -XDignore.symbol.file=true TSFrame.java |
|
33 * @run main/manual/othervm TranslucentShapedFrameTest |
|
34 * @run main/manual/othervm -Dsun.java2d.noddraw=true TranslucentShapedFrameTest |
|
35 * @run main/manual/othervm -Dsun.java2d.opengl=True TranslucentShapedFrameTest |
|
36 */ |
|
37 import com.sun.awt.AWTUtilities; |
|
38 import static com.sun.awt.AWTUtilities.Translucency.*; |
|
39 import java.awt.Frame; |
|
40 import java.awt.GraphicsConfiguration; |
|
41 import java.awt.GraphicsDevice; |
|
42 import java.awt.GraphicsEnvironment; |
|
43 import java.awt.Shape; |
|
44 import java.awt.geom.Ellipse2D; |
|
45 import java.util.concurrent.CountDownLatch; |
|
46 import javax.swing.JSlider; |
|
47 import javax.swing.SwingUtilities; |
|
48 import javax.swing.UIManager; |
|
49 import javax.swing.UnsupportedLookAndFeelException; |
|
50 |
|
51 public class TranslucentShapedFrameTest extends javax.swing.JFrame { |
|
52 Frame testFrame; |
|
53 static CountDownLatch done; |
|
54 static volatile boolean failed = false; |
|
55 GraphicsConfiguration gcToUse = null; |
|
56 |
|
57 /** |
|
58 * Creates new form TranslucentShapedFrameTest |
|
59 */ |
|
60 public TranslucentShapedFrameTest() { |
|
61 // not necessary, but we just look nicer |
|
62 try { |
|
63 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
|
64 } catch (Exception ex) {} |
|
65 |
|
66 initComponents(); |
|
67 checkEffects(); |
|
68 |
|
69 SwingUtilities.updateComponentTreeUI(this); |
|
70 } |
|
71 |
|
72 /** This method is called from within the constructor to |
|
73 * initialize the form. |
|
74 * WARNING: Do NOT modify this code. The content of this method is |
|
75 * always regenerated by the Form Editor. |
|
76 */ |
|
77 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents |
|
78 private void initComponents() { |
|
79 createDisposeGrp = new javax.swing.ButtonGroup(); |
|
80 jLabel1 = new javax.swing.JLabel(); |
|
81 transparencySld = new javax.swing.JSlider(); |
|
82 shapedCb = new javax.swing.JCheckBox(); |
|
83 nonOpaqueChb = new javax.swing.JCheckBox(); |
|
84 jScrollPane1 = new javax.swing.JScrollPane(); |
|
85 jTextArea1 = new javax.swing.JTextArea(); |
|
86 jLabel2 = new javax.swing.JLabel(); |
|
87 passedBtn = new javax.swing.JButton(); |
|
88 failedBtn = new javax.swing.JButton(); |
|
89 createFrameBtn = new javax.swing.JToggleButton(); |
|
90 disposeFrameBtn = new javax.swing.JToggleButton(); |
|
91 useSwingCb = new javax.swing.JCheckBox(); |
|
92 |
|
93 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
|
94 setTitle("TranslucentShapedFrameTest"); |
|
95 jLabel1.setText("Frame Opacity:"); |
|
96 |
|
97 transparencySld.setMajorTickSpacing(10); |
|
98 transparencySld.setMinorTickSpacing(5); |
|
99 transparencySld.setPaintLabels(true); |
|
100 transparencySld.setPaintTicks(true); |
|
101 transparencySld.setValue(100); |
|
102 transparencySld.addChangeListener(new javax.swing.event.ChangeListener() { |
|
103 public void stateChanged(javax.swing.event.ChangeEvent evt) { |
|
104 transparencySldStateChanged(evt); |
|
105 } |
|
106 }); |
|
107 |
|
108 shapedCb.setText("Shaped Frame"); |
|
109 shapedCb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
110 shapedCb.setMargin(new java.awt.Insets(0, 0, 0, 0)); |
|
111 shapedCb.addActionListener(new java.awt.event.ActionListener() { |
|
112 public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
113 shapedCbActionPerformed(evt); |
|
114 } |
|
115 }); |
|
116 |
|
117 nonOpaqueChb.setText("Non Opaque Frame"); |
|
118 nonOpaqueChb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
119 nonOpaqueChb.setMargin(new java.awt.Insets(0, 0, 0, 0)); |
|
120 nonOpaqueChb.addActionListener(new java.awt.event.ActionListener() { |
|
121 public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
122 nonOpaqueChbActionPerformed(evt); |
|
123 } |
|
124 }); |
|
125 |
|
126 jTextArea1.setColumns(20); |
|
127 jTextArea1.setRows(5); |
|
128 jTextArea1.setText("Create translucent and/or shaped, or\nnon-opaque frame. Make sure it behaves\ncorrectly (no artifacts left on the screen\nwhen dragging - if dragging is possible).\nClick \"Passed\" if the test behaves correctly,\n\"Falied\" otherwise."); |
|
129 jScrollPane1.setViewportView(jTextArea1); |
|
130 |
|
131 jLabel2.setText("Instructions:"); |
|
132 |
|
133 passedBtn.setBackground(new java.awt.Color(129, 255, 100)); |
|
134 passedBtn.setText("Passed"); |
|
135 passedBtn.addActionListener(new java.awt.event.ActionListener() { |
|
136 public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
137 passedBtnActionPerformed(evt); |
|
138 } |
|
139 }); |
|
140 |
|
141 failedBtn.setBackground(java.awt.Color.red); |
|
142 failedBtn.setText("Failed"); |
|
143 failedBtn.addActionListener(new java.awt.event.ActionListener() { |
|
144 public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
145 failedBtnActionPerformed(evt); |
|
146 } |
|
147 }); |
|
148 |
|
149 createDisposeGrp.add(createFrameBtn); |
|
150 createFrameBtn.setText("Create Frame"); |
|
151 createFrameBtn.addActionListener(new java.awt.event.ActionListener() { |
|
152 public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
153 createFrameBtnActionPerformed(evt); |
|
154 } |
|
155 }); |
|
156 |
|
157 createDisposeGrp.add(disposeFrameBtn); |
|
158 disposeFrameBtn.setSelected(true); |
|
159 disposeFrameBtn.setText("Dispose Frame"); |
|
160 disposeFrameBtn.addActionListener(new java.awt.event.ActionListener() { |
|
161 public void actionPerformed(java.awt.event.ActionEvent evt) { |
|
162 disposeFrameBtnActionPerformed(evt); |
|
163 } |
|
164 }); |
|
165 |
|
166 useSwingCb.setText("Use JFrame"); |
|
167 useSwingCb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
168 useSwingCb.setMargin(new java.awt.Insets(0, 0, 0, 0)); |
|
169 |
|
170 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
|
171 getContentPane().setLayout(layout); |
|
172 layout.setHorizontalGroup( |
|
173 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|
174 .addGroup(layout.createSequentialGroup() |
|
175 .addContainerGap() |
|
176 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|
177 .addGroup(layout.createSequentialGroup() |
|
178 .addComponent(transparencySld, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE) |
|
179 .addContainerGap()) |
|
180 .addComponent(jLabel1) |
|
181 .addGroup(layout.createSequentialGroup() |
|
182 .addComponent(shapedCb) |
|
183 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
184 .addComponent(nonOpaqueChb) |
|
185 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
186 .addComponent(useSwingCb) |
|
187 .addContainerGap(102, Short.MAX_VALUE)) |
|
188 .addGroup(layout.createSequentialGroup() |
|
189 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|
190 .addGroup(layout.createSequentialGroup() |
|
191 .addComponent(jLabel2) |
|
192 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 314, javax.swing.GroupLayout.PREFERRED_SIZE)) |
|
193 .addGroup(layout.createSequentialGroup() |
|
194 .addComponent(passedBtn) |
|
195 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
196 .addComponent(failedBtn) |
|
197 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 241, javax.swing.GroupLayout.PREFERRED_SIZE)) |
|
198 .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE) |
|
199 .addGroup(layout.createSequentialGroup() |
|
200 .addComponent(createFrameBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE) |
|
201 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
202 .addComponent(disposeFrameBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE))) |
|
203 .addContainerGap()))) |
|
204 ); |
|
205 layout.setVerticalGroup( |
|
206 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|
207 .addGroup(layout.createSequentialGroup() |
|
208 .addContainerGap() |
|
209 .addComponent(jLabel1) |
|
210 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
211 .addComponent(transparencySld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
|
212 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
213 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
|
214 .addComponent(shapedCb) |
|
215 .addComponent(nonOpaqueChb) |
|
216 .addComponent(useSwingCb)) |
|
217 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
218 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
|
219 .addComponent(disposeFrameBtn) |
|
220 .addComponent(createFrameBtn)) |
|
221 .addGap(17, 17, 17) |
|
222 .addComponent(jLabel2) |
|
223 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
224 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE) |
|
225 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|
226 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
|
227 .addComponent(passedBtn) |
|
228 .addComponent(failedBtn)) |
|
229 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) |
|
230 ); |
|
231 pack(); |
|
232 }// </editor-fold>//GEN-END:initComponents |
|
233 |
|
234 private void nonOpaqueChbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nonOpaqueChbActionPerformed |
|
235 if (testFrame != null) { |
|
236 // REMIND: this path in the test doesn't work well (test bug) |
|
237 // AWTUtilities.setWindowOpaque(testFrame, !nonOpaqueChb.isSelected()); |
|
238 } |
|
239 }//GEN-LAST:event_nonOpaqueChbActionPerformed |
|
240 |
|
241 private void shapedCbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shapedCbActionPerformed |
|
242 if (testFrame != null) { |
|
243 Shape s = null; |
|
244 if (shapedCb.isSelected()) { |
|
245 s = new Ellipse2D.Double(0, 0, |
|
246 testFrame.getWidth(), |
|
247 testFrame.getHeight()); |
|
248 } |
|
249 AWTUtilities.setWindowShape(testFrame, s); |
|
250 } |
|
251 }//GEN-LAST:event_shapedCbActionPerformed |
|
252 |
|
253 private void transparencySldStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_transparencySldStateChanged |
|
254 JSlider source = (JSlider)evt.getSource(); |
|
255 int transl = transparencySld.getValue(); |
|
256 if (testFrame != null) { |
|
257 AWTUtilities.setWindowOpacity(testFrame, (float)transl/100f); |
|
258 } |
|
259 }//GEN-LAST:event_transparencySldStateChanged |
|
260 |
|
261 private void failedBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_failedBtnActionPerformed |
|
262 disposeFrameBtnActionPerformed(evt); |
|
263 dispose(); |
|
264 failed = true; |
|
265 done.countDown(); |
|
266 }//GEN-LAST:event_failedBtnActionPerformed |
|
267 |
|
268 private void disposeFrameBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disposeFrameBtnActionPerformed |
|
269 TSFrame.stopThreads(); |
|
270 if (testFrame != null) { |
|
271 testFrame.dispose(); |
|
272 testFrame = null; |
|
273 } |
|
274 }//GEN-LAST:event_disposeFrameBtnActionPerformed |
|
275 |
|
276 private void createFrameBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createFrameBtnActionPerformed |
|
277 disposeFrameBtnActionPerformed(evt); |
|
278 int transl = transparencySld.getValue(); |
|
279 testFrame = TSFrame.createGui(gcToUse, |
|
280 useSwingCb.isSelected(), shapedCb.isSelected(), |
|
281 (transl < 100), nonOpaqueChb.isSelected(), |
|
282 (float)transl/100f); |
|
283 }//GEN-LAST:event_createFrameBtnActionPerformed |
|
284 |
|
285 private void passedBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passedBtnActionPerformed |
|
286 disposeFrameBtnActionPerformed(evt); |
|
287 dispose(); |
|
288 done.countDown(); |
|
289 }//GEN-LAST:event_passedBtnActionPerformed |
|
290 |
|
291 /** |
|
292 * @param args the command line arguments |
|
293 */ |
|
294 public static void main(String args[]) { |
|
295 done = new CountDownLatch(1); |
|
296 java.awt.EventQueue.invokeLater(new Runnable() { |
|
297 public void run() { |
|
298 new TranslucentShapedFrameTest().setVisible(true); |
|
299 } |
|
300 }); |
|
301 try { |
|
302 done.await(); |
|
303 } catch (InterruptedException ex) {} |
|
304 if (failed) { |
|
305 throw new RuntimeException("Test FAILED"); |
|
306 } |
|
307 System.out.println("Test PASSED"); |
|
308 } |
|
309 |
|
310 private void checkEffects() { |
|
311 if (!AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSPARENT)) { |
|
312 shapedCb.setEnabled(false); |
|
313 } |
|
314 |
|
315 if (!AWTUtilities.isTranslucencySupported(TRANSLUCENT)) { |
|
316 transparencySld.setEnabled(false); |
|
317 } |
|
318 |
|
319 GraphicsConfiguration gc = null; |
|
320 if (AWTUtilities.isTranslucencySupported(PERPIXEL_TRANSLUCENT)) { |
|
321 gc = findGraphicsConfig(); |
|
322 if (gc == null) { |
|
323 nonOpaqueChb.setEnabled(false); |
|
324 } |
|
325 } |
|
326 |
|
327 gcToUse = gc; |
|
328 } |
|
329 |
|
330 private GraphicsConfiguration findGraphicsConfig() { |
|
331 GraphicsDevice gd = |
|
332 GraphicsEnvironment.getLocalGraphicsEnvironment(). |
|
333 getDefaultScreenDevice(); |
|
334 GraphicsConfiguration gcs[] = gd.getConfigurations(); |
|
335 for (GraphicsConfiguration gc : gcs) { |
|
336 if (AWTUtilities.isTranslucencyCapable(gc)) { |
|
337 return gc; |
|
338 } |
|
339 } |
|
340 return null; |
|
341 } |
|
342 |
|
343 // Variables declaration - do not modify//GEN-BEGIN:variables |
|
344 private javax.swing.ButtonGroup createDisposeGrp; |
|
345 private javax.swing.JToggleButton createFrameBtn; |
|
346 private javax.swing.JToggleButton disposeFrameBtn; |
|
347 private javax.swing.JButton failedBtn; |
|
348 private javax.swing.JLabel jLabel1; |
|
349 private javax.swing.JLabel jLabel2; |
|
350 private javax.swing.JScrollPane jScrollPane1; |
|
351 private javax.swing.JTextArea jTextArea1; |
|
352 private javax.swing.JCheckBox nonOpaqueChb; |
|
353 private javax.swing.JButton passedBtn; |
|
354 private javax.swing.JCheckBox shapedCb; |
|
355 private javax.swing.JSlider transparencySld; |
|
356 private javax.swing.JCheckBox useSwingCb; |
|
357 // End of variables declaration//GEN-END:variables |
|
358 |
|
359 } |
|