8289077: Add manual tests to open

Reviewed-by: azvegint
This commit is contained in:
Harshitha Onkar 2023-02-06 23:43:18 +00:00
parent 07fb4f9a0b
commit 787e16bb44
7 changed files with 945 additions and 0 deletions

View File

@ -0,0 +1,116 @@
/*
* Copyright (c) 2006, 2023, 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.Button;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
/*
* @test
* @bug 6435804
* @summary REGRESSION: NetBeans 5.0 icon no longer shows up when you alt-tab on XP
* @key headful
* @requires (os.family != "mac")
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual ALTTABIconBeingErased
*/
public class ALTTABIconBeingErased {
private static final String INSTRUCTIONS =
"This test verifies that the Frame's icon is not corrupted after showing\n"
+ "and disposing owned dialog\n"
+ "You would see a button in a Frame.\n"
+ "1) The frame should have icon with 2 black and 2 white squares.\n"
+ "2) Verify that icon appearing on ALT-TAB is also a\n"
+ "light icon.\n"
+ "3) Now open a child by pressing on \"Open Child\" button.\n"
+ "Child Dialog should appear. It should have the same icon as frame.\n"
+ "4) Now close the dialog by pressing Space or clicking on a button in it.\n"
+ "Dialog should be disposed now.\n"
+ "5) Verify that icon on ALT-TAB is the same as before";
private static Frame frame;
private static final int SIZE = 300;
private static void updateIconImage() {
BufferedImage image = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
Graphics gr = image.createGraphics();
gr.setColor(Color.WHITE);
gr.fillRect(0, 0, SIZE, SIZE);
gr.setColor(Color.BLACK);
gr.fillRect(0, 0, SIZE / 2, SIZE / 2);
gr.fillRect(SIZE / 2, SIZE / 2, SIZE, SIZE);
frame.setIconImage(image);
}
private static void createAndShowGUI(){
frame = new Frame();
Button setImageButton5 = new Button("Open Child");
updateIconImage();
setImageButton5.addActionListener(event -> {
try {
final Dialog d1 = new Dialog(frame, true);
d1.setSize(100, 100);
Button ok = new Button("OK");
ok.addActionListener(e -> {
d1.setVisible(false);
d1.dispose();
});
d1.add(ok);
d1.setLocation(frame.getX(), frame.getY() + 70);
d1.setVisible(true);
} catch (Exception e) {
throw new RuntimeException("Test failed because of" +
" exception" + e + ". Press Fail.");
}
});
frame.add(setImageButton5, BorderLayout.CENTER);
frame.setSize(200,65);
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);
frame.setVisible(true);
}
public static void main(String[] args) throws InterruptedException,
InvocationTargetException {
PassFailJFrame passFailJFrame = new PassFailJFrame("Large Icon " +
"Test Instructions", INSTRUCTIONS, 5, 12, 50);
SwingUtilities.invokeAndWait(ALTTABIconBeingErased::createAndShowGUI);
passFailJFrame.awaitAndCheck();
}
}

View File

