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+

Reviewed-by: dnguyen, jdv, tr, serb
  • Loading branch information
Abhishek Kumar committed Apr 19, 2024
1 parent 85261bc commit eb60822
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

5 comments on commit eb60822

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@mrserb
Copy link
Member

@mrserb mrserb commented on eb60822 May 30, 2024

Choose a reason for hiding this comment

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

/backport jdk22u

@mrserb
Copy link
Member

@mrserb mrserb commented on eb60822 May 30, 2024

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on eb60822 May 30, 2024

Choose a reason for hiding this comment

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

@mrserb the backport was successfully created on the branch backport-mrserb-eb60822a in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit eb60822a from the openjdk/jdk repository.

The commit being backported was authored by Abhishek Kumar on 19 Apr 2024 and was reviewed by Damon Nguyen, Jayathirth D V, Tejesh R and Sergey Bylokhov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-mrserb-eb60822a:backport-mrserb-eb60822a
$ git checkout backport-mrserb-eb60822a
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-mrserb-eb60822a

@openjdk
Copy link

@openjdk openjdk bot commented on eb60822 May 30, 2024

Choose a reason for hiding this comment

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

@mrserb the backport was successfully created on the branch backport-mrserb-eb60822a in my personal fork of openjdk/jdk22u. To create a pull request with this backport targeting openjdk/jdk22u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit eb60822a from the openjdk/jdk repository.

The commit being backported was authored by Abhishek Kumar on 19 Apr 2024 and was reviewed by Damon Nguyen, Jayathirth D V, Tejesh R and Sergey Bylokhov.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22u:

$ git fetch https://github.com/openjdk-bots/jdk22u.git backport-mrserb-eb60822a:backport-mrserb-eb60822a
$ git checkout backport-mrserb-eb60822a
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22u.git backport-mrserb-eb60822a

⚠️ @mrserb You are not yet a collaborator in my fork openjdk-bots/jdk22u. An invite will be sent out and you need to accept it before you can proceed.

Please sign in to comment.