KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > FontDisplayField


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, 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-2004, 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.4 2005/11/16 15:58:41 taqua 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 resourceBundle (RFE 690236) (AL);
42  *
43  */

44
45 package org.jfree.ui;
46
47 import java.awt.Font JavaDoc;
48 import java.util.ResourceBundle JavaDoc;
49
50 import javax.swing.JTextField JavaDoc;
51
52 /**
53  * A field for displaying a font selection. The display field itself is read-only, to the developer
54  * must provide another mechanism to allow the user to change the font.
55  *
56  * @author David Gilbert
57  */

58 public class FontDisplayField extends JTextField JavaDoc {
59
60     /** The current font. */
61     private Font JavaDoc displayFont;
62
63     /** The resourceBundle for the localization. */
64     protected static final ResourceBundle JavaDoc localizationResources =
65         ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle");
66
67     /**
68      * Standard constructor - builds a FontDescriptionField initialised with the specified font.
69      *
70      * @param font the font.
71      */

72     public FontDisplayField(final Font JavaDoc font) {
73         super("");
74         setDisplayFont(font);
75         setEnabled(false);
76     }
77
78     /**
79      * Returns the current font.
80      *
81      * @return the font.
82      */

83     public Font JavaDoc getDisplayFont() {
84         return this.displayFont;
85     }
86
87     /**
88      * Sets the font.
89      *
90      * @param font the font.
91      */

92     public void setDisplayFont(final Font JavaDoc font) {
93         this.displayFont = font;
94         setText(fontToString(this.displayFont));
95     }
96
97     /**
98      * Returns a string representation of the specified font.
99      *
100      * @param font the font.
101      *
102      * @return a string describing the font.
103      */

104     private String JavaDoc fontToString(final Font JavaDoc font) {
105         if (font != null) {
106             return font.getFontName() + ", " + font.getSize();
107         }
108         else {
109             return localizationResources.getString("No_Font_Selected");
110         }
111     }
112
113 }
114
Popular Tags