2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
41 import javax
.swing
.plaf
.*;
44 import javax
.accessibility
.AccessibleContext
;
45 import javax
.accessibility
.AccessibleRole
;
46 import javax
.accessibility
.AccessibleState
;
47 import javax
.accessibility
.AccessibleStateSet
;
50 public class JLabel
extends JComponent
implements SwingConstants
68 public JLabel(Icon image
)
73 public JLabel(Icon image
, int horizontalAlignment
)
75 this("", image
, horizontalAlignment
);
78 public JLabel(String text
)
83 public JLabel(String text
, int horizontalAlignment
)
85 this(text
, null, horizontalAlignment
);
88 public JLabel(String text
, Icon icon
, int horizontalAlignment
)
93 this.align
= horizontalAlignment
;
95 updateUI(); // get a proper ui
99 protected int checkHorizontalKey(int key
, String message
)
101 // Verify that key is a legal value for the horizontalAlignment properties.
104 protected int checkVerticalKey(int key
, String message
)
106 // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
109 public AccessibleContext
getAccessibleContext()
111 // Get the AccessibleContext of this object
114 public Icon
getDisabledIcon()
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.
119 public int getDisplayedMnemonic()
121 // Return the keycode that indicates a mnemonic key.
124 public int getHorizontalAlignment()
126 // Returns the alignment of the label's contents along the X axis.
129 public int getHorizontalTextPosition()
131 // Returns the horizontal position of the label's text, relative to its image.
135 public Icon
getIcon()
138 public int getIconTextGap()
140 // Returns the amount of space between the text and the icon displayed in this label.
143 public Component
getLabelFor()
145 // Get the component this is labelling.
148 public String
getText()
151 public String
getUIClassID()
154 public int getVerticalAlignment()
156 // Returns the alignment of the label's contents along the Y axis.
159 public int getVerticalTextPosition()
161 // Returns the vertical position of the label's text, relative to its image.
162 return vert_text_pos
;
165 public boolean imageUpdate(Image img
, int infoflags
, int x
, int y
, int w
, int h
)
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
);
170 protected String
paramString()
172 // Returns a string representation of this JLabel.
175 public void setDisabledIcon(Icon disabledIcon
)
177 // Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)).
179 public void setDisplayedMnemonic(char aChar
)
181 // Specifies the displayedMnemonic as a char value.
183 public void setDisplayedMnemonic(int key
)
185 // Specify a keycode that indicates a mnemonic key.
187 public void setHorizontalAlignment(int alignment
)
189 // Sets the alignment of the label's contents along the X axis.
190 hor_align
= alignment
;
192 public void setHorizontalTextPosition(int textPosition
)
194 // Sets the horizontal position of the label's text, relative to its image.
195 hor_text_pos
= textPosition
;
197 public void setIcon(Icon icon
)
202 // XXX FIXME - icons do not know their parent
203 // icon.setParent(this);
209 public void setIconTextGap(int iconTextGap
)
214 public void setLabelFor(Component c
)
216 // Set the component this is labelling.
218 public void setText(String text
)
225 public void setVerticalAlignment(int alignment
)
227 // Sets the alignment of the label's contents along the Y axis.
228 vert_align
= alignment
;
230 public void setVerticalTextPosition(int textPosition
)
232 // Sets the vertical position of the label's text, relative to its image.
233 vert_text_pos
= textPosition
;
235 public void updateUI()
237 LabelUI b
= (LabelUI
)UIManager
.getUI(this);