undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,264 @@
/*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* 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.
*
* 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.
*/
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsDevice.WindowTranslucency;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Ellipse2D;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class TSFrame {
static volatile boolean done = false;
static final boolean useSwing = System.getProperty("useswing") != null;
static final boolean useShape = System.getProperty("useshape") != null;
static final boolean useTransl = System.getProperty("usetransl") != null;
static final boolean useNonOpaque = System.getProperty("usenonop") != null;
static final Random rnd = new Random();
private static void render(Graphics g, int w, int h, boolean useNonOpaque) {
if (useNonOpaque) {
Graphics2D g2d = (Graphics2D)g;
GradientPaint p =
new GradientPaint(0.0f, 0.0f,
new Color(rnd.nextInt(0xffffff)),
w, h,
new Color(rnd.nextInt(0xff),
rnd.nextInt(0xff),
rnd.nextInt(0xff), 0),
true);
g2d.setPaint(p);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.fillOval(0, 0, w, h);
} else {
g.setColor(new Color(rnd.nextInt(0xffffff)));
g.fillRect(0, 0, w, h);
}
}
private static class MyCanvas extends Canvas {
@Override
public void paint(Graphics g) {
render(g, getWidth(), getHeight(), false);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 100);
}
}
private static class NonOpaqueJFrame extends JFrame {
NonOpaqueJFrame() {
super("NonOpaque Swing JFrame");
JPanel p = new JPanel() {
public void paintComponent(Graphics g) {
super.paintComponent(g);
render(g, getWidth(), getHeight(), true);
g.setColor(Color.red);
g.drawString("Non-Opaque Swing JFrame", 10, 15);
}
};
p.setDoubleBuffered(false);
p.setOpaque(false);
add(p);
setUndecorated(true);
}
}
private static class NonOpaqueFrame extends Frame {
NonOpaqueFrame() {
super("NonOpaque AWT Frame");
// uncomment to test with hw child
// setLayout(null);
// Component c = new Panel() {
// public void paint(Graphics g) {
// g.setColor(new Color(1.0f, 1.0f, 1.0f, 0.5f));
// g.fillRect(0, 0, getWidth(), getHeight());
// }
// };
// c.setSize(100, 100);
// c.setBackground(Color.red);
// c.setForeground(Color.red);
// add(c);
// c.setLocation(130, 130);
}
@Override
public void paint(Graphics g) {
render(g, getWidth(), getHeight(), true);
g.setColor(Color.red);
g.drawString("Non-Opaque AWT Frame", 10, 15);
}
}
private static class MyJPanel extends JPanel {
@Override
public void paintComponent(Graphics g) {
render(g, getWidth(), getHeight(), false);
}
}
public static Frame createGui(
final boolean useSwing,
final boolean useShape,
final boolean useTransl,
final boolean useNonOpaque,
final float factor)
{
Frame frame;
done = false;
if (useNonOpaque) {
if (useSwing) {
frame = new NonOpaqueJFrame();
} else {
frame = new NonOpaqueFrame();
}
animateComponent(frame);
} else if (useSwing) {
frame = new JFrame("Swing Frame");
JComponent p = new JButton("Swing!");
p.setPreferredSize(new Dimension(200, 100));
frame.add("North", p);
p = new MyJPanel();
animateComponent(p);
frame.add("Center", p);
} else {
frame = new Frame("AWT Frame") {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
}
};
frame.setLayout(new BorderLayout());
Canvas c = new MyCanvas();
frame.add("North", c);
animateComponent(c);
c = new MyCanvas();
frame.add("Center", c);
animateComponent(c);
c = new MyCanvas();
frame.add("South", c);
animateComponent(c);
}
final Frame finalFrame = frame;
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
finalFrame.dispose();
done = true;
}
});
frame.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
finalFrame.dispose();
done = true;
}
});
frame.setPreferredSize(new Dimension(800, 600));
frame.setUndecorated(true);
frame.setLocation(450, 10);
frame.pack();
GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
if (useShape) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
System.out.println("applying PERPIXEL_TRANSPARENT");
frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(),
frame.getHeight()/3));
frame.setTitle("PERPIXEL_TRANSPARENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
}
}
if (useTransl) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
System.out.println("applying TRANSLUCENT");
frame.setOpacity(factor);
frame.setTitle("TRANSLUCENT");
} else {
System.out.println("Passed: TRANSLUCENT unsupported");
}
}
if (useNonOpaque) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
System.out.println("applying PERPIXEL_TRANSLUCENT");
frame.setBackground(new Color(0, 0, 0, 0));
frame.setTitle("PERPIXEL_TRANSLUCENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
}
}
frame.setVisible(true);
return frame;
}
public static void stopThreads() {
done = true;
}
private static void animateComponent(final Component comp) {
Thread t = new Thread(new Runnable() {
public void run() {
do {
try {
Thread.sleep(50);
} catch (InterruptedException ex) {}
comp.repaint();
} while (!done);
}
});
t.start();
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TSFrame.createGui(useSwing,
useShape,
useTransl,
useNonOpaque,
0.7f);
}
});
}
}

