8369251: Opensource few tests

Reviewed-by: honkar
This commit is contained in:
Prasanta Sadhukhan 2025-10-16 02:02:16 +00:00
parent a7a3a660e3
commit 4ed364033d
8 changed files with 1102 additions and 0 deletions

View File

@ -0,0 +1,122 @@
/*
* Copyright (c) 2006, 2025, 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
* @bug 6405689
* @key headful
* @summary Reg: Painting is not happening properly,
* when Choice scrollbar gets disappeared after selected item
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual PaintArtefacts
*/
import java.awt.Button;
import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class PaintArtefacts {
static boolean removeItems = true;
private static final String INSTRUCTIONS = """
The problem is seen on XToolkit only.
Open the choice and press down or up key several times
until the scrollbar gets disappeared.
At that moment you may see a painting artefacts on dropdown menu
If you see them, press Fail.
If you don't see them press Add/Remove switch button and
again open the choice and press Up/Down key several times
until Scrollbar gets appeared back.
If you still don't see any painting artefacts press Pass.
""";
private static Frame init() {
Frame frame = new Frame("Painting Frame");
Button b = new Button ("Add/Remove switch");
final Choice ch = new Choice();
ch.add("Praveen");
ch.add("Mohan");
ch.add("Rakesh");
ch.add("Menon");
ch.add("Girish");
ch.add("Ramachandran");
ch.add("Elancheran");
ch.add("Subramanian");
ch.add("Raju");
ch.add("Pallath");
ch.add("Mayank");
ch.add("Joshi");
ch.add("Sundar");
ch.add("Srinivas");
ch.add("Mandalika");
ch.add("Suresh");
ch.add("Chandar");
ch.select(1);
frame.setLayout(new FlowLayout());
frame.add(ch);
frame.add(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
PassFailJFrame.log(ae.toString());
PassFailJFrame.log("selected index = " + ch.getSelectedIndex());
removeItems = !removeItems;
}
});
ch.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ie) {
PassFailJFrame.log(ie.toString());
PassFailJFrame.log("selected index = " + ch.getSelectedIndex());
if (removeItems) {
PassFailJFrame.log("REMOVE : " + ch.getSelectedIndex());
ch.remove(ch.getSelectedIndex());
} else {
PassFailJFrame.log("ADD : "+ch.getSelectedIndex() + "/" + "new item");
ch.add("new item");
}
}
});
frame.setSize(200, 200);
for (int i = 0; i < 5; i++){
ch.remove(ch.getSelectedIndex());
}
return frame;
}
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.columns(45)
.testUI(PaintArtefacts::init)
.logArea()
.build()
.awaitAndCheck();
}
}

View File

