Skip to content

Commit 52c0b09

Browse files
committed
8277240: java/awt/Graphics2D/ScaledTransform/ScaledTransform.java dialog does not get disposed
Reviewed-by: aivanov
1 parent 0329855 commit 52c0b09

File tree

1 file changed

+66
-35
lines changed

1 file changed

+66
-35
lines changed
Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
2121
* questions.
2222
*/
2323
import java.awt.Dialog;
24+
import java.awt.EventQueue;
2425
import java.awt.Frame;
2526
import java.awt.Graphics;
2627
import java.awt.Graphics2D;
@@ -29,63 +30,93 @@
2930
import java.awt.GraphicsEnvironment;
3031
import java.awt.Panel;
3132
import java.awt.geom.AffineTransform;
33+
import java.util.concurrent.CountDownLatch;
34+
import java.util.concurrent.TimeUnit;
3235

3336
/*
3437
* @test
3538
* @bug 8069361
3639
* @key headful
3740
* @summary SunGraphics2D.getDefaultTransform() does not include scale factor
38-
* @author Alexander Scherbatiy
39-
* @run main ScaledTransform
41+
* @run main/timeout=300 ScaledTransform
4042
*/
4143
public class ScaledTransform {
4244

43-
private static volatile boolean passed = false;
45+
private static volatile CountDownLatch painted;
46+
private static volatile boolean passed;
47+
private static volatile Dialog dialog;
48+
private static volatile long startTime;
49+
private static volatile long endTime;
4450

45-
public static void main(String[] args) {
51+
public static void main(String[] args) throws Exception {
4652
GraphicsEnvironment ge = GraphicsEnvironment.
4753
getLocalGraphicsEnvironment();
4854

49-
if (ge.isHeadlessInstance()) {
50-
return;
51-
}
52-
5355
for (GraphicsDevice gd : ge.getScreenDevices()) {
54-
for (GraphicsConfiguration gc : gd.getConfigurations()) {
55-
testScaleFactor(gc);
56+
System.out.println("Screen = " + gd);
57+
test(gd.getDefaultConfiguration());
58+
/* Don't want to run too long. Test the default and up to 10 more */
59+
GraphicsConfiguration[] configs = gd.getConfigurations();
60+
for (int c = 0; c < configs.length && c < 10; c++) {
61+
test(configs[c]);
5662
}
5763
}
5864
}
5965

60-
private static void testScaleFactor(final GraphicsConfiguration gc) {
61-
final Dialog dialog = new Dialog((Frame) null, "Test", true, gc);
62-
66+
static void test(GraphicsConfiguration gc) throws Exception {
6367
try {
64-
dialog.setSize(100, 100);
65-
Panel panel = new Panel() {
66-
67-
@Override
68-
public void paint(Graphics g) {
69-
if (g instanceof Graphics2D) {
70-
AffineTransform gcTx = gc.getDefaultTransform();
71-
AffineTransform gTx
72-
= ((Graphics2D) g).getTransform();
73-
passed = gcTx.getScaleX() == gTx.getScaleX()
74-
&& gcTx.getScaleY() == gTx.getScaleY();
75-
} else {
76-
passed = true;
77-
}
78-
dialog.setVisible(false);
79-
}
80-
};
81-
dialog.add(panel);
82-
dialog.setVisible(true);
83-
68+
/* reset vars for each run */
69+
passed = false;
70+
dialog = null;
71+
painted = new CountDownLatch(1);
72+
EventQueue.invokeLater(() -> showDialog(gc));
73+
startTime = System.currentTimeMillis();
74+
endTime = startTime;
75+
if (!painted.await(5, TimeUnit.SECONDS)) {
76+
throw new RuntimeException("Panel is not painted!");
77+
}
78+
System.out.println("Time to paint = " + (endTime - startTime) + "ms.");
8479
if (!passed) {
8580
throw new RuntimeException("Transform is not scaled!");
8681
}
8782
} finally {
88-
dialog.dispose();
83+
EventQueue.invokeAndWait(() -> disposeDialog());
8984
}
9085
}
86+
87+
private static void showDialog(final GraphicsConfiguration gc) {
88+
System.out.println("Creating dialog for gc=" + gc + " with tx=" + gc.getDefaultTransform());
89+
dialog = new Dialog((Frame) null, "ScaledTransform", true, gc);
90+
dialog.setSize(300, 100);
91+
92+
Panel panel = new Panel() {
93+
94+
@Override
95+
public void paint(Graphics g) {
96+
System.out.println("Painting panel");
97+
if (g instanceof Graphics2D g2d) {
98+
AffineTransform gcTx = gc.getDefaultTransform();
99+
AffineTransform gTx = g2d.getTransform();
100+
System.out.println("GTX = " + gTx);
101+
passed = (gcTx.getScaleX() == gTx.getScaleX()) &&
102+
(gcTx.getScaleY() == gTx.getScaleY());
103+
} else {
104+
passed = true;
105+
}
106+
endTime = System.currentTimeMillis();
107+
painted.countDown();
108+
System.out.println("Painted panel");
109+
}
110+
};
111+
dialog.add(panel);
112+
dialog.setVisible(true);
113+
}
114+
115+
private static void disposeDialog() {
116+
if (dialog != null) {
117+
System.out.println("Disposing dialog");
118+
dialog.setVisible(false);
119+
dialog.dispose();
120+
}
121+
}
91122
}

0 commit comments

Comments
 (0)