--- /dev/null
+/*
+ * jSite2 - FontList.java -
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.jsite.gui;
+
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.GraphicsEnvironment;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+
+/**
+ * Combobox that displays a list of all available fonts, showing the name of the
+ * font in the font itself.
+ *
+ * @see GraphicsEnvironment#getAllFonts()
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ * @version $Id$
+ */
+public class FontComboBox extends JComboBox {
+
+ /**
+ * Creates a new font combo box.
+ */
+ public FontComboBox() {
+ super();
+ Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
+ String[] fontNames = new String[allFonts.length];
+ int fontIndex = 0;
+ for (Font font: allFonts) {
+ fontNames[fontIndex++] = font.getName();
+ }
+ setModel(new DefaultComboBoxModel(fontNames));
+ setRenderer(new FontCellRenderer());
+ }
+
+ /**
+ * The cell renderer for the font name cells.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ * @version $Id$
+ */
+ private static class FontCellRenderer extends JLabel implements ListCellRenderer {
+
+ /**
+ * Creates a new list cell renderer.
+ */
+ public FontCellRenderer() {
+ setOpaque(true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ Font font = Font.decode((String) value);
+ setFont(font);
+ setText((String) value);
+ setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
+ setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
+ return this;
+ }
+
+ }
+
+}