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 und die Messung sind noch experimentell.