source: trunk/gcc/libjava/java/awt/Label.java

Last change on this file was 1392, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.5 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;
43import java.io.Serializable;
44import javax.accessibility.Accessible;
45
46/**
47 * This component is used for displaying simple text strings that cannot
48 * be edited.
49 *
50 * @author Aaron M. Renn ([email protected])
51 * @author Tom Tromey <[email protected]>
52 */
53public class Label extends Component implements Serializable, Accessible
54{
55
56/*
57 * Static Variables
58 */
59
60/**
61 * Alignment constant aligning the text to the left of its window.
62 */
63public static final int LEFT = 0;
64
65/**
66 * Alignment constant aligning the text in the center of its window.
67 */
68public static final int CENTER = 1;
69
70/**
71 * Alignment constant aligning the text to the right of its window.
72 */
73public static final int RIGHT = 2;
74
75// Serialization version constant:
76private static final long serialVersionUID = 3094126758329070636L;
77
78/*************************************************************************/
79
80/*
81 * Instance Variables
82 */
83
84/**
85 * @serial Indicates the alignment of the text within this label's window.
86 * This is one of the constants in this class. The default value is
87 * <code>LEFT</code>.
88 */
89private int alignment;
90
91/**
92 * @serial The text displayed in the label
93 */
94private String text;
95
96/*************************************************************************/
97
98/*
99 * Constructors
100 */
101
102/**
103 * Initializes a new instance of <code>Label</code> with no text.
104 *
105 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
106 */
107public
108Label()
109{
110 this("", LEFT);
111}
112
113/*************************************************************************/
114
115/**
116 * Initializes a new instance of <code>Label</code> with the specified
117 * text that is aligned to the left.
118 *
119 * @param text The text of the label.
120 *
121 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
122 */
123public
124Label(String text)
125{
126 this(text, LEFT);
127}
128
129/*************************************************************************/
130
131/**
132 * Initializes a new instance of <code>Label</code> with the specified
133 * text and alignment.
134 *
135 * @param text The text of the label.
136 * @param alignment The desired alignment for the text in this label,
137 * which must be one of <code>LEFT</code>, <code>CENTER</code>, or
138 * <code>RIGHT</code>.
139 *
140 * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
141 */
142public
143Label(String text, int alignment)
144{
145 setAlignment (alignment);
146 setText (text);
147
148 if (GraphicsEnvironment.isHeadless())
149 throw new HeadlessException ();
150}
151
152/*************************************************************************/
153
154/*
155 * Instance Variables
156 */
157
158/**
159 * Returns the constant indicating the alignment of the text in this
160 * label. The value returned will be one of the alignment constants
161 * from this class.
162 *
163 * @return The alignment of the text in the label.
164 */
165public int
166getAlignment()
167{
168 return(alignment);
169}
170
171/*************************************************************************/
172
173/**
174 * Sets the text alignment of this label to the specified value.
175 *
176 * @param alignment The desired alignment for the text in this label,
177 * which must be one of <code>LEFT</code>, <code>CENTER</code>, or
178 * <code>RIGHT</code>.
179 */
180public synchronized void
181setAlignment(int alignment)
182{
183 if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
184 throw new IllegalArgumentException ("invalid alignment: " + alignment);
185 this.alignment = alignment;
186 if (peer != null)
187 {
188 LabelPeer lp = (LabelPeer) peer;
189 lp.setAlignment (alignment);
190 }
191}
192
193/*************************************************************************/
194
195/**
196 * Returns the text displayed in this label.
197 *
198 * @return The text for this label.
199 */
200public String
201getText()
202{
203 return(text);
204}
205
206/*************************************************************************/
207
208/**
209 * Sets the text in this label to the specified value.
210 *
211 * @param text The new text for this label.
212 */
213public synchronized void
214setText(String text)
215{
216 this.text = text;
217
218 if (peer != null)
219 {
220 LabelPeer lp = (LabelPeer) peer;
221 lp.setText (text);
222 }
223}
224
225/*************************************************************************/
226
227/**
228 * Notifies this lable that it has been added to a container, causing
229 * the peer to be created. This method is called internally by the AWT
230 * system.
231 */
232public void
233addNotify()
234{
235 if (peer == null)
236 peer = getToolkit ().createLabel (this);
237 super.addNotify ();
238}
239
240/*************************************************************************/
241
242/**
243 * Returns a parameter string useful for debugging.
244 *
245 * @param A debugging string.
246 */
247protected String
248paramString()
249{
250 return ("text=" + getText() + ",alignment=" +
251 getAlignment() + "," + super.paramString());
252}
253
254} // class Label
255
Note: See TracBrowser for help on using the repository browser.