KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SLabel


1 /*
2  * $Id: SLabel.java,v 1.14 2005/05/26 13:18:08 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16 import org.wings.plaf.LabelCG;
17
18 /**
19  * A display area for a short text string or an image, or both.
20  * You can specify where in the label's display area the label's contents
21  * are aligned by setting the vertical and horizontal alignment.
22  * You can also specify the position of the text relative to the image.
23  *
24  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
25  * @version $Revision: 1.14 $
26  */

27 public class SLabel extends SComponent {
28     
29     /**
30      * The text to be displayed
31      */

32     protected String JavaDoc text;
33
34     /**
35      * The icon to be displayed
36      */

37     protected SIcon icon = null;
38
39     protected SIcon disabledIcon = null;
40
41     private int verticalTextPosition = SConstants.CENTER;
42     private int horizontalTextPosition = SConstants.RIGHT;
43     private int iconTextGap = 1;
44     private boolean imageAbsBottom = false;
45
46     /**
47      * Creates a new <code>SLabel</code> instance with the specified text
48      * (left alligned) and no icon.
49      *
50      * @param text The text to be displayed by the label.
51      */

52     public SLabel(String JavaDoc text) {
53         this(text, null, SConstants.LEFT);
54     }
55
56     /**
57      * Creates a new <code>SLabel</code> instance with no text and no icon.
58      */

59     public SLabel() {
60         this((String JavaDoc) null);
61     }
62
63     /**
64      * Creates a new <code>SLabel</code> instance with the specified icon
65      * (left alligned) and no text.
66      *
67      * @param icon The image to be displayed by the label.
68      */

69     public SLabel(SIcon icon) {
70         this(icon, SConstants.LEFT);
71     }
72
73     /**
74      * Creates a new <code>SLabel</code> instance with the specified icon
75      * (alligned as specified) and no text.
76      *
77      * @param icon The image to be displayed by the label.
78      * @param horizontalAlignment One of the following constants defined in
79      * <code>SConstants</code>:
80      * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
81      * @see SConstants
82      */

83     public SLabel(SIcon icon, int horizontalAlignment) {
84         this(null, icon, horizontalAlignment);
85     }
86
87     /**
88      * Creates a new <code>SLabel</code> instance with the specified icon
89      * and the specified text (left alligned).
90      *
91      * @param text The text to be displayed by the label.
92      * @param icon The image to be displayed by the label.
93      */

94     public SLabel(String JavaDoc text, SIcon icon) {
95         this(text, icon, SConstants.LEFT);
96     }
97
98     /**
99      * Creates a new <code>SLabel</code> instance with the specified icon
100      * and the specified text (alligned as specified).
101      *
102      * @param text The text to be displayed by the label.
103      * @param icon The image to be displayed by the label.
104      * @param horizontalAlignment One of the following constants defined in
105      * <code>SConstants</code>:
106      * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
107      * @see SConstants
108      */

109     public SLabel(String JavaDoc text, SIcon icon, int horizontalAlignment) {
110         setText(text);
111         setIcon(icon);
112         setHorizontalAlignment(horizontalAlignment);
113     }
114
115     /**
116      * Creates a new <code>SLabel</code> instance with the specified text
117      * (alligned as specified) and no icon.
118      *
119      * @param text The text to be displayed by the label.
120      * @param horizontalAlignment One of the following constants defined in
121      * <code>SConstants</code>:
122      * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
123      * @see SConstants
124      */

125     public SLabel(String JavaDoc text, int horizontalAlignment) {
126         this(text, null, horizontalAlignment);
127     }
128
129
130     public void setImageAbsBottom(boolean t) {
131         imageAbsBottom = t;
132     }
133
134
135     public boolean isImageAbsBottom() {
136         return imageAbsBottom;
137     }
138
139     /**
140      * Returns the horizontal position of the lable's text
141      *
142      * @return the position
143      * @see SConstants
144      * @see #setHorizontalTextPosition
145      */

146     public int getHorizontalTextPosition() {
147         return horizontalTextPosition;
148     }
149
150     /**
151      * Sets the horizontal position of the lable's text, relative to its icon.
152      * <p/>
153      * The default value of this property is CENTER.
154      *
155      * @param textPosition One of the following constants defined in
156      * <code>SConstants</code>:
157      * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
158      */

159     public void setHorizontalTextPosition(int textPosition) {
160         horizontalTextPosition = textPosition;
161     }
162
163     /**
164      * Sets the vertical position of the lable's text, relative to its icon.
165      * <p/>
166      * The default value of this property is CENTER.
167      *
168      * @param textPosition One of the following constants defined in
169      * <code>SConstants</code>:
170      * <code>TOP</code>, <code>CENTER</code>, <code>BOTTOM</code>.
171      */

172     public void setVerticalTextPosition(int textPosition) {
173         verticalTextPosition = textPosition;
174     }
175
176     /**
177      * Returns the vertical position of the label's text
178      *
179      * @return the position
180      * @see SConstants
181      * @see #setVerticalTextPosition
182      */

183     public int getVerticalTextPosition() {
184         return verticalTextPosition;
185     }
186
187     public void setIconTextGap(int gap) {
188         iconTextGap = gap;
189     }
190
191     public int getIconTextGap() {
192         return iconTextGap;
193     }
194
195     public void setIcon(SIcon i) {
196         reloadIfChange(icon, i);
197         icon = i;
198     }
199
200     public SIcon getIcon() {
201         return icon;
202     }
203
204     public void setDisabledIcon(SIcon i) {
205         reloadIfChange(disabledIcon, i);
206         disabledIcon = i;
207     }
208
209     public SIcon getDisabledIcon() {
210         return disabledIcon;
211     }
212
213     /**
214      * Returns the text of the label
215      */

216     public String JavaDoc getText() {
217         return text;
218     }
219
220     /**
221      * Sets the text of the label. If the value of text is null or an empty
222      * string, nothing is displayed.
223      *
224      * @param t The new text
225      */

226     public void setText(String JavaDoc t) {
227         reloadIfChange(text, t);
228         text = t;
229     }
230
231     public void setCG(LabelCG cg) {
232         super.setCG(cg);
233     }
234 }
235
236
237
Popular Tags