8352149: Test java/awt/Frame/MultiScreenTest.java fails: Window list is empty

Reviewed-by: aivanov, abhiscxk
This commit is contained in:
Khalid Boulanouare 2025-06-11 10:25:28 +00:00 committed by Alexey Ivanov
parent 56ce70c5df
commit 5ae32c4c86

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2025, 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
@ -43,6 +43,7 @@ import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.TextField;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -74,7 +75,7 @@ public class MultiScreenTest {
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
gs = ge.getScreenDevices();
if (gs.length < 2) {
throw new SkippedException("You have only one monitor in your system - test passed");
throw new SkippedException("You have only one monitor in your system");
}
MultiScreenTest obj = new MultiScreenTest();
String INSTRUCTIONS =
@ -82,38 +83,42 @@ public class MultiScreenTest {
"You have " + gs.length + " monitors in your system.\n" +
"Actively drag the DitherTest frames on the secondary screen and " +
"if you see garbage appearing on your primary screen " +
"test failed otherwise it passed.";;
"test failed otherwise it passed.";
PassFailJFrame.builder()
.title("MultiScreenTest Instruction")
.instructions(INSTRUCTIONS)
.rows((int) INSTRUCTIONS.lines().count() + 2)
.columns(40)
.testUI(obj::init)
.positionTestUI(MultiScreenTest::positionTestWindows)
.build()
.awaitAndCheck();
}
private static void positionTestWindows(List<Window> windows, PassFailJFrame.InstructionUI instructionUI) {
// Do nothing - the location of each window is set when they're created
}
public List<JFrame> init() {
List<JFrame> list = new ArrayList<>();
for (int j = 0; j < gs.length; j++) {
GraphicsConfiguration[] gc = gs[j].getConfigurations();
if (gc.length > 0) {
for (int i = 0; i < gc.length / 2; i++) {
JFrame f = new JFrame(gc[i]); //test JFrame( gc )
GCCanvas c = new GCCanvas(gc[i]);//test canvas( gc )
Rectangle gcBounds = gc[i].getBounds(); //test getBounds()
for (int i = 0; i < gc.length && i < 10; i++) {
JFrame f = new JFrame(gc[i]);
GCCanvas c = new GCCanvas(gc[i]);
Rectangle gcBounds = gc[i].getBounds();
int xoffs = gcBounds.x;
int yoffs = gcBounds.y;
f.getContentPane().add(c);
f.setTitle("Screen# " + Integer.toString(j) + ", GC#" + Integer.toString(i));
f.setTitle("Screen# " + j + ", GC#" + i);
f.setSize(300, 200);
f.setLocation(400 + xoffs, (i * 150) + yoffs);//test displaying in right location
// test displaying in right location
f.setLocation(400 + xoffs, (i * 150) + yoffs);
list.add(f);
Frame ditherfs = new Frame("DitherTest GC#" + Integer.toString(i), gc[i]);
ditherfs.setLayout(new BorderLayout()); //showDitherTest
Frame ditherfs = new Frame("DitherTest GC#" + i, gc[i]);
ditherfs.setLayout(new BorderLayout());
DitherTest ditherTest = new DitherTest(gc[i]);
ditherfs.add("Center", ditherTest);
ditherfs.setBounds(300, 200, 300, 200);
@ -126,13 +131,12 @@ public class MultiScreenTest {
}
return list;
}
}
class GCCanvas extends Canvas {
static class GCCanvas extends Canvas {
GraphicsConfiguration gc;
Rectangle bounds;
Graphics g = this.getGraphics();
Dimension size = getSize();
public GCCanvas(GraphicsConfiguration gc) {
@ -141,6 +145,7 @@ class GCCanvas extends Canvas {
bounds = gc.getBounds();
}
@Override
public void paint( Graphics _g ) {
Graphics2D g = (Graphics2D) _g;
@ -174,12 +179,13 @@ class GCCanvas extends Canvas {
g.fillArc(150, 30, 30, 30, 0, 200);
}
@Override
public Dimension getPreferredSize(){
return new Dimension(300, 200);
}
}
class DitherCanvas extends Canvas {
static class DitherCanvas extends Canvas {
Image img;
static String calcString = "Calculating...";
@ -194,6 +200,7 @@ class DitherCanvas extends Canvas {
return mGC;
}
@Override
public void paint(Graphics g) {
int w = getSize().width;
int h = getSize().height;
@ -209,14 +216,17 @@ class DitherCanvas extends Canvas {
}
}
@Override
public void update(Graphics g) {
paint(g);
}
@Override
public Dimension getMinimumSize() {
return new Dimension(20, 20);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 200);
}
@ -231,7 +241,7 @@ class DitherCanvas extends Canvas {
}
}
class DitherTest extends Panel implements Runnable {
static class DitherTest extends Panel implements Runnable {
final static int NOOP = 0;
final static int RED = 1;
final static int GREEN = 2;
@ -371,6 +381,7 @@ class DitherTest extends Panel implements Runnable {
}
}
@Override
public void run() {
canvas.setImage(null); // Wipe previous image
Image img = calculateImage();
@ -440,7 +451,7 @@ class DitherTest extends Panel implements Runnable {
}
}
class DitherControls extends Panel implements ActionListener {
static class DitherControls extends Panel implements ActionListener {
TextField start;
TextField end;
Button button;
@ -477,9 +488,11 @@ class DitherControls extends Panel implements ActionListener {
return choice.getSelectedIndex();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) {
dt.start();
}
}
}
}