001    /* JAPI - (Yet another (hopefully) useful) Java API
002     *
003     * Copyright (C) 2004-2006 Christian Hujer
004     *
005     * This program is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU General Public License as
007     * published by the Free Software Foundation; either version 2 of the
008     * License, or (at your option) any later version.
009     *
010     * This program is distributed in the hope that it will be useful, but
011     * WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013     * General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018     * 02111-1307, USA.
019     */
020    
021    package net.sf.japi.swing.font;
022    
023    import java.awt.Component;
024    import java.awt.Font;
025    import java.util.Map;
026    import javax.swing.JList;
027    import javax.swing.DefaultListCellRenderer;
028    
029    /** List cell renderer for letting the user choose the font family.
030     * This list cell renderer displays each font in its font.
031     * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a>
032     * @version $Id: FontFamilyListCellRenderer.java,v 1.1 2006/03/26 01:26:27 christianhujer Exp $
033     */
034    public class FontFamilyListCellRenderer extends DefaultListCellRenderer {
035    
036        /** Serial Version. */
037        private static final long serialVersionUID = 1L;
038    
039        /** The fonts to render.
040         * @serial include
041         */
042        private Map<String,Font> fonts;
043    
044        /** Set the fonts to render.
045         * The key of the map is the family name, the value of the map is the font to render.
046         * @param fonts fonts to render
047         */
048        public void setFonts(final Map<String,Font> fonts) {
049            this.fonts = fonts;
050        }
051    
052        /** {@inheritDoc} */
053        @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
054            final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
055            //Font f = FontFamilyComboBox.this.getFont();
056            //c.setFont(new Font((String)value, f.getStyle(), f.getSize()));
057            c.setFont(fonts.get((String)value));
058            return c;
059        }
060    
061    } // class FontFamilyCellRenderer