Skip to content

Commit 7bded55

Browse files
committed
8273685: Remove jtreg tag manual=yesno for java/awt/Graphics/LCDTextAndGraphicsState.java & show test instruction
Backport-of: 2a2e9190d4e866ac1b712feb0e4bb61d08e112c7
1 parent 41c6116 commit 7bded55

File tree

1 file changed

+86
-24
lines changed

1 file changed

+86
-24
lines changed
Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2021, 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,72 +21,134 @@
2121
* questions.
2222
*/
2323

24-
/**
24+
/*
2525
* @test
2626
* @bug 6576507
2727
* @summary Both lines of text should be readable
28-
* @run main/manual=yesno LCDTextAndGraphicsState
28+
* @run main/manual LCDTextAndGraphicsState
2929
*/
30-
import java.awt.*;
31-
import java.awt.geom.*;
30+
31+
import java.awt.AlphaComposite;
32+
import java.awt.BorderLayout;
33+
import java.awt.Button;
34+
import java.awt.Color;
35+
import java.awt.Component;
36+
import java.awt.Dimension;
37+
import java.awt.Frame;
38+
import java.awt.GradientPaint;
39+
import java.awt.Graphics;
40+
import java.awt.Graphics2D;
41+
import java.awt.GridLayout;
42+
import java.awt.Panel;
43+
import java.awt.RenderingHints;
44+
import java.awt.Shape;
45+
import java.awt.TextArea;
46+
import java.awt.event.ActionEvent;
47+
import java.awt.geom.RoundRectangle2D;
48+
import java.util.concurrent.CountDownLatch;
49+
import java.util.concurrent.TimeUnit;
3250

3351
public class LCDTextAndGraphicsState extends Component {
3452

35-
String text = "This test passes only if this text appears SIX TIMES";
53+
private static final Frame testFrame = new Frame("Composite and Text Test");
54+
private static final String text = "This test passes only if this text appears SIX TIMES else fail";
55+
private static volatile boolean testResult;
56+
private static volatile CountDownLatch countDownLatch;
3657

3758
public void paint(Graphics g) {
38-
3959
Graphics2D g2d = (Graphics2D)g.create();
4060
g2d.setColor(Color.white);
4161
g2d.fillRect(0,0,getSize().width, getSize().height);
42-
43-
test1(g.create(0, 0, 500, 200));
44-
test2(g.create(0, 200, 500, 200));
45-
test3(g.create(0, 400, 500, 200));
62+
test1(g.create(0, 0, 500, 100));
63+
test2(g.create(0, 100, 500, 100));
64+
test3(g.create(0, 200, 500, 100));
4665
}
4766

4867
public void test1(Graphics g) {
4968
Graphics2D g2d = (Graphics2D)g;
5069
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
5170
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
5271
g2d.setColor(Color.black);
53-
g2d.drawString(text, 10, 50);
72+
g2d.drawString(text, 10, 20);
5473
g2d.setComposite(AlphaComposite.getInstance(
5574
AlphaComposite.SRC_OVER, 0.9f));
56-
g2d.drawString(text, 10, 80);
75+
g2d.drawString(text, 10, 50);
5776
}
5877

5978
public void test2(Graphics g) {
6079
Graphics2D g2d = (Graphics2D)g;
6180
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
6281
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
6382
g2d.setColor(Color.black);
64-
g2d.drawString(text, 10, 50);
83+
g2d.drawString(text, 10, 20);
6584
g2d.setPaint(new GradientPaint(
6685
0f, 0f, Color.BLACK, 100f, 100f, Color.GRAY));
67-
g2d.drawString(text, 10, 80);
86+
g2d.drawString(text, 10, 50);
6887
}
6988

7089
public void test3(Graphics g) {
7190
Graphics2D g2d = (Graphics2D)g;
7291
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
7392
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
7493
g2d.setColor(Color.black);
75-
g2d.drawString(text, 10, 50);
76-
Shape s = new RoundRectangle2D.Double(0, 60, 400, 50, 5, 5);
94+
g2d.drawString(text, 10, 20);
95+
Shape s = new RoundRectangle2D.Double(0, 30, 400, 50, 5, 5);
7796
g2d.clip(s);
78-
g2d.drawString(text, 10, 80);
97+
g2d.drawString(text, 10, 50);
7998
}
8099

81100
public Dimension getPreferredSize() {
82-
return new Dimension(500,600);
101+
return new Dimension(500,300);
102+
}
103+
104+
public static void disposeUI() {
105+
countDownLatch.countDown();
106+
testFrame.dispose();
83107
}
84108

85-
public static void main(String[] args) throws Exception {
109+
public static void createTestUI() {
110+
testFrame.add(new LCDTextAndGraphicsState(), BorderLayout.NORTH);
111+
Panel resultButtonPanel = new Panel(new GridLayout(1, 2));
112+
Button passButton = new Button("Pass");
113+
passButton.addActionListener((ActionEvent e) -> {
114+
testResult = true;
115+
disposeUI();
116+
});
117+
Button failButton = new Button("Fail");
118+
failButton.addActionListener(e -> {
119+
testResult = false;
120+
disposeUI();
121+
});
122+
resultButtonPanel.add(passButton);
123+
resultButtonPanel.add(failButton);
124+
125+
Panel controlUI = new Panel(new BorderLayout());
126+
TextArea instructions = new TextArea(
127+
"Instructions:\n" +
128+
"If you see the text six times above, press Pass.\n" +
129+
"If not, press Fail.",
130+
3,
131+
50,
132+
TextArea.SCROLLBARS_NONE
133+
);
134+
instructions.setEditable(false);
135+
controlUI.add(instructions, BorderLayout.CENTER);
136+
controlUI.add(resultButtonPanel, BorderLayout.SOUTH);
137+
138+
testFrame.add(controlUI, BorderLayout.SOUTH);
139+
testFrame.pack();
140+
testFrame.setLocationRelativeTo(null);
141+
testFrame.setVisible(true);
142+
}
86143

87-
Frame f = new Frame("Composite and Text Test");
88-
f.add(new LCDTextAndGraphicsState(), BorderLayout.CENTER);
89-
f.pack();
90-
f.setVisible(true);
144+
public static void main(String[] args) throws InterruptedException {
145+
countDownLatch = new CountDownLatch(1);
146+
createTestUI();
147+
if (!countDownLatch.await(10, TimeUnit.MINUTES)) {
148+
throw new RuntimeException("Timeout : No action was performed on the test UI.");
149+
}
150+
if (!testResult) {
151+
throw new RuntimeException("Test failed!");
152+
}
91153
}
92154
}

0 commit comments

Comments
 (0)