@ -0,0 +1,146 @@
/*
* Copyright (c) 2005, 2025, 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
* @bug 6318746
* @key headful
* @summary REG: File Selection is failing for every second selection made in the FileDlg drop-down, XToolkit
*/
import java.awt.Choice;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class SelectBetweenPressRelease {
static Frame frame;
static Choice ch;
static Robot r;
static volatile Point loc;
static volatile int selectedIndex;
public static void main(final String[] args) throws Exception {
r = new Robot();
try {
EventQueue.invokeAndWait(() -> init());
r.waitForIdle();
r.delay(1000);
test();
} finally {
EventQueue.invokeAndWait(() -> frame.dispose());
}
}
private static void init() {
frame = new Frame("SelectBetweenPressRelease");
ch = new Choice();
ch.add("0");
ch.add("1");
frame.add(ch);
frame.setLayout (new FlowLayout ());
addListener();
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.validate();
}
private static void test() throws Exception {
EventQueue.invokeAndWait(() -> ch.select(0));
EventQueue.invokeAndWait(() -> {
loc = ch.getLocationOnScreen();
});
r.delay(1000);
r.waitForIdle();
r.mouseMove(loc.x+ch.getWidth()/2, loc.y+ch.getHeight()/2);
r.delay(10);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
r.delay(100);
// This code leads to the bug
EventQueue.invokeAndWait(() -> ch.select(1));
r.delay(100);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
r.delay(1000);
r.waitForIdle();
// 'selected' variable wich stored in the peer still equals 0
// if the bug is reproducible
// so the next ISC to the first item by mouse will be ignored
// try to hit the first item
if (System.getProperty("os.name").startsWith("Mac")) {
r.mouseMove(loc.x + ch.getWidth() / 2, loc.y + ch.getHeight() / 2);
} else {
r.mouseMove(loc.x + ch.getWidth() / 2,
loc.y + ch.getHeight() * 3 / 2);
}
r.delay(10);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
r.delay(100);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
r.delay(1000);
r.waitForIdle();
EventQueue.invokeAndWait(() -> {
selectedIndex = ch.getSelectedIndex();
});
if (selectedIndex != 0){
throw new RuntimeException("Test failed. ch.getSelectedIndex() = "+selectedIndex);
}
}
// just for logging
private static void addListener(){
frame.addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent me){
System.out.println(me);
}
public void mouseReleased(MouseEvent me){
System.out.println(me);
}
});
ch.addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent me){
System.out.println(me);
}
public void mouseReleased(MouseEvent me){
System.out.println(me);
}
});
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2004, 2025, 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
* @bug 5041225
* @key headful
* @summary Tests that we can set a display mode with unknown refresh rate
* if corresponding system display mode (with equal w/h/d) is available.
* @run main DisplayModeNoRefreshTest
*/
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
public class DisplayModeNoRefreshTest extends Frame {
private static DisplayModeNoRefreshTest fs;
private static final GraphicsDevice gd =
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
private static final DisplayMode origMode = gd.getDisplayMode();
public DisplayModeNoRefreshTest() {
super("DisplayModeNoRefreshTest");
if (!gd.isFullScreenSupported()) {
System.out.println("Full Screen is not supported, test considered passed.");
return;
}
setBackground(Color.green);
gd.setFullScreenWindow(this);
DisplayMode dlMode = getNoRefreshDisplayMode(gd.getDisplayModes());
if (dlMode != null) {
System.out.println("Selected Display Mode: " +
" Width " + dlMode.getWidth() +
" Height " + dlMode.getHeight() +
" BitDepth " + dlMode.getBitDepth() +
" Refresh Rate " + dlMode.getRefreshRate());
try {
gd.setDisplayMode(dlMode);
} catch (IllegalArgumentException ex) {
throw new RuntimeException("Test Failed due to IAE", ex);
}
} else {
System.out.println("No suitable display mode available, test considered passed.");
return;
}
try { Thread.sleep(2000); } catch (InterruptedException e) {}
System.out.println("Test Passed.");
}
public DisplayMode getNoRefreshDisplayMode(DisplayMode dm[]) {
DisplayMode mode = new DisplayMode(640, 480, 32, DisplayMode.REFRESH_RATE_UNKNOWN);
int i = 0;
for (i = 0; i < dm.length; i++) {
if (mode.getWidth() == dm[i].getWidth()
&& mode.getHeight() == dm[i].getHeight()
&& mode.getBitDepth() == dm[i].getBitDepth()) {
return mode;
}
}
if (dm.length > 0) {
return
new DisplayMode(dm[0].getWidth(), dm[0].getHeight(),
dm[0].getBitDepth(),
DisplayMode.REFRESH_RATE_UNKNOWN);
}
return null;
}
public static void main(String[] args) throws Exception {
try {
EventQueue.invokeAndWait(() -> {
System.setProperty("sun.java2d.noddraw", "true");
fs = new DisplayModeNoRefreshTest();
});
} finally {
gd.setDisplayMode(origMode);
EventQueue.invokeAndWait(() -> {
if (fs != null) {
fs.dispose();
}
});
}
}
}

View File

