Skip to content
Snippets Groups Projects
Commit e52902ee authored by KIRIYAMA Takuya's avatar KIRIYAMA Takuya Committed by Goetz Lindenmaier
Browse files

8310072: JComboBox/DisabledComboBoxFontTestAuto: Enabled and disabled ComboBox...

8310072: JComboBox/DisabledComboBoxFontTestAuto: Enabled and disabled ComboBox does not match in these LAFs: GTK+

Backport-of: eb60822a45ecd076484e707b2dd1049ed9d8079b
parent 467231b6
No related branches found
No related tags found
No related merge requests found
/* /*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -21,13 +21,6 @@ ...@@ -21,13 +21,6 @@
* questions. * questions.
*/ */
/*
* @test
* @bug 7093691
* @summary Tests if JComboBox has correct font color when disabled/enabled
* @run main/othervm -Dsun.java2d.uiScale=1 DisabledComboBoxFontTestAuto
*/
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
...@@ -44,20 +37,29 @@ import javax.swing.UnsupportedLookAndFeelException; ...@@ -44,20 +37,29 @@ import javax.swing.UnsupportedLookAndFeelException;
import static java.awt.image.BufferedImage.TYPE_INT_ARGB; import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
/*
* @test
* @bug 7093691 8310072
* @summary Tests if JComboBox has correct font color when disabled/enabled
* @key headful
* @run main/othervm -Dsun.java2d.uiScale=1 DisabledComboBoxFontTestAuto
*/
public class DisabledComboBoxFontTestAuto { public class DisabledComboBoxFontTestAuto {
private static JComboBox combo, combo2; private static JComboBox combo, combo2;
private static BufferedImage enabledImage, disabledImage, enabledImage2, disabledImage2; private static BufferedImage enabledImage, disabledImage, enabledImage2, disabledImage2;
private static Path testDir;
private static String lafName; private static String lafName;
private static StringBuffer failingLafs; private static StringBuffer failingLafs;
private static int COMBO_HEIGHT, COMBO_WIDTH, COMBO2_HEIGHT, COMBO2_WIDTH; private static int COMBO_HEIGHT, COMBO_WIDTH, COMBO2_HEIGHT, COMBO2_WIDTH;
private static void createCombo() { private static void createCombo() {
combo = new JComboBox(); combo = new JComboBox();
combo.addItem("Simple JComboBox"); combo.addItem("\u2588".repeat(5));
combo.setFont(combo.getFont().deriveFont(50.0f));
combo.setRenderer(new DefaultListCellRenderer()); combo.setRenderer(new DefaultListCellRenderer());
combo2 = new JComboBox(); combo2 = new JComboBox();
combo2.addItem("Simple JComboBox"); combo2.addItem("\u2588".repeat(5));
combo2.setFont(combo2.getFont().deriveFont(50.0f));
COMBO_WIDTH = (int) combo.getPreferredSize().getWidth(); COMBO_WIDTH = (int) combo.getPreferredSize().getWidth();
COMBO_HEIGHT = (int) combo.getPreferredSize().getHeight(); COMBO_HEIGHT = (int) combo.getPreferredSize().getHeight();
COMBO2_WIDTH = (int) combo2.getPreferredSize().getWidth(); COMBO2_WIDTH = (int) combo2.getPreferredSize().getWidth();
...@@ -90,53 +92,38 @@ public class DisabledComboBoxFontTestAuto { ...@@ -90,53 +92,38 @@ public class DisabledComboBoxFontTestAuto {
} }
private static void testMethod() throws IOException { private static void testMethod() throws IOException {
ImageIO.write(enabledImage, "png", new File(testDir
+ "/" + lafName + "Enabled.png"));
ImageIO.write(disabledImage, "png", new File(testDir
+ "/" + lafName + "Disabled.png"));
ImageIO.write(enabledImage2, "png", new File(testDir
+ "/" + lafName + "EnabledDLCR.png"));
ImageIO.write(disabledImage2, "png", new File(testDir
+ "/" + lafName + "DisabledDLCR.png"));
boolean isIdentical = true;
Color eColor1, eColor2, dColor1, dColor2; Color eColor1, eColor2, dColor1, dColor2;
Path testDir = Path.of(System.getProperty("test.classes", "."));
// Use center line to compare RGB values // Use center line to compare RGB values
int y = 10; int y = enabledImage.getHeight() / 2;
for (int x = (enabledImage.getWidth() / 2) - 20; for (int x = (enabledImage.getWidth() / 2) - 20;
x < (enabledImage.getWidth() / 2) + 20; x++) { x < (enabledImage.getWidth() / 2) + 20; x++) {
// Nimbus has a pixel offset in coordinates since Nimbus is 2px
// smaller in width than other L&F's
if (lafName.equals("Nimbus")) {
eColor1 = new Color(enabledImage.getRGB(x + 1, y));
eColor2 = new Color(enabledImage2.getRGB(x, y));
dColor1 = new Color(disabledImage.getRGB(x + 1, y));
dColor2 = new Color(disabledImage2.getRGB(x, y));
} else {
eColor1 = new Color(enabledImage.getRGB(x, y)); eColor1 = new Color(enabledImage.getRGB(x, y));
eColor2 = new Color(enabledImage2.getRGB(x, y)); eColor2 = new Color(enabledImage2.getRGB(x, y));
dColor1 = new Color(disabledImage.getRGB(x, y)); dColor1 = new Color(disabledImage.getRGB(x, y));
dColor2 = new Color(disabledImage2.getRGB(x, y)); dColor2 = new Color(disabledImage2.getRGB(x, y));
}
if ((!isColorMatching(eColor1, eColor2)) || (!isColorMatching(dColor1, dColor2))) {
isIdentical = false;
break;
}
}
if (isIdentical) { if ((!isColorMatching(eColor1, eColor2)) || (!isColorMatching(dColor1, dColor2))) {
System.out.println("PASSED");
} else {
failingLafs.append(lafName + ", "); failingLafs.append(lafName + ", ");
ImageIO.write(enabledImage, "png", new File(testDir
+ "/" + lafName + "Enabled.png"));
ImageIO.write(disabledImage, "png", new File(testDir
+ "/" + lafName + "Disabled.png"));
ImageIO.write(enabledImage2, "png", new File(testDir
+ "/" + lafName + "EnabledDLCR.png"));
ImageIO.write(disabledImage2, "png", new File(testDir
+ "/" + lafName + "DisabledDLCR.png"));
return;
} }
} }
System.out.println("Test Passed: " + lafName);
}
private static boolean isColorMatching(Color c1, Color c2) { private static boolean isColorMatching(Color c1, Color c2) {
if ((c1.getRed() != c2.getRed()) if ((c1.getRed() != c2.getRed())
|| (c1.getBlue() != c2.getBlue()) || (c1.getBlue() != c2.getBlue())
|| (c1.getGreen() != c2.getGreen())) { || (c1.getGreen() != c2.getGreen())) {
System.out.println(lafName + " Enabled RGB failure: " System.out.println(lafName + " Enabled RGB failure: "
+ c1.getRed() + ", " + c1.getRed() + ", "
+ c1.getBlue() + ", " + c1.getBlue() + ", "
...@@ -163,7 +150,6 @@ public class DisabledComboBoxFontTestAuto { ...@@ -163,7 +150,6 @@ public class DisabledComboBoxFontTestAuto {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
lafName = "null"; lafName = "null";
failingLafs = new StringBuffer(); failingLafs = new StringBuffer();
testDir = Path.of(System.getProperty("test.classes", "."));
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
// Change Motif LAF name to avoid using slash in saved image file path // Change Motif LAF name to avoid using slash in saved image file path
lafName = laf.getName().equals("CDE/Motif") ? "Motif" : laf.getName(); lafName = laf.getName().equals("CDE/Motif") ? "Motif" : laf.getName();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment