2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
5506
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @test
|
|
26 |
* @bug 6576507
|
|
27 |
* @summary Both lines of text should be readable
|
|
28 |
* @run main/manual=yesno LCDTextAndGraphicsState
|
|
29 |
*/
|
|
30 |
import java.awt.*;
|
|
31 |
import java.awt.geom.*;
|
|
32 |
|
|
33 |
public class LCDTextAndGraphicsState extends Component {
|
|
34 |
|
|
35 |
String text = "This test passes only if this text appears SIX TIMES";
|
|
36 |
|
|
37 |
public void paint(Graphics g) {
|
|
38 |
|
|
39 |
Graphics2D g2d = (Graphics2D)g.create();
|
|
40 |
g2d.setColor(Color.white);
|
|
41 |
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));
|
|
46 |
}
|
|
47 |
|
|
48 |
public void test1(Graphics g) {
|
|
49 |
Graphics2D g2d = (Graphics2D)g;
|
|
50 |
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
|
51 |
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
|
52 |
g2d.setColor(Color.black);
|
|
53 |
g2d.drawString(text, 10, 50);
|
|
54 |
g2d.setComposite(AlphaComposite.getInstance(
|
|
55 |
AlphaComposite.SRC_OVER, 0.9f));
|
|
56 |
g2d.drawString(text, 10, 80);
|
|
57 |
}
|
|
58 |
|
|
59 |
public void test2(Graphics g) {
|
|
60 |
Graphics2D g2d = (Graphics2D)g;
|
|
61 |
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
|
62 |
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
|
63 |
g2d.setColor(Color.black);
|
|
64 |
g2d.drawString(text, 10, 50);
|
|
65 |
g2d.setPaint(new GradientPaint(
|
|
66 |
0f, 0f, Color.BLACK, 100f, 100f, Color.GRAY));
|
|
67 |
g2d.drawString(text, 10, 80);
|
|
68 |
}
|
|
69 |
|
|
70 |
public void test3(Graphics g) {
|
|
71 |
Graphics2D g2d = (Graphics2D)g;
|
|
72 |
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
|
73 |
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
|
74 |
g2d.setColor(Color.black);
|
|
75 |
g2d.drawString(text, 10, 50);
|
|
76 |
Shape s = new RoundRectangle2D.Double(0, 60, 400, 50, 5, 5);
|
|
77 |
g2d.clip(s);
|
|
78 |
g2d.drawString(text, 10, 80);
|
|
79 |
}
|
|
80 |
|
|
81 |
public Dimension getPreferredSize() {
|
|
82 |
return new Dimension(500,600);
|
|
83 |
}
|
|
84 |
|
|
85 |
public static void main(String[] args) throws Exception {
|
|
86 |
|
|
87 |
Frame f = new Frame("Composite and Text Test");
|
|
88 |
f.add(new LCDTextAndGraphicsState(), BorderLayout.CENTER);
|
|
89 |
f.pack();
|
|
90 |
f.setVisible(true);
|
|
91 |
}
|
|
92 |
}
|