View file

@ -0,0 +1,230 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Component class="javax.swing.ButtonGroup" name="createDisposeGrp">
</Component>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="TranslucentShapedFrameTest"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="transparencySld" pref="375" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="shapedCb" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="nonOpaqueChb" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="useSwingCb" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="102" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="314" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="passedBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="failedBtn" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="241" max="-2" attributes="0"/>
</Group>
<Component id="jScrollPane1" alignment="1" pref="375" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="createFrameBtn" min="-2" pref="187" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="disposeFrameBtn" min="-2" pref="182" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="transparencySld" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="shapedCb" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="nonOpaqueChb" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="useSwingCb" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="disposeFrameBtn" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="createFrameBtn" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="148" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="passedBtn" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="failedBtn" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Frame Opacity:"/>
</Properties>
</Component>
<Component class="javax.swing.JSlider" name="transparencySld">
<Properties>
<Property name="majorTickSpacing" type="int" value="10"/>
<Property name="minorTickSpacing" type="int" value="5"/>
<Property name="paintLabels" type="boolean" value="true"/>
<Property name="paintTicks" type="boolean" value="true"/>
<Property name="value" type="int" value="100"/>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="transparencySldStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="shapedCb">
<Properties>
<Property name="text" type="java.lang.String" value="Shaped Frame"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="shapedCbActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="nonOpaqueChb">
<Properties>
<Property name="text" type="java.lang.String" value="Non Opaque Frame"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="nonOpaqueChbActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTextArea" name="jTextArea1">
<Properties>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
<Property name="text" type="java.lang.String" value="Create translucent and/or shaped, or&#xa;non-opaque frame. Make sure it behaves&#xa;correctly (no artifacts left on the screen&#xa;when dragging - if dragging is possible).&#xa;Click &quot;Passed&quot; if the test behaves correctly,&#xa;&quot;Failed&quot; otherwise."/>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Instructions:"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="passedBtn">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="64" green="ff" red="81" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Passed"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="passedBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="failedBtn">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" id="red" palette="1" red="ff" type="palette"/>
</Property>
<Property name="text" type="java.lang.String" value="Failed"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="failedBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToggleButton" name="createFrameBtn">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="createDisposeGrp"/>
</Property>
<Property name="text" type="java.lang.String" value="Create Frame"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="createFrameBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToggleButton" name="disposeFrameBtn">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="createDisposeGrp"/>
</Property>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Dispose Frame"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="disposeFrameBtnActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="useSwingCb">
<Properties>
<Property name="text" type="java.lang.String" value="Use JFrame"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
</Border>
</Property>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[0, 0, 0, 0]"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>

View file

