Path: blob/master/test/jdk/java/awt/Graphics/LCDTextAndGraphicsState.java
41149 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 657650726* @summary Both lines of text should be readable27* @run main/manual=yesno LCDTextAndGraphicsState28*/29import java.awt.*;30import java.awt.geom.*;3132public class LCDTextAndGraphicsState extends Component {3334String text = "This test passes only if this text appears SIX TIMES";3536public void paint(Graphics g) {3738Graphics2D g2d = (Graphics2D)g.create();39g2d.setColor(Color.white);40g2d.fillRect(0,0,getSize().width, getSize().height);4142test1(g.create(0, 0, 500, 200));43test2(g.create(0, 200, 500, 200));44test3(g.create(0, 400, 500, 200));45}4647public void test1(Graphics g) {48Graphics2D g2d = (Graphics2D)g;49g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,50RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);51g2d.setColor(Color.black);52g2d.drawString(text, 10, 50);53g2d.setComposite(AlphaComposite.getInstance(54AlphaComposite.SRC_OVER, 0.9f));55g2d.drawString(text, 10, 80);56}5758public void test2(Graphics g) {59Graphics2D g2d = (Graphics2D)g;60g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,61RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);62g2d.setColor(Color.black);63g2d.drawString(text, 10, 50);64g2d.setPaint(new GradientPaint(650f, 0f, Color.BLACK, 100f, 100f, Color.GRAY));66g2d.drawString(text, 10, 80);67}6869public void test3(Graphics g) {70Graphics2D g2d = (Graphics2D)g;71g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,72RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);73g2d.setColor(Color.black);74g2d.drawString(text, 10, 50);75Shape s = new RoundRectangle2D.Double(0, 60, 400, 50, 5, 5);76g2d.clip(s);77g2d.drawString(text, 10, 80);78}7980public Dimension getPreferredSize() {81return new Dimension(500,600);82}8384public static void main(String[] args) throws Exception {8586Frame f = new Frame("Composite and Text Test");87f.add(new LCDTextAndGraphicsState(), BorderLayout.CENTER);88f.pack();89f.setVisible(true);90}91}929394