FSF GCC merge 02/23/03
[official-gcc.git] / libjava / javax / swing / JLabel.java
bloba4d6fa16faf2643bc87c3938f18515cc8701ff91
1 /* JLabel.java --
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)
9 any later version.
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
19 02111-1307 USA.
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.
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. */
38 package javax.swing;
40 import java.awt.*;
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
52 String text;
53 Icon icon;
54 int gap;
55 int align;
57 int hor_align;
58 int hor_text_pos;
60 int vert_align;
61 int vert_text_pos;
63 public JLabel()
65 this("", null, 0);
68 public JLabel(Icon image)
70 this("", image, 0);
73 public JLabel(Icon image, int horizontalAlignment)
75 this("", image, horizontalAlignment);
78 public JLabel(String text)
80 this(text, null, 0);
83 public JLabel(String text, int horizontalAlignment)
85 this(text, null, horizontalAlignment);
88 public JLabel(String text, Icon icon, int horizontalAlignment)
90 // do the work.....
91 this.text = text;
92 setIcon(icon);
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.
102 return 0;
104 protected int checkVerticalKey(int key, String message)
106 // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
107 return 0;
109 public AccessibleContext getAccessibleContext()
111 // Get the AccessibleContext of this object
112 return null;
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.
117 return null;
119 public int getDisplayedMnemonic()
121 // Return the keycode that indicates a mnemonic key.
122 return 0;
124 public int getHorizontalAlignment()
126 // Returns the alignment of the label's contents along the X axis.
127 return hor_align;
129 public int getHorizontalTextPosition()
131 // Returns the horizontal position of the label's text, relative to its image.
132 return hor_text_pos;
135 public Icon getIcon()
136 { return icon; }
138 public int getIconTextGap()
140 // Returns the amount of space between the text and the icon displayed in this label.
141 return 0;
143 public Component getLabelFor()
145 // Get the component this is labelling.
146 return null;
148 public String getText()
149 { return text; }
151 public String getUIClassID()
152 { return "JLabel"; }
154 public int getVerticalAlignment()
156 // Returns the alignment of the label's contents along the Y axis.
157 return vert_align;
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.
173 return "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)
199 this.icon = icon;
200 if (icon != null)
202 // XXX FIXME - icons do not know their parent
203 // icon.setParent(this);
205 revalidate();
206 repaint();
209 public void setIconTextGap(int iconTextGap)
211 gap = iconTextGap;
214 public void setLabelFor(Component c)
216 // Set the component this is labelling.
218 public void setText(String text)
220 this.text = text;
221 revalidate();
222 repaint();
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);
238 setUI(b);