Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8233564: [TESTBUG] MouseComboBoxTest.java is failing #3456

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -27,7 +27,7 @@
* @summary Tests that a JApplet in a translucent JFrame works properly
* @author Kenneth.Russell@sun.com: area=Graphics
* @compile -XDignore.symbol.file=true TranslucentJAppletTest.java
* @run main TranslucentJAppletTest
* @run main/manual/othervm TranslucentJAppletTest
*/

import java.awt.*;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018, 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
@@ -25,175 +25,91 @@
* @bug 4449413
* @summary Tests that checkbox and radiobuttons' check marks are visible when background is black
* @author Ilya Boyandin
* @run main/manual bug4449413
* @library /test/lib
* @modules java.desktop/sun.awt
* @build jdk.test.lib.Platform
* @run applet/manual=yesno bug4449413.html
*/

import javax.swing.AbstractButton;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.MetalTheme;
import javax.swing.plaf.metal.OceanTheme;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class bug4449413 extends JFrame {

private static final String INSTRUCTIONS = """
There are eight controls with black backgrounds.
Four enabled (on the left side) and four disabled (on the right side)
checkboxes and radiobuttons.
1. If at least one of the controls' check marks is not visible:
the test fails.
""";

private static final String INSTRUCTIONS_ADDITIONS_METAL = """
2. Uncheck the "Use Ocean Theme" check box.
If now at least one of the controls' check marks is not visible:
the test fails.
""";

private static final CountDownLatch latch = new CountDownLatch(1);
private static volatile boolean failed = true;

private final MetalTheme defaultMetalTheme = new DefaultMetalTheme();
private final MetalTheme oceanTheme = new OceanTheme();

private static bug4449413 instance;

boolean isMetalLookAndFeel() {
return UIManager.getLookAndFeel() instanceof MetalLookAndFeel;
}
import javax.swing.*;
import javax.swing.plaf.metal.*;
import java.awt.event.*;
import java.awt.*;

public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(() -> {
instance = new bug4449413();
instance.createAndShowGUI();
});
import jdk.test.lib.Platform;

boolean timeoutHappened = !latch.await(2, TimeUnit.MINUTES);
if (instance != null) {
instance.dispose();
}
public class bug4449413 extends JApplet {

System.out.println("Passed: " + !failed);
@Override
public void init() {

if (timeoutHappened || failed) {
throw new RuntimeException("Test failed!");
}
}
try {

private void createAndShowGUI() {
setTitle(UIManager.getLookAndFeel().getClass().getName());

addComponentsToPane();

addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
latch.countDown();
if (Platform.isOSX()) {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
}
});

setLocationRelativeTo(null);
pack();
setVisible(true);
}

public void addComponentsToPane() {
setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

JPanel testedPanel = new JPanel();
testedPanel.setLayout(new GridLayout(4, 6, 10, 15));
for (int k = 0; k <= 3; k++) {
for (int j = 1; j >= 0; j--) {
AbstractButton b = createButton(j, k);
testedPanel.add(b);
}
}

add(testedPanel);


if (isMetalLookAndFeel()) {
JCheckBox oceanThemeSwitch = new JCheckBox("Use Ocean theme", true);
oceanThemeSwitch.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
MetalLookAndFeel.setCurrentTheme(oceanTheme);
} else {
MetalLookAndFeel.setCurrentTheme(defaultMetalTheme);
final MetalTheme oceanTheme = (MetalTheme) sun.awt.AppContext.getAppContext().get("currentMetalTheme");


SwingUtilities.invokeAndWait(new Runnable() {

@Override
public void run() {
getContentPane().setLayout(new FlowLayout());
final JPanel panel = new JPanel();

JCheckBox box = new JCheckBox("Use Ocean theme", true);
getContentPane().add(box);
box.addItemListener(new ItemListener() {

@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
MetalLookAndFeel.setCurrentTheme(oceanTheme);
} else {
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
}
SwingUtilities.updateComponentTreeUI(panel);
}
});

getContentPane().add(panel);
panel.setLayout(new GridLayout(4, 6, 10, 15));
for (int k = 0; k <= 3; k++) {
for (int j = 1; j >= 0; j--) {
AbstractButton b = createButton(j, k);
panel.add(b);
}
}
}
SwingUtilities.updateComponentTreeUI(testedPanel);
});

add(oceanThemeSwitch);
} catch (Exception e) {
throw new RuntimeException(e);
}

JTextArea instructionArea = new JTextArea(
isMetalLookAndFeel()
? INSTRUCTIONS + INSTRUCTIONS_ADDITIONS_METAL
: INSTRUCTIONS
);

instructionArea.setEditable(false);
instructionArea.setFocusable(false);
instructionArea.setMargin(new Insets(10,10,10,10));

add(instructionArea);


JButton passButton = new JButton("Pass");
JButton failButton = new JButton("Fail");

ActionListener actionListener = e -> {
failed = e.getSource() == failButton;
latch.countDown();
};

passButton.addActionListener(actionListener);
failButton.addActionListener(actionListener);

JPanel passFailPanel = new JPanel();
passFailPanel.add(passButton);
passFailPanel.add(failButton);

add(passFailPanel);
}

static AbstractButton createButton(int enabled, int type) {
AbstractButton b = switch (type) {
case 0 -> new JRadioButton("RadioButton");
case 1 -> new JCheckBox("CheckBox");
case 2 -> new JRadioButtonMenuItem("RBMenuItem");
case 3 -> new JCheckBoxMenuItem("CBMenuItem");
default -> throw new IllegalArgumentException("type should be in range of 0..3");
};

b.setOpaque(true);
AbstractButton b = null;
switch (type) {
case 0:
b = new JRadioButton("RadioButton");
break;
case 1:
b = new JCheckBox("CheckBox");
break;
case 2:
b = new JRadioButtonMenuItem("RBMenuItem");
break;
case 3:
b = new JCheckBoxMenuItem("CBMenuItem");
break;
}
b.setBackground(Color.black);
b.setForeground(Color.white);
b.setEnabled(enabled == 1);
b.setSelected(true);
return b;
}
}