@ -0,0 +1,142 @@
/*
* Copyright (c) 2006, 2025, 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
* @bug 6444688
* @key printer
* @summary Print an image with an IndexedColorModel with transparent pixel.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual BitmaskImage
*/
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.IndexColorModel;
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import static java.awt.print.Printable.NO_SUCH_PAGE;
import static java.awt.print.Printable.PAGE_EXISTS;
public class BitmaskImage implements Printable, ActionListener {
static int sz = 1000;
BufferedImage bi;
public BitmaskImage() {
int i = 0;
int[] cmap = new int[256];
for (int r = 0; r < 256; r += 51) {
for (int g = 0; g < 256; g += 51) {
for (int b = 0; b < 256; b += 51) {
cmap[i++] = (0xff << 24) | (r << 16) | (g << 8) | b;
}
}
}
IndexColorModel icm = new
IndexColorModel(8, 256, cmap, 0, true, 253, DataBuffer.TYPE_BYTE);
bi = new BufferedImage(sz, sz, BufferedImage.TYPE_BYTE_INDEXED, icm);
Graphics g = bi.getGraphics();
Graphics2D g2d = (Graphics2D)g;
g.setColor(Color.white);
g.fillRect(0, 0, sz, sz);
g.setColor(Color.black);
int off = sz / 20;
int wh = sz / 10;
for (int x = off; x < sz; x += wh * 2) {
for (int y = off; y < sz; y += wh * 2) {
g.fillRect(x, y, wh, wh);
}
}
}
public int print(Graphics g, PageFormat pf, int page) throws
PrinterException {
if (page > 0) { /* We have only one page, and 'page' is zero-based */
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)g;
AffineTransform tx = g2d.getTransform();
double sx = tx.getScaleX();
double sy = tx.getScaleY();
g2d.translate(pf.getImageableX(), pf.getImageableY());
g2d.scale(1/sx, 1/sx);
g.drawImage(bi, 10, 10, null);
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
} catch (PrinterException ex) {
/* The job did not successfully complete */
}
}
System.out.println("done");
}
static String INSTRUCTIONS = """
Press the "Print Simple ICM Image" button and if a printer is available,
choose one in the dialog and click OK to start printing.
This test will print an image which contains a grid of black squares.
If it prints so, press Pass otherwise press Fail.""";
public static Frame initTest() {
Frame f = new Frame("Image Printer");
Button printButton = new Button("Print Simple ICM image...");
printButton.addActionListener(new BitmaskImage());
f.add(printButton);
f.pack();
return f;
}
public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.testUI(BitmaskImage::initTest)
.columns(35)
.build()
.awaitAndCheck();
}
}

View File

@ -0,0 +1,186 @@
/*
* Copyright (c) 2006, 2025, 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
* @bug 6436437
* @requires (os.family == "windows")
* @summary Test setIconImages() for client-decorated JFrame
* @library ../../regtesthelpers
* @run main/manual ClientDecoratedIconTest
*/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JTextArea;
public class ClientDecoratedIconTest extends SwingTestHelper implements ActionListener {
JButton passed;
JButton failed;
java.util.List<Image> icons1;
java.util.List<Image> icons2;
IconFrame frame1;
IconFrame frame2;
Object lock = new Object();
boolean done = false;
protected String getInstructions() {
StringBuilder instructionsStr = new StringBuilder();
instructionsStr.append("This tests the functionality of the setIconImages() API\n");
instructionsStr.append("You will see two JFrames with custom icons1. Both JFrames should have the same icon: a colored box.\n");
instructionsStr.append("If either of the JFrames has the default, coffe-cup icon, the test fails.\n");
instructionsStr.append("If the JFrames DO NOT both have the same colored box as their icon, the test fails.\n");
instructionsStr.append("If both JFrames DO have the same colored box as their icon, then the test passes.");
return instructionsStr.toString();
}
protected Component createContentPane() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JTextArea instructions = new JTextArea(getInstructions());
panel.add(instructions, BorderLayout.CENTER);
passed = new JButton("Icons match (PASS)");
passed.addActionListener(this);
failed = new JButton("Icons don't match (FAIL)");
failed.addActionListener(this);
JPanel btnPanel = new JPanel();
btnPanel.setLayout(new FlowLayout());
btnPanel.add(passed);
btnPanel.add(failed);
panel.add(btnPanel, BorderLayout.SOUTH);
return panel;
}
public void onEDT10() throws IOException {
Image img1 = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
Graphics g = img1.getGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, 16, 16);
g.dispose();
Image img2 = new BufferedImage(24, 24, BufferedImage.TYPE_INT_ARGB);
g = img2.getGraphics();
g.setColor(Color.magenta);
g.fillRect(0, 0, 24, 24);
g.dispose();
Image img3 = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
g = img3.getGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, 32, 32);
g.dispose();
Image img4 = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
g = img4.getGraphics();
g.setColor(Color.blue);
g.fillRect(0, 0, 64, 64);
g.dispose();
icons1 = new ArrayList(4);
icons1.add(img1);
icons1.add(img2);
icons1.add(img3);
icons1.add(img4);
icons2 = new ArrayList(4);
icons2.add(img4);
icons2.add(img3);
icons2.add(img2);
icons2.add(img1);
frame1 = new IconFrame(icons1);
frame2 = new IconFrame(icons2);
frame1.setLocation(50, 250);
frame2.setLocation(275, 250);
frame1.setVisible(true);
frame2.setVisible(true);
}
public void onEDT20() {
waitForCondition(new Runnable() {
public void run() {
while (true) {
synchronized(lock) {
if (done) {
return;
}
}
try {
Thread.sleep(250);
}
catch(InterruptedException e) {}
}
}
});
System.out.println("done waiting");
}
public void onEDT30() {
// Needed so waitForCondition() has something to wait for :)
}
public void actionPerformed(ActionEvent e) {
System.out.println("actionPerformed()");
if (e.getSource() == passed) {
synchronized(lock) {
done = true;
}
}
if (e.getSource() == failed) {
throw new RuntimeException("Test Failed");
}
}
class IconFrame extends JFrame {
public IconFrame(java.util.List<Image> icons) {
super("Custom Icon Frame");
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
setIconImages(icons);
setSize(200, 200);
}
}
public static void main(String[] args) throws Throwable {
new ClientDecoratedIconTest().run(args);
System.out.println("end of main()");
}
}

