1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
6  *
7  * Project Info:  http://www.jfree.org/jcommon/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------------
28  * FontDisplayField.java
29  * ---------------------
30  * (C) Copyright 2000-2008, by Object Refinery Limited.
31  *
32  * Original Author:  David Gilbert (for Object Refinery Limited);
33  * Contributor(s):   Arnaud Lelievre;
34  *
35  * $Id: FontDisplayField.java,v 1.6 2008/12/18 09:57:32 mungady Exp $
36  *
37  * Changes (from 26-Oct-2001)
38  * ----------------------------------
39  * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
40  * 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
41  * 08-Sep-2003 : Added internationalization via use of properties
42  *               resourceBundle (RFE 690236) (AL);
43  * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by
44  *               Jess Thrysoee (DG);
45  *
46  */
47 
48 package org.jfree.ui;
49 
50 import java.awt.Font;
51 import java.util.ResourceBundle;
52 
53 import javax.swing.JTextField;
54 
55 import org.jfree.util.ResourceBundleWrapper;
56 
57 /**
58  * A field for displaying a font selection.  The display field itself is
59  * read-only, to the developer must provide another mechanism to allow the
60  * user to change the font.
61  *
62  * @author David Gilbert
63  */
64 public class FontDisplayField extends JTextField {
65 
66     /** The current font. */
67     private Font displayFont;
68 
69     /** The resourceBundle for the localization. */
70     protected static final ResourceBundle localizationResources =
71             ResourceBundleWrapper.getBundle("org.jfree.ui.LocalizationBundle");
72 
73     /**
74      * Standard constructor - builds a FontDescriptionField initialised with
75      * the specified font.
76      *
77      * @param font  the font.
78      */
FontDisplayField(final Font font)79     public FontDisplayField(final Font font) {
80         super("");
81         setDisplayFont(font);
82         setEnabled(false);
83     }
84 
85     /**
86      * Returns the current font.
87      *
88      * @return the font.
89      */
getDisplayFont()90     public Font getDisplayFont() {
91         return this.displayFont;
92     }
93 
94     /**
95      * Sets the font.
96      *
97      * @param font  the font.
98      */
setDisplayFont(final Font font)99     public void setDisplayFont(final Font font) {
100         this.displayFont = font;
101         setText(fontToString(this.displayFont));
102     }
103 
104     /**
105      * Returns a string representation of the specified font.
106      *
107      * @param font  the font.
108      *
109      * @return a string describing the font.
110      */
fontToString(final Font font)111     private String fontToString(final Font font) {
112         if (font != null) {
113             return font.getFontName() + ", " + font.getSize();
114         }
115         else {
116             return localizationResources.getString("No_Font_Selected");
117         }
118     }
119 
120 }
121