1 | /* JLabel.java --
|
---|
2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This file is part of GNU Classpath.
|
---|
5 |
|
---|
6 | GNU Classpath is free software; you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | any later version.
|
---|
10 |
|
---|
11 | GNU Classpath is distributed in the hope that it will be useful, but
|
---|
12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
---|
18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 USA.
|
---|
20 |
|
---|
21 | Linking this library statically or dynamically with other modules is
|
---|
22 | making a combined work based on this library. Thus, the terms and
|
---|
23 | conditions of the GNU General Public License cover the whole
|
---|
24 | combination.
|
---|
25 |
|
---|
26 | As a special exception, the copyright holders of this library give you
|
---|
27 | permission to link this library with independent modules to produce an
|
---|
28 | executable, regardless of the license terms of these independent
|
---|
29 | modules, and to copy and distribute the resulting executable under
|
---|
30 | terms of your choice, provided that you also meet, for each linked
|
---|
31 | independent module, the terms and conditions of the license of that
|
---|
32 | module. An independent module is a module which is not derived from
|
---|
33 | or based on this library. If you modify this library, you may extend
|
---|
34 | this exception to your version of the library, but you are not
|
---|
35 | obligated to do so. If you do not wish to do so, delete this
|
---|
36 | exception statement from your version. */
|
---|
37 |
|
---|
38 | package javax.swing;
|
---|
39 |
|
---|
40 | import java.awt.*;
|
---|
41 | import javax.swing.plaf.*;
|
---|
42 |
|
---|
43 |
|
---|
44 | import javax.accessibility.AccessibleContext;
|
---|
45 | import javax.accessibility.AccessibleRole;
|
---|
46 | import javax.accessibility.AccessibleState;
|
---|
47 | import javax.accessibility.AccessibleStateSet;
|
---|
48 |
|
---|
49 |
|
---|
50 | public 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 | }
|
---|