/* * @(#)FontSampler.java 2.5.0 31 August 2006 * * Copyright 2006 * College of Computer and Information Science * Northeastern University * Boston, MA 02115 * * The Java Power Tools software may be used for educational * purposes as long as this copyright notice is retained intact * at the top of all source files. * * To discuss possible commercial use of this software, * contact Richard Rasala at Northeastern University, * College of Computer and Information Science, * 617-373-2462 or rasala@ccs.neu.edu. * * The Java Power Tools software has been designed and built * in collaboration with Viera Proulx and Jeff Raab. * * Should this software be modified, the words "Modified from * Original" must be included as a comment below this notice. * * All publication rights are retained. This software or its * documentation may not be published in any media either * in whole or in part without explicit permission. * * This software was created with support from Northeastern * University and from NSF grant DUE-9950829. */ package edu.neu.ccs.gui; import java.awt.*; import java.awt.font.*; /** *
Class FontSampler creates a GUI to sample
* the fonts installed on the system. The characters shown
* are those with codes from 32 to 126.
This methods displays the characters with codes * from 32 to 126 in the graphics window using the * current font.
*/ protected void showFont() { window.clearPanel(); Graphics2D graphics = window.getBufferGraphics(); Font font = getCurrentFont(); TextPaintable paintable = new TextPaintable (null, font, null, null, TextAnchor.CENTER_BASELINE, 0, 0); for (int row = 2; row < 8; row++) { int y = deltah * (row - 1); int next = 16 * row; for (int col = 0; col <= 15; col++) { int x = deltaw * (col + 1); int code = next + col; if (code == 127) break; String s = "" + (char) (code); paintable.setString(s); paintable.setAnchorPosition(x, y); paintable.paint(graphics); } } // repaint window window.repaint(); } /** *Returns the current font based on the user * selections in the GUI of this panel.
*/ public Font getCurrentFont() { String name = fontDropdown.getViewState(); int size = fontSizeTFV.demandInt(); if (size < minimum) { size = minimum; fontSizeTFV.setViewState("" + size); } int style = (boldBox. getBooleanValue() ? Font.BOLD : 0) | (italicBox.getBooleanValue() ? Font.ITALIC : 0); return new Font(name, style, size); } /** *The main program that launches a font sampler * in its own GUI frame.
* *Use the call:
* *FontSampler.main(null)* * @param args ignored and may be
null
*/
public static void main(String[] args) {
new FontSampler().frame("Font Sampler", NORTH);
}
}