KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > app > Label


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.app;
31
32 /**
33  * A component which displays a text string, an icon, or both.
34  */

35 public class Label extends Component {
36
37     public static final String JavaDoc PROPERTY_ICON = "icon";
38     public static final String JavaDoc PROPERTY_ICON_TEXT_MARGIN = "iconTextMargin";
39     public static final String JavaDoc PROPERTY_LINE_WRAP = "lineWrap";
40     public static final String JavaDoc PROPERTY_TEXT = "text";
41     public static final String JavaDoc PROPERTY_TEXT_ALIGNMENT = "textAlignment";
42     public static final String JavaDoc PROPERTY_TEXT_POSITION = "textPosition";
43     public static final String JavaDoc PROPERTY_TOOL_TIP_TEXT = "toolTipText";
44
45     /**
46      * Creates a label with no text or icon.
47      */

48     public Label() {
49         this(null, null);
50     }
51     
52     /**
53      * Creates a label with text.
54      *
55      * @param text the text to be displayed
56      */

57     public Label(String JavaDoc text) {
58         this(text, null);
59     }
60     
61     /**
62      * Creates a label with an icon.
63      *
64      * @param icon the icon to be displayed
65      */

66     public Label(ImageReference icon) {
67         this(null, icon);
68     }
69
70     /**
71      * Creates a label with text and an icon.
72      *
73      * @param text the text to be displayed
74      * @param icon the icon to be displayed
75      */

76     public Label(String JavaDoc text, ImageReference icon) {
77         super();
78     
79         setIcon(icon);
80         setText(text);
81     }
82     
83     /**
84      * Returns the icon of the label.
85      *
86      * @return the icon
87      */

88     public ImageReference getIcon() {
89         return (ImageReference) getProperty(PROPERTY_ICON);
90     }
91     
92     /**
93      * Returns the margin size between the icon and the text.
94      * The margin will only be displayed if the label has both
95      * icon and text properties set.
96      *
97      * @return the margin size
98      */

99     public Extent getIconTextMargin() {
100         return (Extent) getProperty(PROPERTY_ICON_TEXT_MARGIN);
101     }
102     
103     /**
104      * Returns the text of the label.
105      *
106      * @return the text
107      */

108     public String JavaDoc getText() {
109         return (String JavaDoc) getProperty(PROPERTY_TEXT);
110     }
111
112     /**
113      * Returns the alignment of the text relative to the icon.
114      *
115      * @return the text alignment
116      */

117     public Alignment getTextAlignment() {
118         return (Alignment) getProperty(PROPERTY_TEXT_ALIGNMENT);
119     }
120
121     /**
122      * Returns the position of the text relative to the icon.
123      *
124      * @return the text position
125      */

126     public Alignment getTextPosition() {
127         return (Alignment) getProperty(PROPERTY_TEXT_POSITION);
128     }
129
130     /**
131      * Returns the tool tip text (displayed when the mouse cursor is hovered
132      * over the component).
133      *
134      * @return the tool tip text
135      */

136     public String JavaDoc getToolTipText() {
137         return (String JavaDoc) getProperty(PROPERTY_TOOL_TIP_TEXT);
138     }
139     
140     /**
141      * Determines if the text of the label should wrap in the event that
142      * horizontal space is limited. Default value is true.
143      *
144      * @return the line wrap state
145      */

146     public boolean isLineWrap() {
147         Boolean JavaDoc value = (Boolean JavaDoc) getProperty(PROPERTY_LINE_WRAP);
148         return value == null ? true : value.booleanValue();
149     }
150     
151     /**
152      * This component does not support children.
153      *
154      * @see nextapp.echo2.app.Component#isValidChild(nextapp.echo2.app.Component)
155      */

156     public boolean isValidChild(Component component) {
157         return false;
158     }
159     
160     /**
161      * Sets the icon to be displayed.
162      *
163      * @param newValue the icon to be displayed
164      */

165     public void setIcon(ImageReference newValue) {
166         setProperty(PROPERTY_ICON, newValue);
167     }
168     
169     /**
170      * Sets the margin size between the icon and the text.
171      * The margin will only be displayed if the label has both
172      * icon and text properties set.
173      *
174      * @param newValue the margin size
175      */

176     public void setIconTextMargin(Extent newValue) {
177         setProperty(PROPERTY_ICON_TEXT_MARGIN, newValue);
178     }
179     
180     /**
181      * Sets whether the text of the label should wrap in the event that
182      * horizontal space is limited. Default value is true.
183      *
184      * @param newValue the new line wrap state
185      */

186     public void setLineWrap(boolean newValue) {
187         setProperty(PROPERTY_LINE_WRAP, new Boolean JavaDoc(newValue));
188     }
189     
190     /**
191      * Sets the text to be displayed.
192      *
193      * @param newValue the text to be displayed
194      */

195     public void setText(String JavaDoc newValue) {
196         setProperty(PROPERTY_TEXT, newValue);
197     }
198     
199     /**
200      * Sets the alignment of the text relative to the icon.
201      * Note that only one of the provided <code>Alignment</code>'s
202      * settings should be non-default.
203      *
204      * @param newValue the new text position
205      */

206     public void setTextAlignment(Alignment newValue) {
207         setProperty(PROPERTY_TEXT_ALIGNMENT, newValue);
208     }
209     
210     /**
211      * Sets the position of the text relative to the icon.
212      * Note that only one of the provided <code>Alignment</code>'s
213      * settings should be non-default.
214      *
215      * @param newValue the new text position
216      */

217     public void setTextPosition(Alignment newValue) {
218         setProperty(PROPERTY_TEXT_POSITION, newValue);
219     }
220
221     /**
222      * Sets the tool tip text (displayed when the mouse cursor is hovered
223      * over the component).
224      *
225      * @param newValue the new tool tip text
226      */

227     public void setToolTipText(String JavaDoc newValue) {
228         setProperty(PROPERTY_TOOL_TIP_TEXT, newValue);
229     }
230 }
231
Popular Tags