2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / javax / swing / JLabel.java
blobc49615c463888c9c54b6cfabbb63ef222dd8fb67
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. */
39 package javax.swing;
41 import java.awt.Component;
42 import java.awt.Image;
43 import javax.accessibility.Accessible;
44 import javax.accessibility.AccessibleContext;
45 import javax.swing.plaf.LabelUI;
47 public class JLabel extends JComponent implements Accessible, SwingConstants
49 String text;
50 Icon icon;
51 int gap;
52 int align;
54 int hor_align;
55 int hor_text_pos;
57 int vert_align;
58 int vert_text_pos;
60 public JLabel()
62 this("", null, 0);
65 public JLabel(Icon image)
67 this("", image, 0);
70 public JLabel(Icon image, int horizontalAlignment)
72 this("", image, horizontalAlignment);
75 public JLabel(String text)
77 this(text, null, 0);
80 public JLabel(String text, int horizontalAlignment)
82 this(text, null, horizontalAlignment);
85 public JLabel(String text, Icon icon, int horizontalAlignment)
87 // do the work.....
88 this.text = text;
89 setIcon(icon);
90 this.align = horizontalAlignment;
92 updateUI(); // get a proper ui
96 protected int checkHorizontalKey(int key, String message)
98 // Verify that key is a legal value for the horizontalAlignment properties.
99 return 0;
101 protected int checkVerticalKey(int key, String message)
103 // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
104 return 0;
106 public AccessibleContext getAccessibleContext()
108 // Get the AccessibleContext of this object
109 return null;
111 public Icon getDisabledIcon()
113 // 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.
114 return null;
116 public int getDisplayedMnemonic()
118 // Return the keycode that indicates a mnemonic key.
119 return 0;
121 public int getHorizontalAlignment()
123 // Returns the alignment of the label's contents along the X axis.
124 return hor_align;
126 public int getHorizontalTextPosition()
128 // Returns the horizontal position of the label's text, relative to its image.
129 return hor_text_pos;
132 public Icon getIcon()
133 { return icon; }
135 public int getIconTextGap()
137 // Returns the amount of space between the text and the icon displayed in this label.
138 return 0;
140 public Component getLabelFor()
142 // Get the component this is labelling.
143 return null;
145 public String getText()
146 { return text; }
148 public String getUIClassID()
149 { return "JLabel"; }
151 public int getVerticalAlignment()
153 // Returns the alignment of the label's contents along the Y axis.
154 return vert_align;
156 public int getVerticalTextPosition()
158 // Returns the vertical position of the label's text, relative to its image.
159 return vert_text_pos;
162 public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
164 // This is overriden to return false if the current Icon's Image is not equal to the passed in Image img.
165 return (img == icon);
167 protected String paramString()
169 // Returns a string representation of this JLabel.
170 return "JLabel";
172 public void setDisabledIcon(Icon disabledIcon)
174 // Set the icon to be displayed if this JLabel is "disabled" (JLabel.setEnabled(false)).
176 public void setDisplayedMnemonic(char aChar)
178 // Specifies the displayedMnemonic as a char value.
180 public void setDisplayedMnemonic(int key)
182 // Specify a keycode that indicates a mnemonic key.
184 public void setHorizontalAlignment(int alignment)
186 // Sets the alignment of the label's contents along the X axis.
187 hor_align = alignment;
189 public void setHorizontalTextPosition(int textPosition)
191 // Sets the horizontal position of the label's text, relative to its image.
192 hor_text_pos = textPosition;
194 public void setIcon(Icon icon)
196 this.icon = icon;
197 if (icon != null)
199 // XXX FIXME - icons do not know their parent
200 // icon.setParent(this);
202 revalidate();
203 repaint();
206 public void setIconTextGap(int iconTextGap)
208 gap = iconTextGap;
211 public void setLabelFor(Component c)
213 // Set the component this is labelling.
215 public void setText(String text)
217 this.text = text;
218 revalidate();
219 repaint();
222 public void setVerticalAlignment(int alignment)
224 // Sets the alignment of the label's contents along the Y axis.
225 vert_align = alignment;
227 public void setVerticalTextPosition(int textPosition)
229 // Sets the vertical position of the label's text, relative to its image.
230 vert_text_pos = textPosition;
232 public void updateUI()
234 LabelUI b = (LabelUI)UIManager.getUI(this);
235 setUI(b);