Skip to content

Commit

Permalink
8310072: JComboBox/DisabledComboBoxFontTestAuto: Enabled and disabled…
Browse files Browse the repository at this point in the history
… ComboBox does not match in these LAFs: GTK+

Backport-of: eb60822a45ecd076484e707b2dd1049ed9d8079b
  • Loading branch information
mrserb committed Jun 1, 2024
1 parent 0d9833e commit 0e9b9f2
Showing 1 changed file with 33 additions and 47 deletions.
80 changes: 33 additions & 47 deletions test/jdk/javax/swing/JComboBox/DisabledComboBoxFontTestAuto.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -44,20 +37,29 @@

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();
Expand Down Expand Up @@ -90,53 +92,38 @@ private static void paintCombo() {
}

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));
}
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;
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;
}
}

if (isIdentical) {
System.out.println("PASSED");
} else {
failingLafs.append(lafName + ", ");
}
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() + ", "
Expand All @@ -163,7 +150,6 @@ private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
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();
Expand Down

1 comment on commit 0e9b9f2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.