diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-10-29 22:49:21 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-10-29 22:49:21 +0000 |
commit | e36d2a50b5a1a677c7ecaf926e73a5dac386c1ef (patch) | |
tree | 9649a7997f35624c829eccad8c84c84e9c8e3fb9 /javax/swing/JLabel.java | |
parent | be24db70d4ff66302f560e12913f5b71acf3c12c (diff) | |
download | classpath-e36d2a50b5a1a677c7ecaf926e73a5dac386c1ef.tar.gz |
2006-10-29 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD --> generics for 2006/10/04-2006/10/29.
Diffstat (limited to 'javax/swing/JLabel.java')
-rw-r--r-- | javax/swing/JLabel.java | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/javax/swing/JLabel.java b/javax/swing/JLabel.java index fcf0fd7cb..3e0f28ed7 100644 --- a/javax/swing/JLabel.java +++ b/javax/swing/JLabel.java @@ -38,13 +38,14 @@ exception statement from your version. */ package javax.swing; -import gnu.classpath.NotImplementedException; - import java.awt.Component; import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Image; +import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; +import java.awt.Shape; import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; @@ -54,8 +55,12 @@ import javax.accessibility.AccessibleExtendedComponent; import javax.accessibility.AccessibleRole; import javax.accessibility.AccessibleText; import javax.swing.plaf.LabelUI; +import javax.swing.plaf.basic.BasicHTML; import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.Position; import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.View; /** * A component that displays a static text message and/or an icon. @@ -303,10 +308,52 @@ public class JLabel extends JComponent implements Accessible, SwingConstants * @return the bounding box of the character at the specified index */ public Rectangle getCharacterBounds(int index) - throws NotImplementedException { - // FIXME: Implement this correctly. - return new Rectangle(); + Rectangle bounds = null; + View view = (View) getClientProperty(BasicHTML.propertyKey); + if (view != null) + { + Rectangle textR = getTextRectangle(); + try + { + Shape s = view.modelToView(index, textR, Position.Bias.Forward); + bounds = s.getBounds(); + } + catch (BadLocationException ex) + { + // Can't return something reasonable in this case. + } + } + return bounds; + } + + /** + * Returns the rectangle inside the JLabel, in which the actual text is + * rendered. This method has been adopted from the Mauve testcase + * gnu.testlet.javax.swing.JLabel.AccessibleJLabel.getCharacterBounds. + * + * @return the rectangle inside the JLabel, in which the actual text is + * rendered + */ + private Rectangle getTextRectangle() + { + JLabel l = JLabel.this; + Rectangle textR = new Rectangle(); + Rectangle iconR = new Rectangle(); + Insets i = l.getInsets(); + int w = l.getWidth(); + int h = l.getHeight(); + Rectangle viewR = new Rectangle(i.left, i.top, w - i.left - i.right, + h - i.top - i.bottom); + FontMetrics fm = l.getFontMetrics(l.getFont()); + SwingUtilities.layoutCompoundLabel(l, fm, l.getText(), l.getIcon(), + l.getVerticalAlignment(), + l.getHorizontalAlignment(), + l.getVerticalTextPosition(), + l.getHorizontalTextPosition(), + viewR, iconR, textR, + l.getIconTextGap()); + return textR; } /** @@ -319,10 +366,15 @@ public class JLabel extends JComponent implements Accessible, SwingConstants * point */ public int getIndexAtPoint(Point point) - throws NotImplementedException { - // FIXME: Implement this correctly. - return 0; + int index = -1; + View view = (View) getClientProperty(BasicHTML.propertyKey); + if (view != null) + { + Rectangle r = getTextRectangle(); + index = view.viewToModel(point.x, point.y, r, new Position.Bias[0]); + } + return index; } } |