source: trunk/src/gcc/libjava/java/awt/Label.java@ 154

Last change on this file since 154 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.1 KB
Line 
1/* Label.java -- Java label widget
2 Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.awt;
40
41import java.awt.peer.LabelPeer;
42import java.awt.peer.ComponentPeer;
43
44/**
45 * This component is used for displaying simple text strings that cannot
46 * be edited.
47 *
48 * @author Aaron M. Renn ([email protected])
49 * @author Tom Tromey <[email protected]>
50 */
51public class Label extends Component implements java.io.Serializable
52{
53
54/*
55 * Static Variables
56 */
57
58/**
59 * Alignment constant aligning the text to the left of its window.
60 */
61public static final int LEFT = 0;
62
63/**
64 * Alignment constant aligning the text in the center of its window.
65 */
66public static final int CENTER = 1;
67
68/**
69 * Alignment constant aligning the text to the right of its window.
70 */
71public static final int RIGHT = 2;
72
73// Serialization version constant:
74private static final long serialVersionUID = 3094126758329070636L;
75
76/*************************************************************************/
77
78/*
79 * Instance Variables
80 */
81
82/**
83 * @serial Indicates the alignment of the text within this label's window.
84 * This is one of the constants in this class. The default value is
85 * <code>LEFT</code>.
86 */
87private int alignment;
88
89/**
90 * @serial The text displayed in the label
91 */
92private String text;
93
94/*************************************************************************/
95
96/*
97 * Constructors
98 */
99
100/**
101 * Initializes a new instance of <code>Label</code> with no text.
102 */
103public
104Label()
105{
106 this("", LEFT);
107}
108
109/*************************************************************************/
110
111/**
112 * Initializes a new instance of <code>Label</code> with the specified
113 * text that is aligned to the left.
114 *
115 * @param text The text of the label.
116 */
117public
118Label(String text)
119{
120 this(text, LEFT);
121}
122
123/*************************************************************************/
124
125/**
126 * Initializes a new instance of <code>Label</code> with the specified
127 * text and alignment.
128 *
129 * @param text The text of the label.
130 * @param alignment The desired alignment for the text in this label,
131 * which must be one of <code>LEFT</code>, <code>CENTER</code>, or
132 * <code>RIGHT</code>.
133 */
134public
135Label(String text, int alignment)
136{
137 setAlignment (alignment);
138 setText (text);
139}
140
141/*************************************************************************/
142
143/*
144 * Instance Variables
145 */
146
147/**
148 * Returns the constant indicating the alignment of the text in this
149 * label. The value returned will be one of the alignment constants
150 * from this class.
151 *
152 * @return The alignment of the text in the label.
153 */
154public int
155getAlignment()
156{
157 return(alignment);
158}
159
160/*************************************************************************/
161
162/**
163 * Sets the text alignment of this label to the specified value.
164 *
165 * @param alignment The desired alignment for the text in this label,
166 * which must be one of <code>LEFT</code>, <code>CENTER</code>, or
167 * <code>RIGHT</code>.
168 */
169public synchronized void
170setAlignment(int alignment)
171{
172 if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
173 throw new IllegalArgumentException ("invalid alignment: " + alignment);
174 this.alignment = alignment;
175 if (peer != null)
176 {
177 LabelPeer lp = (LabelPeer) peer;
178 lp.setAlignment (alignment);
179 }
180}
181
182/*************************************************************************/
183
184/**
185 * Returns the text displayed in this label.
186 *
187 * @return The text for this label.
188 */
189public String
190getText()
191{
192 return(text);
193}
194
195/*************************************************************************/
196
197/**
198 * Sets the text in this label to the specified value.
199 *
200 * @param text The new text for this label.
201 */
202public synchronized void
203setText(String text)
204{
205 this.text = text;
206
207 if (peer != null)
208 {
209 LabelPeer lp = (LabelPeer) peer;
210 lp.setText (text);
211 }
212}
213
214/*************************************************************************/
215
216/**
217 * Notifies this lable that it has been added to a container, causing
218 * the peer to be created. This method is called internally by the AWT
219 * system.
220 */
221public void
222addNotify()
223{
224 if (peer == null)
225 peer = getToolkit ().createLabel (this);
226 super.addNotify ();
227}
228
229/*************************************************************************/
230
231/**
232 * Returns a parameter string useful for debugging.
233 *
234 * @param A debugging string.
235 */
236protected String
237paramString()
238{
239 return ("text=" + getText() + ",alignment=" +
240 getAlignment() + "," + super.paramString());
241}
242
243} // class Label
244
Note: See TracBrowser for help on using the repository browser.