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.Dimension;
024    import javax.swing.JTextField;
025    import net.sf.japi.swing.ActionFactory;
026    import static net.sf.japi.swing.ActionFactory.getFactory;
027    
028    /** Font Preview.
029     * Uses a localized text to display the font, but the user may edit the text to try out the characters she's interested in.
030     * This class is derived from JTextField, but never ever depend on that inheritance.
031     * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a>
032     */
033    public class FontPreview extends JTextField {
034    
035        /** Serial Version. */
036        private static final long serialVersionUID = 1L;
037    
038        /** Action Factory. */
039        private static final ActionFactory ACTION_FACTORY = getFactory("net.sf.japi.swing.font");
040    
041        /** Create a new FontPreview. */
042        public FontPreview() {
043            super(getDefaultText());
044            setHorizontalAlignment(CENTER);
045            final Dimension d = getMinimumSize();
046            d.height = 64;
047            setMinimumSize(d);
048            setPreferredSize(d);
049        }
050    
051        /** Get the default text for previewing a font.
052         * @return default text
053         */
054        public static String getDefaultText() {
055            return ACTION_FACTORY.getString("font_preview_text");
056        }
057    
058    } // class FontPreview