8310072: JComboBox/DisabledComboBoxFontTestAuto: Enabled and disabled ComboBox does not match in these LAFs: GTK+
Reviewed-by: dnguyen, jdv, tr, serb
This commit is contained in:
parent
85261bcebc
commit
eb60822a45
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -21,13 +21,6 @@
|
||||
* 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.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
@ -44,20 +37,29 @@ import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
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 {
|
||||
private static JComboBox combo, combo2;
|
||||
private static BufferedImage enabledImage, disabledImage, enabledImage2, disabledImage2;
|
||||
private static Path testDir;
|
||||
private static String lafName;
|
||||
private static StringBuffer failingLafs;
|
||||
private static int COMBO_HEIGHT, COMBO_WIDTH, COMBO2_HEIGHT, COMBO2_WIDTH;
|
||||
|
||||
private static void createCombo() {
|
||||
combo = new JComboBox();
|
||||
combo.addItem("Simple JComboBox");
|
||||
combo.addItem("\u2588".repeat(5));
|
||||
combo.setFont(combo.getFont().deriveFont(50.0f));
|
||||
combo.setRenderer(new DefaultListCellRenderer());
|
||||
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_HEIGHT = (int) combo.getPreferredSize().getHeight();
|
||||
COMBO2_WIDTH = (int) combo2.getPreferredSize().getWidth();
|
||||
@ -90,53 +92,38 @@ public class DisabledComboBoxFontTestAuto {
|
||||
}
|
||||
|
||||
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;
|
||||
Path testDir = Path.of(System.getProperty("test.classes", "."));
|
||||
|
||||
// Use center line to compare RGB values
|
||||
int y = 10;
|
||||
int y = enabledImage.getHeight() / 2;
|
||||
for (int x = (enabledImage.getWidth() / 2) - 20;
|
||||
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));
|
||||
eColor2 = new Color(enabledImage2.getRGB(x, y));
|
||||
dColor1 = new Color(disabledImage.getRGB(x, y));
|
||||
dColor2 = new Color(disabledImage2.getRGB(x, y));
|
||||
}
|
||||
if ((!isColorMatching(eColor1, eColor2)) || (!isColorMatching(dColor1, dColor2))) {
|
||||
isIdentical = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
eColor1 = new Color(enabledImage.getRGB(x, y));
|
||||
eColor2 = new Color(enabledImage2.getRGB(x, y));
|
||||
dColor1 = new Color(disabledImage.getRGB(x, y));
|
||||
dColor2 = new Color(disabledImage2.getRGB(x, y));
|
||||
|
||||
if (isIdentical) {
|
||||
System.out.println("PASSED");
|
||||
} else {
|
||||
failingLafs.append(lafName + ", ");
|
||||
if ((!isColorMatching(eColor1, eColor2)) || (!isColorMatching(dColor1, dColor2))) {
|
||||
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) {
|
||||
if ((c1.getRed() != c2.getRed())
|
||||
|| (c1.getBlue() != c2.getBlue())
|
||||
|| (c1.getGreen() != c2.getGreen())) {
|
||||
|
||||
|| (c1.getBlue() != c2.getBlue())
|
||||
|| (c1.getGreen() != c2.getGreen())) {
|
||||
System.out.println(lafName + " Enabled RGB failure: "
|
||||
+ c1.getRed() + ", "
|
||||
+ c1.getBlue() + ", "
|
||||
@ -163,7 +150,6 @@ public class DisabledComboBoxFontTestAuto {
|
||||
public static void main(String[] args) throws Exception {
|
||||
lafName = "null";
|
||||
failingLafs = new StringBuffer();
|
||||
testDir = Path.of(System.getProperty("test.classes", "."));
|
||||
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
|
||||
// Change Motif LAF name to avoid using slash in saved image file path
|
||||
lafName = laf.getName().equals("CDE/Motif") ? "Motif" : laf.getName();
|
||||
|
Loading…
x
Reference in New Issue
Block a user