/* * @(#)FontDialog.java * * This file is part of webCDwriter - Network CD Writing. * * Copyright (C) 2001 Jörg P. M. Haeger * * webCDwriter is free software. See CDcreator.java for details. * * Jörg Haeger, 17.07.2001 */ import java.awt.*; import java.util.*; import javax.swing.*; class FontDialog extends JFrame { public FontDialog() { super(CDcreator.i18n("FDTitle")); setSize(600, 300); sample = CDcreator.i18n("FDTextSample"); fontView = new FontView(sample); getContentPane().add(fontView); scanner = new Thread() { public void run() { Font[] allfonts = GraphicsEnvironment .getLocalGraphicsEnvironment().getAllFonts(); for (int i = 0; i < allfonts.length; i++) { fontView.status(i, allfonts[i].getFontName()); if (allfonts[i].canDisplayUpTo(sample) == sample.length()) fontView.show(allfonts[i]); } fontView.status(0, "Ready"); } }; scanner.start(); } private String sample; private FontView fontView; private Thread scanner; } class FontView extends JComponent { public FontView(String text) { this.text = text; } public void paint(Graphics g) { g.clearRect(0, 0, getWidth(), getHeight()); g.setColor(Color.black); g.drawString("Test " + fontNo + " " + fontName, 10, 10); for (int i = 0; i < fonts.size(); i++) { g.setFont(getFont()); g.drawString(((Font)fonts.get(i)).getFontName(), 10, 40 + 20 * i); g.setFont((Font)fonts.get(i)); g.drawString(text, 400, 40 + 20 * i); } } public void show(Font font) { fonts.add(font.deriveFont((float)12.0)); paintImmediately(0, 0, getWidth(), getHeight()); } public void status(int fontNo, String fontName) { this.fontNo = fontNo; this.fontName = fontName; paintImmediately(0, 0, getWidth(), getHeight()); } int count = 0; Vector fonts = new Vector(100); String text = "text"; int fontNo; String fontName; }