@ -0,0 +1,209 @@
/*
* Copyright (c) 2006, 2023, 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.Color;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
import static jdk.test.lib.Platform.isWindows;
/*
* @test
* @bug 6415057
* @summary Tests if toplevel's icons are updated in runtime
* @key headful
* @requires (os.family == "windows")
* @modules java.desktop/sun.awt
* @library /java/awt/regtesthelpers /test/lib
* @build PassFailJFrame jdk.test.lib.Platform
* @run main/manual IconChangingTest
*/
public class IconChangingTest {
private static final int ICON_SIZE = 16;
private static final int MARGIN = 2;
private static final int STACK_SIZE = 4;
// Number of windows per stack
private static final int WIN_PER_STACK = 4;
private static int windowPosX = 0;
private static final int EXTRA_OFFSET = 50;
private static ImageIcon ii1;
private static ImageIcon ii2;
private static ImageIcon ji;
private static final Window[][] windowStack = new Window[STACK_SIZE][WIN_PER_STACK];
private static final JLabel[][] labels = new JLabel[STACK_SIZE][WIN_PER_STACK];
private static final boolean[][] isResizable = new boolean[][]{
{true, true, false, true}, //stack 1
{true, false, true, false}, //stack 2
{true, false, true, true}, //stack 3
{false, true, false, false} //stack 4
};
private static final String INSTRUCTIONS = """
The test is supposed to work on Windows.
It may not work on other platforms.
Icons and window decorations should change in windows
(frames & dialogs) every 3 seconds.
Notes:
* Icons might appear in grayscale.
* Default icon might be either Duke or Java Cup.
Press PASS if the icons match the labels
and are shown correctly, FAIL otherwise.
""";
public static void main(String[] args) throws Exception {
PassFailJFrame passFailJFrame = new PassFailJFrame("Icon Changing " +
"Test Instructions", INSTRUCTIONS, 5, 18, 40);
SwingUtilities.invokeAndWait(() -> {
try {
createAndShowGUI();
} catch (Exception e) {
throw new RuntimeException("Error while running the test", e);
}
});
passFailJFrame.awaitAndCheck();
}
private static void createAndShowGUI() throws InterruptedException,
InvocationTargetException {
PassFailJFrame.positionTestWindow(null,
PassFailJFrame.Position.TOP_LEFT_CORNER);
Rectangle bounds = PassFailJFrame.getInstructionFrameBounds();
windowPosX = bounds.x + bounds.width;
ii1 = new ImageIcon(generateIcon(Color.RED));
ii2 = new ImageIcon(generateIcon(Color.BLUE));
ji = new ImageIcon(IconChangingTest.class.getResource("java-icon16.png"));
// Creates STACK_SIZE different combinations of window stacks,
// each stack contains WIN_PER_STACK windows (frame/dialog).
for (int i = 0; i < STACK_SIZE; i++) {
for (int j = 0; j < WIN_PER_STACK; j++) {
createWindow(i, j);
}
}
Thread thread = new Thread(new Runnable() {
private final ImageIcon[][] icons = {
{null, ii1},
{ii2, null},
{ii1, ii2}
};
@Override
public void run() {
int index = 0;
while (true) {
try {
setIcons(icons[index][0], icons[index][1]);
Thread.sleep(4000);
if (++index >= icons.length) {
index = 0;
}
} catch (InterruptedException e) {
break;
}
}
}
private static void setIcons(final ImageIcon icon1, final ImageIcon icon2) {
Image i1 = (icon1 == null) ? null : icon1.getImage();
Image i2 = (icon2 == null) ? null : icon2.getImage();
ImageIcon li1 = (icon1 == null) ? ji : icon1;
ImageIcon li2 = (icon2 == null) ? li1 : icon2;
ImageIcon[][] iconList = new ImageIcon[][]{
{li1, li1, ((i2 == null && isWindows()) ? null : li2), li2},
{li1, (isWindows()) ? null : li1, li2, (isWindows()) ? null : li2},
{li1, (isWindows()) ? null : li1, li2, li2},
{li1, li1, (i2 == null && isWindows()) ? null : li2, (isWindows()) ? null : li2},
};
for (int i = 0; i < STACK_SIZE; i++) {
windowStack[i][0].setIconImage(i1);
windowStack[i][2].setIconImage(i2);
for (int j = 0; j < WIN_PER_STACK; j++) {
labels[i][j].setIcon(iconList[i][j]);
}
}
}
});
thread.start();
}
private static void createWindow(int i, int j) {
boolean isFrame = (i == 0 && j == 0) || (i == 1 && j == 0);
String title = (isFrame ? "Frame ": "Dialog ") + (i+1) + "." + (j+1);
windowStack[i][j] = isFrame
? createFrame(title, i, j)
: createDialog(title, i, j);
labels[i][j]= new JLabel(title);
windowStack[i][j].add(labels[i][j]);
windowStack[i][j].setBounds(windowPosX + (i * 200), (j * 100) + EXTRA_OFFSET,
200, 100);
windowStack[i][j].toFront();
windowStack[i][j].setVisible(true);
PassFailJFrame.addTestWindow(windowStack[i][j]);
}
private static Frame createFrame(String title, int i, int j) {
Frame frame = new Frame(title);
frame.setResizable(isResizable[i][j]);
return frame;
}
private static Dialog createDialog(String title, int i, int j) {
Dialog dialog = new Dialog((j == 0 ? null : windowStack[i][j-1]), title);
dialog.setResizable(isResizable[i][j]);
return dialog;
}
private static Image generateIcon(Color color) {
BufferedImage bImg = new BufferedImage(ICON_SIZE, ICON_SIZE, TYPE_INT_ARGB);
Graphics2D g2d = bImg.createGraphics();
g2d.setColor(color);
g2d.fillRect(MARGIN, MARGIN, ICON_SIZE - 2 * MARGIN, ICON_SIZE - 2 * MARGIN);
g2d.dispose();
return bImg;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1,280 @@
/*
* Copyright (c) 2005, 2023, 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.AlphaComposite;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Window;
import java.awt.image.BaseMultiResolutionImage;
import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
import static jdk.test.lib.Platform.isWindows;
/*
* @test
* @bug 6233560 6280303 6292933
* @summary Tests if toplevel's icons are shown correctly
* @key headful
* @requires (os.family == "windows")
* @library /java/awt/regtesthelpers /test/lib
* @build PassFailJFrame jdk.test.lib.Platform
* @run main/manual IconShowingTest
*/
public class IconShowingTest {
private static final int EXTRA_OFFSET = 50;
private static final String INSTRUCTIONS =
"Look at the icons shown on frames and dialogs, icons of minimized frames\n"
+ (isWindows() ? "are displayed in ALT+TAB window\n" : "") + "\n"+
"""
Alpha-channel (transparency) should be supported
by Windows and may not be supported by other platforms.
Notes:
* Icons might appear in grayscale.
* Default icon might be either Duke or Java Cup.
Press PASS if the icons match label description in windows
and are shown correctly, FAIL otherwise.
""";
public static void main(String[] args) throws Exception {
PassFailJFrame passFailJFrame = new PassFailJFrame("Icon Showing " +
"Test Instructions", INSTRUCTIONS, 5, 18, 48);
SwingUtilities.invokeAndWait(() -> {
try {
createAndShowGUI();
} catch (Exception e) {
throw new RuntimeException("Error while running the test", e);
}
});
passFailJFrame.awaitAndCheck();
}
public static void createAndShowGUI()
throws InterruptedException, InvocationTargetException {
Image i_16 = createIcon(16, 8, "16");
Image i_32 = createIcon(32, 14, "32");
Image i_48 = createIcon(48, 24, "48");
Image i_64 = createIcon(64, 30, "64");
ImageIcon ji_16 = new ImageIcon(IconShowingTest.class.getResource(
"java-icon16.png"));
Image[] images = new Image[] {i_16, i_32, i_48, i_64};
List<Image> imageList = Arrays.asList(images);
ImageIcon icon = new ImageIcon(new MRImage(images));
Frame f1 = new Frame("Frame 1");
f1.setIconImages(imageList);
f1.setLayout(new GridLayout(0, 1));
f1.add(new JLabel("Icon 16x16", new ImageIcon(i_16), JLabel.CENTER));
f1.add(new JLabel("Icon 32x32", new ImageIcon(i_32), JLabel.CENTER));
f1.add(new JLabel("Icon 48x48", new ImageIcon(i_48), JLabel.CENTER));
f1.add(new JLabel("Icon 64x64", new ImageIcon(i_64), JLabel.CENTER));
PassFailJFrame.positionTestWindow(null,
PassFailJFrame.Position.TOP_LEFT_CORNER);
Rectangle bounds = PassFailJFrame.getInstructionFrameBounds();
int windowPosX = bounds.x + bounds.width + 5;
f1.setBounds(windowPosX, EXTRA_OFFSET, 200, 300);
f1.setVisible(true);
f1.toFront();
PassFailJFrame.addTestWindow(f1);
int windowPosY = f1.getY() + f1.getHeight();
Dialog d11 = new Dialog(f1, "Dialog 1.1");
d11.setResizable(false);
addIconAndLabelToWindow(d11, windowPosX, windowPosY - EXTRA_OFFSET,
(isWindows() ? "No icon, non-resizable dialog"
: "Inherited icon, non-resizable dialog"),
(isWindows() ? null : icon));
Dialog d12 = new Dialog(d11, "Dialog 1.2");
addIconAndLabelToWindow(d12, windowPosX, windowPosY + EXTRA_OFFSET,
"Inherited icon, resizable dialog", icon);
Frame f2 = new Frame("Frame 2");
addIconAndLabelToWindow(f2, windowPosX + 200, 0,
"Default Icon", ji_16);
Dialog d21 = new Dialog(f2, "Dialog 2.1");
d21.setResizable(false);
addIconAndLabelToWindow(d21, windowPosX + 200, 100,
(isWindows() ? "No icon, non-resizable dialog"
: "Inherited default Icon, non-resizable dialog"),
(isWindows() ? null : ji_16));
Dialog d22 = new Dialog(f2, "Dialog 2.2");
addIconAndLabelToWindow(d22, windowPosX + 200, 200,
"Inherited default Icon, resizable dialog", ji_16);
Dialog d23 = new Dialog(f2, "Dialog 2.3");
d23.setIconImages(imageList);
d23.setResizable(false);
addIconAndLabelToWindow(d23, windowPosX + 200, 300,
"Modified Icon, non-resizable dialog", icon);
Dialog d24 = new Dialog(f2, "Dialog 2.4");
d24.setIconImages(imageList);
addIconAndLabelToWindow(d24, windowPosX + 200, 400,
"Modified Icon, resizable dialog", icon);
Dialog d31 = new Dialog((Frame)null, "Dialog 3.1");
addIconAndLabelToWindow(d31, windowPosX + 400, 100,
"Default icon, resizable dialog", ji_16);
Dialog d32 = new Dialog(d31, "Dialog 3.2");
d32.setResizable(false);
addIconAndLabelToWindow(d32, windowPosX + 400, 200,
(isWindows() ? "No icon, non-resizable dialog"
: "Default Icon, non-resizable dialog"),
(isWindows() ? null : ji_16));
Dialog d33 = new Dialog(d31, "Dialog 3.3");
d33.setIconImages(imageList);
d33.setResizable(false);
addIconAndLabelToWindow(d33, windowPosX + 400, 300,
"Modified icon, non-resizable dialog", icon);
Dialog d34 = new Dialog(d33, "Dialog 3.4");
d34.setResizable(false);
addIconAndLabelToWindow(d34, windowPosX + 400, 400,
(isWindows() ? "No icon, non-resizable dialog"
: "Inherited modified icon, non-resizable dialog"),
(isWindows() ? null : icon));
Dialog d41 = new Dialog((Frame) null, "Dialog 4.1");
d41.setResizable(false);
addIconAndLabelToWindow(d41, windowPosX + 600, 100,
"Default icon, non-resizable dialog", ji_16);
Dialog d42 = new Dialog(d41, "Dialog 4.2");
addIconAndLabelToWindow(d42, windowPosX + 600, 200,
"Inherited default icon, resizable dialog", ji_16);
Dialog d43 = new Dialog(d41, "Dialog 4.3");
d43.setIconImages(imageList);
addIconAndLabelToWindow(d43, windowPosX + 600, 300,
"Modified icon, resizable dialog", icon);
Dialog d44 = new Dialog(d43, "Dialog 4.4");
addIconAndLabelToWindow(d44, windowPosX + 600, 400,
"Inherited modified icon, resizable dialog", icon);
}
private static void addIconAndLabelToWindow(Window win, int x, int y,
String title, ImageIcon icon) {
win.setBounds(x, (y + EXTRA_OFFSET), 200, 100);
win.add(new JLabel(title, icon, JLabel.CENTER));
win.setVisible(true);
win.toFront();
PassFailJFrame.addTestWindow(win);
}
public static Image createIcon(int size, int fontSize, String value) {
BufferedImage bImg = new BufferedImage(size, size, TYPE_INT_ARGB);
Graphics2D g2d = bImg.createGraphics();
int half = size / 2;
for (int i = 0; i < half - 1; i += 2) {
g2d.setComposite(AlphaComposite.Src);
g2d.setColor(Color.RED);
g2d.fillRect(0, i, half, 1);
g2d.setComposite(AlphaComposite.Clear);
g2d.fillRect(0, i + 1, half, 1);
}
g2d.setComposite(AlphaComposite.Clear);
g2d.fillRect(half, 0, half, half);
g2d.setComposite(AlphaComposite.Src);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2d.setFont(new Font("Dialog", Font.PLAIN, fontSize));
g2d.setColor(Color.BLUE);
g2d.drawString(value, half - 1, half - 2);
int height = (half + 1) / 3;
// Green
GradientPaint greenGradient = new GradientPaint(0, half - 1, Color.GREEN,
size, half - 1, new Color(0, 255, 0, 0));
g2d.setPaint(greenGradient);
g2d.fillRect(0, half - 1, size, height);
// Blue
GradientPaint blueGradient = new GradientPaint(0, (half - 1) + height, Color.BLUE,
size, (half - 1) + height, new Color(0, 0, 255, 0));
g2d.setPaint(blueGradient);
g2d.fillRect(0, (half - 1) + height, size, height);
// Red
GradientPaint redGradient = new GradientPaint(0, (half - 1) + height * 2, Color.RED,
size, (half - 1) + height * 2, new Color(255, 0, 0, 0));
g2d.setPaint(redGradient);
g2d.fillRect(0, (half - 1) + height * 2, size, height);
g2d.dispose();
return bImg;
}
private static class MRImage extends BaseMultiResolutionImage {
public MRImage(Image... resolutionVariants) {
super(resolutionVariants);
}
@Override
public Image getResolutionVariant(double expectedSize, double unused) {
final int size = (int) Math.round(expectedSize / 16.0) * 16;
List<Image> imageList = getResolutionVariants();
for (int i = 0; i < imageList.size(); i++) {
if (size == imageList.get(i).getWidth(null)) {
return imageList.get(i);
} else if (imageList.get(i).getWidth(null) > size) {
return imageList.get(i > 0 ? i - 1 : i);
}
}
return imageList.get(0); //default/base image
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1,251 @@
/*
* Copyright (c) 2005, 2023, 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.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.image.IndexColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
/*
* @test
* @bug 4987171
* @key headful
* @summary GIF transparency in frame icons not work with Metacity/GNOME
* @requires (os.family != "mac")
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual IconTransparencyTest
*/
public class IconTransparencyTest {
private static final String INSTRUCTIONS = """
The icon of the frame and the resized icon in the label should be transparent.
Transparency can be verified by checking if the background color (pink)
is visible in and around icon within the JLabel.
Press continue to view next icon (6 total).
Icon might be presented as grayscale image.
For the 3rd icon in JLabel, the 2nd vertical slot is transparent, hence
the background color (pink) should be visible at the 2nd vertical slot.
For the 4th icon in JLabel, the 5th vertical slot is transparent, hence
the background color (pink) should be visible at the 5th vertical slot.
Press Pass or Fail at the end of test.
""";
static class TestLabel extends JLabel {
public void paint(Graphics g) {
Dimension d = getSize();
g.setColor(Color.PINK);
g.fillRect(0, 0, d.width, d.height);
Icon icon = getIcon();
if (icon != null) {
icon.paintIcon(this, g, 0, 0);
}
int iw = (icon != null) ? icon.getIconWidth() + 3 : 3;
if (d.width - iw > 0) {
g.setColor(Color.BLACK);
g.drawString(getText(), iw, 16);
}
}
}
static class TestFrame implements ActionListener {
static final int TEST_CNT = 6;
int currTest = 0;
static ImageIcon[] testIcon;
TestLabel label;
JButton button;
static JFrame frame;
final String[] testText = {
"1st Icon: Size 16x16, GIF",
"2nd Icon: Size 48x48, GIF",
"3rd Icon: Size 64x64, GIF",
"4th Icon: Size 64x64, GIF",
"5th Icon: Size 64x64, PNG",
"No Icon (system default)"
};
TestFrame() throws IOException {
generateIcon(16, "img_16.gif", 13, 15, 1, "gif");
generateIcon(48, "img_48.gif", 36, 40, 4, "gif");
generateIcon(64, "img_64.png", 50, 58, 4, "png");
// gif created with GREEN selected as transparent color index in IndexColorModel
generateGIFWithIndexColorModel(64, "greenTransparent.gif", 1);
// gif created with BLACK selected as transparent color index in IndexColorModel
generateGIFWithIndexColorModel(64, "blackTransparent.gif", 4);
testIcon = new ImageIcon[] {
new ImageIcon("img_16.gif"),
new ImageIcon("img_48.gif"),
new ImageIcon("greenTransparent.gif"),
new ImageIcon("blackTransparent.gif"),
new ImageIcon("img_64.png"),
null
};
}
public void createAndShowGUI() {
frame = new JFrame();
//create hint label
label = new TestLabel();
label.setVisible(true);
frame.add(label, BorderLayout.WEST);
//create button
button = new JButton("Continue");
button.setVisible(true);
button.addActionListener(this);
frame.add(button, BorderLayout.EAST);
//show first sample
frame.setIconImage(testIcon[0].getImage());
label.setIcon(testIcon[0]);
label.setText(testText[0]);
frame.pack();
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
currTest++;
if (currTest < TEST_CNT) {
if (testIcon[currTest] != null) {
frame.setIconImage(testIcon[currTest].getImage());
} else {
frame.setIconImage(null);
}
label.setIcon(testIcon[currTest]);
label.setText(testText[currTest]);
} else {
button.setEnabled(false);
button.setText("No more icons left.");
}
frame.revalidate();
frame.pack();
}
}
public static void main(String[] args) throws Exception {
TestFrame testFrame = new TestFrame();
PassFailJFrame passFailJFrame = new PassFailJFrame("Icon Transparency " +
"Test Instructions", INSTRUCTIONS, 5, 16, 46);
SwingUtilities.invokeAndWait(testFrame::createAndShowGUI);
passFailJFrame.awaitAndCheck();
}
public static void generateIcon(int size, String filename, int fontSize,
int yText, int lnHeight, String type) throws IOException {
BufferedImage bImg = new BufferedImage(size, size, TYPE_INT_ARGB);
Graphics2D g2d = bImg.createGraphics();
g2d.setComposite(AlphaComposite.Clear);
g2d.fillRect(0, 0, size, size);
g2d.setComposite(AlphaComposite.Src);
g2d.setColor(Color.BLUE);
g2d.fillRect(0, 0, size, lnHeight);
g2d.setColor(Color.GREEN);
g2d.fillRect(0, lnHeight * 2, size, lnHeight);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
g2d.setFont(new Font("Dialog", Font.PLAIN, fontSize));
g2d.setColor(Color.RED);
g2d.drawString("TR", 0, yText);
g2d.dispose();
ImageIO.write(bImg, type, new File(filename));
}
protected static void generateGIFWithIndexColorModel(int size, String filename,
int transparentColorIndex) throws IOException {
IndexColorModel icm = createIndexedBitmaskColorModel(transparentColorIndex);
BufferedImage img = new BufferedImage(size, size,
BufferedImage.TYPE_BYTE_INDEXED, icm);
int mapSize = icm.getMapSize();
int width = 64 / mapSize;
WritableRaster wr = img.getRaster();
for (int i = 0; i < mapSize; i++) {
for (int y = 0; y < 64; y++) {
for (int x = 0; x < width; x++) {
wr.setSample(i * width + x, y, 0, i);
}
}
}
ImageIO.write(img, "gif", new File(filename));
}
protected static IndexColorModel createIndexedBitmaskColorModel(int transparentColorIndex) {
int paletteSize = 8;
byte[] red = new byte[paletteSize];
byte[] green = new byte[paletteSize];
byte[] blue = new byte[paletteSize];
red[0] = (byte)0xff; green[0] = (byte)0x00; blue[0] = (byte)0x00; //red
red[1] = (byte)0x00; green[1] = (byte)0xff; blue[1] = (byte)0x00; //green
red[2] = (byte)0x00; green[2] = (byte)0x00; blue[2] = (byte)0xff; //blue
red[3] = (byte)0xff; green[3] = (byte)0xff; blue[3] = (byte)0xff; //white
red[4] = (byte)0x00; green[4] = (byte)0x00; blue[4] = (byte)0x00; //black
red[5] = (byte)0x80; green[5] = (byte)0x80; blue[5] = (byte)0x80; //grey
red[6] = (byte)0xff; green[6] = (byte)0xff; blue[6] = (byte)0x00; //yellow
red[7] = (byte)0x00; green[7] = (byte)0xff; blue[7] = (byte)0xff; //cyan
int numBits = 3;
return new IndexColorModel(numBits, paletteSize,
red, green, blue, transparentColorIndex);
}
}

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2006, 2023, 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.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/*
* @test
* @key headful
* @bug 6425089
* @summary PIT. Frame does not show a big size jpg image as icon
* @requires (os.family != "mac")
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual SetLargeIconTest
*/
public class SetLargeIconTest {
private static final String INSTRUCTIONS = """
Case 1: Press "Pass" button if this frame does not have icon with green color.
Case 2: Press "Change to red" if the frame icon is in green color.
For case 2, press "Pass" button if green icon changes to a larger red icon,
press "Fail" otherwise.
""";
private static JFrame frame;
private static void createAndShowGUI() {
frame = new JFrame();
setColoredIcon(Color.green, 128, 128);
JButton btnChangeIcon = new JButton("Change to red");
btnChangeIcon.addActionListener(e -> setColoredIcon(Color.red, 400, 400));
frame.add(btnChangeIcon, BorderLayout.CENTER);
frame.setSize(200,65);
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame,
PassFailJFrame.Position.HORIZONTAL);
frame.setVisible(true);
}
private static void setColoredIcon(Color color, int width, int height) {
BufferedImage image = new BufferedImage(400, 400, BufferedImage.TYPE_INT_ARGB);
Graphics gr = image.createGraphics();
gr.setColor(color);
gr.fillRect(0, 0, width, height);
ArrayList<Image> imageList = new java.util.ArrayList<>();
imageList.add(image);
frame.setIconImages(imageList);
}
public static void main(String[] args) throws Exception {
PassFailJFrame passFailJFrame = new PassFailJFrame("Large Icon " +
"Test Instructions", INSTRUCTIONS, 5, 8, 50);
SwingUtilities.invokeAndWait(SetLargeIconTest::createAndShowGUI);
passFailJFrame.awaitAndCheck();
}
}