source: trunk/gcc/libjava/javax/swing/JLabel.java

Last change on this file was 1389, checked in by bird, 21 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.7 KB
Line 
1/* JLabel.java --
2 Copyright (C) 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
38package javax.swing;
39
40import java.awt.*;
41import javax.swing.plaf.*;
42
43
44import javax.accessibility.AccessibleContext;
45import javax.accessibility.AccessibleRole;
46import javax.accessibility.AccessibleState;
47import javax.accessibility.AccessibleStateSet;
48
49
50public class JLabel extends JComponent implements SwingConstants
51{
52 String text;
53 Icon icon;
54 int gap;
55 int align;
56
57 int hor_align;
58 int hor_text_pos;
59
60 int vert_align;
61 int vert_text_pos;
62
63 public JLabel()
64 {
65 this("", null, 0);
66 }
67
68 public JLabel(Icon image)
69 {
70 this("", image, 0);
71 }
72
73 public JLabel(Icon image, int horizontalAlignment)
74 {
75 this("", image, horizontalAlignment);
76 }
77
78 public JLabel(String text)
79 {
80 this(text, null, 0);
81 }
82
83 public JLabel(String text, int horizontalAlignment)
84 {
85 this(text, null, horizontalAlignment);
86 }
87
88 public JLabel(String text, Icon icon, int horizontalAlignment)
89 {
90 // do the work.....
91 this.text = text;
92 setIcon(icon);
93 this.align = horizontalAlignment;
94
95 updateUI(); // get a proper ui
96 }
97
98
99 protected int checkHorizontalKey(int key, String message)
100 {
101 // Verify that key is a legal value for the horizontalAlignment properties.
102 return 0;
103 }
104 protected int checkVerticalKey(int key, String message)
105 {
106 // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
107 return 0;
108 }
109 public AccessibleContext getAccessibleContext()
110 {
111 // Get the AccessibleContext of this object
112 return null;
113 }
114 public Icon getDisabledIcon()
115 {
116 // Returns the value of the disabledIcon property if it's been set, If it hasn't been set and the value of the icon property is an ImageIcon, we compute a "grayed out" version of the icon and update the disabledIcon property with that.
117 return null;
118 }
119 public int getDisplayedMnemonic()
120 {
121 // Return the keycode that indicates a mnemonic key.
122 return 0;
123 }
124 public int getHorizontalAlignment()
125 {
126 // Returns the alignment of the label's contents along the X axis.
127 return hor_align;
128 }
129 public int getHorizontalTextPosition()
130 {
131 // Returns the horizontal position of the label's text, relative to its image.
132 return hor_text_pos;
133 }
134
135 public Icon getIcon()
136 { return icon; }
137
138 public int getIconTextGap()
139 {
140 // Returns the amount of space between the text and the icon displayed in this label.
141 return 0;
142 }
143 public Component getLabelFor()
144 {
145 // Get the component this is labelling.
146 return null;
147 }
148 public String getText()
149 { return text; }
150
151 public String getUIClassID()
152 { return "JLabel"; }
153
154 public int getVerticalAlignment()
155 {
156 // Returns the alignment of the label's contents along the Y axis.
157 return vert_align;
158 }
159 public int getVerticalTextPosition()
160 {
161 // Returns the vertical position of the label's text, relative to its image.
162 return vert_text_pos;
163 }
164
165 public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
166 {
167 // This is overriden to return false if the current Icon's Image is not equal to the passed in Image img.
168 return (img == icon);
169 }
170 protected String paramString()
171 {
172 // Returns a string representation of this JLabel.
173 return "JLabel";
174 }
175 public void setDisabledIcon(Icon disabledIcon)
176 {
177 // Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)).
178 }
179 public void setDisplayedMnemonic(char aChar)
180 {
181 // Specifies the displayedMnemonic as a char value.
182 }
183 public void setDisplayedMnemonic(int key)
184 {
185 // Specify a keycode that indicates a mnemonic key.
186 }
187 public void setHorizontalAlignment(int alignment)
188 {
189 // Sets the alignment of the label's contents along the X axis.
190 hor_align = alignment;
191 }
192 public void setHorizontalTextPosition(int textPosition)
193 {
194 // Sets the horizontal position of the label's text, relative to its image.
195 hor_text_pos = textPosition;
196 }
197 public void setIcon(Icon icon)
198 {
199 this.icon = icon;
200 if (icon != null)
201 {
202 // XXX FIXME - icons do not know their parent
203// icon.setParent(this);
204 }
205 revalidate();
206 repaint();
207 }
208
209 public void setIconTextGap(int iconTextGap)
210 {
211 gap = iconTextGap;
212 }
213
214 public void setLabelFor(Component c)
215 {
216 // Set the component this is labelling.
217 }
218 public void setText(String text)
219 {
220 this.text = text;
221 revalidate();
222 repaint();
223 }
224
225 public void setVerticalAlignment(int alignment)
226 {
227 // Sets the alignment of the label's contents along the Y axis.
228 vert_align = alignment;
229 }
230 public void setVerticalTextPosition(int textPosition)
231 {
232 // Sets the vertical position of the label's text, relative to its image.
233 vert_text_pos = textPosition;
234 }
235 public void updateUI()
236 {
237 LabelUI b = (LabelUI)UIManager.getUI(this);
238 setUI(b);
239 }
240}
Note: See TracBrowser for help on using the repository browser.