View File

@ -0,0 +1,173 @@
/*
* Copyright (c) 2006, 2025, 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
* @bug 6436437
* @requires (os.family == "windows")
* @summary Test setIconImages() for client-decorated JDialog
* @library ../../regtesthelpers
* @run main/manual DialogIconTest
*/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Frame;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JTextArea;
public class DialogIconTest extends SwingTestHelper implements ActionListener {
JButton passed;
JButton failed;
java.util.List<Image> icons1;
IconDialog dialog1;
Object lock = new Object();
boolean done = false;
protected String getInstructions() {
StringBuilder instructionsStr = new StringBuilder();
instructionsStr.append("This tests the functionality of the setIconImages() API\n");
instructionsStr.append("You will see a client-decorated JDialog. The JDialog should have a custom icon: a solid-colored box.\n");
instructionsStr.append("If the JDialog has a colored box for an icon, then the test passes.\n");
instructionsStr.append("If the JDialog has the default icon, then the test fails.\n");
return instructionsStr.toString();
}
protected Component createContentPane() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JTextArea instructions = new JTextArea(getInstructions());
panel.add(instructions, BorderLayout.CENTER);
passed = new JButton("Solid-color Icon (PASS)");
passed.addActionListener(this);
failed = new JButton("Default Icon (FAIL)");
failed.addActionListener(this);
JPanel btnPanel = new JPanel();
btnPanel.setLayout(new FlowLayout());
btnPanel.add(passed);
btnPanel.add(failed);
panel.add(btnPanel, BorderLayout.SOUTH);
return panel;
}
public void onEDT10() throws IOException {
Image img1 = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
Graphics g = img1.getGraphics();
g.setColor(Color.green);
g.fillRect(0, 0, 16, 16);
g.dispose();
Image img2 = new BufferedImage(24, 24, BufferedImage.TYPE_INT_ARGB);
g = img2.getGraphics();
g.setColor(Color.magenta);
g.fillRect(0, 0, 24, 24);
g.dispose();
Image img3 = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
g = img3.getGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, 32, 32);
g.dispose();
Image img4 = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
g = img4.getGraphics();
g.setColor(Color.blue);
g.fillRect(0, 0, 64, 64);
g.dispose();
icons1 = new ArrayList(4);
icons1.add(img1);
icons1.add(img2);
icons1.add(img3);
icons1.add(img4);
dialog1 = new IconDialog(icons1);
dialog1.setLocation(50, 250);
dialog1.setVisible(true);
}
public void onEDT20() {
waitForCondition(new Runnable() {
public void run() {
while (true) {
synchronized(lock) {
if (done) {
return;
}
}
try {
Thread.sleep(250);
}
catch(InterruptedException e) {}
}
}
});
System.out.println("done waiting");
}
public void onEDT30() {
// Needed so waitForCondition() has something to wait for :)
}
public void actionPerformed(ActionEvent e) {
System.out.println("actionPerformed()");
if (e.getSource() == passed) {
synchronized(lock) {
done = true;
}
}
if (e.getSource() == failed) {
throw new RuntimeException("Test Failed");
}
}
class IconDialog extends JDialog {
public IconDialog(java.util.List<Image> icons) {
super((Frame)null, "Custom Icon Frame", false);
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
setIconImages(icons);
setSize(200, 200);
}
}
public static void main(String[] args) throws Throwable {
new DialogIconTest().run(args);
System.out.println("end of main()");
}
}

View File