@ -0,0 +1,343 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* 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.
*
* 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.
*/
/*
* @test %I% %E%
* @bug 6655001 6670649 6687141 8198613
* @summary Tests that hw acceleration doesn't affect translucent/shaped windows
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @compile -XDignore.symbol.file=true TranslucentShapedFrameTest.java
* @compile -XDignore.symbol.file=true TSFrame.java
* @run main/manual/othervm TranslucentShapedFrameTest
* @run main/manual/othervm -Dsun.java2d.noddraw=true TranslucentShapedFrameTest
*/
import java.awt.Color;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsDevice.WindowTranslucency;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.util.concurrent.CountDownLatch;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class TranslucentShapedFrameTest extends javax.swing.JFrame {
Frame testFrame;
static CountDownLatch done;
static volatile boolean failed = false;
GraphicsConfiguration gcToUse = null;
/**
* Creates new form TranslucentShapedFrameTest
*/
public TranslucentShapedFrameTest() {
// not necessary, but we just look nicer
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {}
initComponents();
checkEffects();
SwingUtilities.updateComponentTreeUI(this);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
createDisposeGrp = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
transparencySld = new javax.swing.JSlider();
shapedCb = new javax.swing.JCheckBox();
nonOpaqueChb = new javax.swing.JCheckBox();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel2 = new javax.swing.JLabel();
passedBtn = new javax.swing.JButton();
failedBtn = new javax.swing.JButton();
createFrameBtn = new javax.swing.JToggleButton();
disposeFrameBtn = new javax.swing.JToggleButton();
useSwingCb = new javax.swing.JCheckBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("TranslucentShapedFrameTest");
jLabel1.setText("Frame Opacity:");
transparencySld.setMajorTickSpacing(10);
transparencySld.setMinorTickSpacing(5);
transparencySld.setPaintLabels(true);
transparencySld.setPaintTicks(true);
transparencySld.setValue(100);
transparencySld.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
transparencySldStateChanged(evt);
}
});
shapedCb.setText("Shaped Frame");
shapedCb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
shapedCb.setMargin(new java.awt.Insets(0, 0, 0, 0));
shapedCb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
shapedCbActionPerformed(evt);
}
});
nonOpaqueChb.setText("Non Opaque Frame");
nonOpaqueChb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
nonOpaqueChb.setMargin(new java.awt.Insets(0, 0, 0, 0));
nonOpaqueChb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nonOpaqueChbActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
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\"Failed\" otherwise.");
jScrollPane1.setViewportView(jTextArea1);
jLabel2.setText("Instructions:");
passedBtn.setBackground(new Color(129, 255, 100));
passedBtn.setText("Passed");
passedBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
passedBtnActionPerformed(evt);
}
});
failedBtn.setBackground(Color.red);
failedBtn.setText("Failed");
failedBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
failedBtnActionPerformed(evt);
}
});
createDisposeGrp.add(createFrameBtn);
createFrameBtn.setText("Create Frame");
createFrameBtn.setSelected(true);
createFrameBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
createFrameBtnActionPerformed(evt);
}
});
createDisposeGrp.add(disposeFrameBtn);
disposeFrameBtn.setEnabled(false);
disposeFrameBtn.setText("Dispose Frame");
disposeFrameBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
disposeFrameBtnActionPerformed(evt);
}
});
useSwingCb.setText("Use JFrame");
useSwingCb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
useSwingCb.setMargin(new java.awt.Insets(0, 0, 0, 0));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(transparencySld, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
.addContainerGap())
.addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
.addComponent(shapedCb)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nonOpaqueChb)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(useSwingCb)
.addContainerGap(102, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 314, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(passedBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(failedBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 241, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(createFrameBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(disposeFrameBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(transparencySld, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(shapedCb)
.addComponent(nonOpaqueChb)
.addComponent(useSwingCb))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(disposeFrameBtn)
.addComponent(createFrameBtn))
.addGap(17, 17, 17)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(passedBtn)
.addComponent(failedBtn))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void nonOpaqueChbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nonOpaqueChbActionPerformed
if (testFrame != null) {
// REMIND: this path in the test doesn't work well (test bug)
testFrame.setBackground(new Color(0, 0, 0, nonOpaqueChb.isSelected() ? 0 : 255));
}
}//GEN-LAST:event_nonOpaqueChbActionPerformed
private void shapedCbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shapedCbActionPerformed
if (testFrame != null) {
Shape s = null;
if (shapedCb.isSelected()) {
s = new Ellipse2D.Double(0, 0,
testFrame.getWidth(),
testFrame.getHeight());
}
testFrame.setShape(s);
}
}//GEN-LAST:event_shapedCbActionPerformed
private void transparencySldStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_transparencySldStateChanged
JSlider source = (JSlider)evt.getSource();
int transl = transparencySld.getValue();
if (testFrame != null) {
testFrame.setOpacity((float)transl/100f);
}
}//GEN-LAST:event_transparencySldStateChanged
private void failedBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_failedBtnActionPerformed
disposeFrameBtnActionPerformed(evt);
dispose();
failed = true;
done.countDown();
}//GEN-LAST:event_failedBtnActionPerformed
private void disposeFrameBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disposeFrameBtnActionPerformed
TSFrame.stopThreads();
if (testFrame != null) {
testFrame.dispose();
testFrame = null;
}
disposeFrameBtn.setEnabled(false);
createFrameBtn.setEnabled(true);
useSwingCb.setEnabled(true);
}//GEN-LAST:event_disposeFrameBtnActionPerformed
private void createFrameBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createFrameBtnActionPerformed
disposeFrameBtnActionPerformed(evt);
int transl = transparencySld.getValue();
testFrame = TSFrame.createGui(
useSwingCb.isSelected(), shapedCb.isSelected(),
(transl < 100), nonOpaqueChb.isSelected(),
(float)transl/100f);
createFrameBtn.setEnabled(false);
disposeFrameBtn.setEnabled(true);
useSwingCb.setEnabled(false);
}//GEN-LAST:event_createFrameBtnActionPerformed
private void passedBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passedBtnActionPerformed
disposeFrameBtnActionPerformed(evt);
dispose();
done.countDown();
}//GEN-LAST:event_passedBtnActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
done = new CountDownLatch(1);
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TranslucentShapedFrameTest().setVisible(true);
}
});
try {
done.await();
} catch (InterruptedException ex) {}
if (failed) {
throw new RuntimeException("Test FAILED");
}
System.out.println("Test PASSED");
}
private void checkEffects() {
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
if (!gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
shapedCb.setEnabled(false);
}
if (!gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
transparencySld.setEnabled(false);
}
if (!gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
nonOpaqueChb.setEnabled(false);
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup createDisposeGrp;
private javax.swing.JToggleButton createFrameBtn;
private javax.swing.JToggleButton disposeFrameBtn;
private javax.swing.JButton failedBtn;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JCheckBox nonOpaqueChb;
private javax.swing.JButton passedBtn;
private javax.swing.JCheckBox shapedCb;
private javax.swing.JSlider transparencySld;
private javax.swing.JCheckBox useSwingCb;
// End of variables declaration//GEN-END:variables
}