2009-02-11 14:07:06 +00:00
|
|
|
/*
|
2021-04-15 11:32:07 +00:00
|
|
|
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
2009-02-11 14:07:06 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 22:58:33 +00:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2009-02-11 14:07:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-04-15 11:32:07 +00:00
|
|
|
* @test
|
|
|
|
* @key headful
|
2009-02-11 14:07:06 +00:00
|
|
|
* @bug 6683728
|
|
|
|
* @summary Tests that a JApplet in a translucent JFrame works properly
|
|
|
|
* @compile -XDignore.symbol.file=true TranslucentJAppletTest.java
|
2021-09-24 17:31:19 +00:00
|
|
|
* @run main/othervm -Dsun.java2d.uiScale=1 TranslucentJAppletTest
|
2009-02-11 14:07:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.image.*;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
|
|
public class TranslucentJAppletTest {
|
|
|
|
|
2013-05-28 12:38:41 +00:00
|
|
|
private static volatile GraphicsConfiguration graphicsConfig = null;
|
2009-02-11 14:07:06 +00:00
|
|
|
private static JFrame frame;
|
|
|
|
private static volatile boolean paintComponentCalled = false;
|
|
|
|
|
|
|
|
private static void initAndShowGUI() {
|
2013-05-28 12:38:41 +00:00
|
|
|
frame = new JFrame(graphicsConfig);
|
2009-02-11 14:07:06 +00:00
|
|
|
JApplet applet = new JApplet();
|
2011-04-08 13:04:35 +00:00
|
|
|
applet.setBackground(new Color(0, 0, 0, 0));
|
2009-02-11 14:07:06 +00:00
|
|
|
JPanel panel = new JPanel() {
|
|
|
|
protected void paintComponent(Graphics g) {
|
|
|
|
paintComponentCalled = true;
|
|
|
|
g.setColor(Color.RED);
|
|
|
|
g.fillOval(0, 0, getWidth(), getHeight());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
panel.setDoubleBuffered(false);
|
|
|
|
panel.setOpaque(false);
|
|
|
|
applet.add(panel);
|
|
|
|
frame.add(applet);
|
|
|
|
frame.setBounds(100, 100, 200, 200);
|
|
|
|
frame.setUndecorated(true);
|
2009-04-21 07:35:52 +00:00
|
|
|
frame.setBackground(new Color(0, 0, 0, 0));
|
2009-02-11 14:07:06 +00:00
|
|
|
frame.setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args)
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
|
2013-05-28 12:38:41 +00:00
|
|
|
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
|
|
for (GraphicsDevice gd : ge.getScreenDevices()) {
|
|
|
|
if (gd.isWindowTranslucencySupported(
|
|
|
|
GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT))
|
|
|
|
{
|
|
|
|
for (GraphicsConfiguration gc : gd.getConfigurations()) {
|
|
|
|
if (gc.isTranslucencyCapable()) {
|
|
|
|
graphicsConfig = gc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (graphicsConfig != null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (graphicsConfig == null) {
|
|
|
|
System.out.println("The system does not support translucency. Consider the test passed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-11 14:07:06 +00:00
|
|
|
Robot r = new Robot();
|
|
|
|
Color color1 = r.getPixelColor(100, 100); // (0, 0) in frame coordinates
|
|
|
|
|
|
|
|
SwingUtilities.invokeAndWait(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
initAndShowGUI();
|
|
|
|
}
|
|
|
|
});
|
2014-12-05 11:55:08 +00:00
|
|
|
r.waitForIdle();
|
2009-02-11 14:07:06 +00:00
|
|
|
|
|
|
|
if (!paintComponentCalled) {
|
|
|
|
throw new RuntimeException("Test FAILED: panel's paintComponent() method is not called");
|
|
|
|
}
|
2015-08-11 13:32:13 +00:00
|
|
|
Thread.sleep(1500);
|
2009-02-11 14:07:06 +00:00
|
|
|
|
|
|
|
Color newColor1 = r.getPixelColor(100, 100);
|
2015-08-11 13:32:13 +00:00
|
|
|
Color newColor2 = r.getPixelColor(200, 200);
|
2009-02-11 14:07:06 +00:00
|
|
|
|
|
|
|
// Frame must be transparent at (100, 100) in screen coords
|
|
|
|
if (!color1.equals(newColor1)) {
|
|
|
|
System.err.println("color1 = " + color1);
|
|
|
|
System.err.println("newColor1 = " + newColor1);
|
|
|
|
throw new RuntimeException("Test FAILED: frame pixel at (0, 0) is not transparent");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Frame must be RED at (200, 200) in screen coords
|
|
|
|
if (!newColor2.equals(Color.RED)) {
|
|
|
|
System.err.println("newColor2 = " + newColor2);
|
|
|
|
throw new RuntimeException("Test FAILED: frame pixel at (100, 100) is not red (transparent?)");
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("Test PASSED");
|
|
|
|
}
|
|
|
|
}
|