@ -0,0 +1,71 @@
/*
* Copyright (c) 2006, 2025, 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
* @bug 6425606
* @requires (os.family == "windows")
* @summary Test JDialog's inheritance of icons set with JFrame.setIconImages()
* @library ../../regtesthelpers
* @run main/manual DialogInheritIcon
*/
import javax.swing.JDialog;
public class DialogInheritIcon extends ClientDecoratedIconTest {
JDialog dialog1;
JDialog dialog2;
/*
* @Override
*/
protected String getInstructions() {
StringBuilder instructionsStr = new StringBuilder();
instructionsStr.append("This tests the functionality of JDialog-inherited icons set using the setIconImages() API.\n");
instructionsStr.append("You will see two JFrames with custom icons, each with a child JDialog below it.\n");
instructionsStr.append("Both JDialogs should have the same icon: a colored box.\n");
instructionsStr.append("If either of the JDialogs has the default, coffe-cup icon, the test fails.\n");
instructionsStr.append("If the JDialogs DO NOT both have the same colored box as their icon, the test fails.\n");
instructionsStr.append("If both JDialogs DO have the same colored box as their icon, then the test passes.\n");
instructionsStr.append("Note: If the JDialog icons don't match the icons of the parent JFrame, that is OK.");
return instructionsStr.toString();
}
public void onEDT15() {
createDialogs();
dialog1.setVisible(true);
dialog2.setVisible(true);
}
protected void createDialogs() {
dialog1 = new JDialog(frame1, "Child JDialog 1", false);
dialog1.setBounds(frame1.getLocation().x, frame1.getLocation().y + frame1.getSize().height + 5, 200, 200);
dialog2 = new JDialog(frame2, "Child JDialog 2", false);
dialog2.setBounds(frame2.getLocation().x, frame2.getLocation().y + frame2.getSize().height + 5, 200, 200);
}
public static void main(String[] args) throws Throwable {
new DialogInheritIcon().run(args);
System.out.println("end of main()");
}
}

View File

@ -0,0 +1,147 @@
/*
* Copyright (c) 2003, 2025, 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
* @bug 4532590
* @summary Tests that selection is not painted when highlighter is set to null
* @run main bug4532590
*/
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.JTextComponent;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.SwingUtilities;
public class bug4532590 {
static final int SELECTION_START = 5;
static final int SELECTION_END = 10;
static final String TEXT = "Typein the missing word.";
static final Color TEXT_FG = Color.BLACK;
static final Color TEXT_BG = Color.WHITE;
static final Color SELECTION_FG = Color.RED;
static final Color SELECTION_BG = Color.YELLOW;
JTextComponent[] comps;
JTextPane pane;
JTextArea area, warea;
int selFG = SELECTION_FG.getRGB();
int selBG = SELECTION_BG.getRGB();
public bug4532590() throws BadLocationException {
// text pane
pane = new JTextPane();
pane.setContentType("text/plain");
// populate the pane
DefaultStyledDocument dsd = new DefaultStyledDocument();
dsd.insertString(0, "\n" + TEXT + "\n\n", new SimpleAttributeSet());
pane.setDocument(dsd);
// text area
area = new JTextArea();
area.setText("\n" + TEXT);
// wrapped text area
warea = new JTextArea();
warea.setText("\n" + TEXT);
comps = new JTextComponent[3];
comps[0] = pane;
comps[1] = area;
comps[2] = warea;
}
void initComp(JTextComponent comp) {
comp.setEditable(false);
comp.setForeground(TEXT_FG);
comp.setBackground(TEXT_BG);
comp.setSelectedTextColor(SELECTION_FG);
comp.setSelectionColor(SELECTION_BG);
comp.setHighlighter(null);
comp.setSize(comp.getPreferredSize());
comp.setSelectionStart(SELECTION_START);
comp.setSelectionEnd(SELECTION_END);
comp.getCaret().setSelectionVisible(true);
}
/**
* Paint given component on an offscreen buffer
*/
BufferedImage drawComp(JTextComponent comp) {
int w = comp.getWidth();
int h = comp.getHeight();
BufferedImage img =
new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
comp.paint(img.createGraphics());
return img;
}
void testComp(JTextComponent comp) {
initComp(comp);
BufferedImage img = drawComp(comp);
int w = img.getWidth(null);
int h = img.getHeight(null);
// scan the image
// there should be no SELECTION_FG or SELECTION_BG pixels
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
int rgb = img.getRGB(i, j);
if (rgb == selFG) {
throw new RuntimeException(
"Failed: selection foreground painted");
} else if (rgb == selBG) {
throw new RuntimeException(
"Failed: selection background painted");
}
}
}
}
void test() {
for (int i = 0; i < comps.length; i++) {
testComp(comps[i]);
}
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(() -> {
try {
new bug4532590().test();
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
});
}
}