/* * Copyright (c) 2007, 2022, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 6263951 * @summary Text should be B&W, grayscale, and LCD. * @requires (os.family != "mac") * @run main/manual TextAAHintsTest
*/
privatestaticfinal String black = "This text should be solid black"; privatestaticfinal String gray = "This text should be gray scale anti-aliased"; privatestaticfinal String lcd = "This text should be LCD sub-pixel text (coloured)."; privatestaticfinal CountDownLatch countDownLatch = new CountDownLatch(1); privatestaticvolatile String failureReason; privatestaticvolatileboolean testPassed = false; privatestatic Frame frame;
/* For visual comparison, render grayscale with graphics AA off */
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.drawString(gray, 10, 65);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
publicvoid volatileImageText(Graphics g) {
VolatileImage image = getVolatileImage(500, 100); if (image == null) { return;
} boolean painted = false; while (!painted) { int status = image.validate(getGraphicsConfiguration()); if (status == VolatileImage.IMAGE_INCOMPATIBLE) {
image = getVolatileImage(500, 100); if (image == null) { return;
}
}
drawText(image.createGraphics());
g.drawImage(image, 0, 0, null);
painted = !image.contentsLost();
System.out.println("painted = " + painted);
}
}
public Dimension getPreferredSize() { returnnew Dimension(500,300);
}
publicstaticvoid createTestUI() {
frame = new Frame("Composite and Text Test");
TextAAHintsTest textAAHintsTestObject = new TextAAHintsTest();
frame.add(textAAHintsTestObject, BorderLayout.NORTH);
String instructions = """
Note: Texts are rendered with different TEXT_ANTIALIASING &
VALUE_TEXT_ANTIALIAS. Text should be B&W, grayscale, and LCD.
Note: The results may be visually the same.
1. Verify that first set of text are rendered correctly.
2. Second set of text are created using BufferedImage of the first text.
3. Third set of text are created using VolatileImage of the first text. """;
TextArea instructionTextArea = new TextArea(instructions, 8, 50);
instructionTextArea.setEditable(false);
frame.add(instructionTextArea, BorderLayout.CENTER);
publicstaticvoid getFailureReason() { // Show dialog to read why the testcase was failed and append the // testcase failure reason to the output final Dialog dialog = new Dialog(frame, "TestCase" + " failure reason", true);
TextArea textArea = new TextArea("", 5, 60, TextArea.SCROLLBARS_BOTH);
dialog.add(textArea, BorderLayout.CENTER);
publicstaticvoid main(String[] args) throws InterruptedException, InvocationTargetException {
EventQueue.invokeAndWait(TextAAHintsTest::createTestUI); if (!countDownLatch.await(2, TimeUnit.MINUTES)) {
EventQueue.invokeAndWait(() -> { if (frame != null) {
frame.dispose();
}
}); thrownew RuntimeException("Timeout : No action was taken on the test.");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.