summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-10-16 11:48:46 +0000
committerRoman Kennke <roman@kennke.org>2006-10-16 11:48:46 +0000
commit3b319cf076295626b1aecafe10a8567e053788c9 (patch)
treebae41eca2d498b442794cc2bb0641f74a462eb82
parent2daa3fe76d42c8b44fd0bca62430d566d08660e5 (diff)
downloadclasspath-3b319cf076295626b1aecafe10a8567e053788c9.tar.gz
2006-10-16 Roman Kennke <kennke@aicas.com>
* javax/swing/JLabel.java (AccessibleJLabel.getIndexAtPoint): Implemented. (AccessibleJLabel.getCharacterBounds): Implemented. (AccessibleJLabel.getTextRectangle): New helper method.
-rw-r--r--ChangeLog7
-rw-r--r--javax/swing/JLabel.java68
2 files changed, 67 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 1e684cc0a..acdc32ced 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2006-10-16 Roman Kennke <kennke@aicas.com>
+ * javax/swing/JLabel.java
+ (AccessibleJLabel.getIndexAtPoint): Implemented.
+ (AccessibleJLabel.getCharacterBounds): Implemented.
+ (AccessibleJLabel.getTextRectangle): New helper method.
+
+2006-10-16 Roman Kennke <kennke@aicas.com>
+
* javax/swing/filechooser/FileSystemView.java
(getFileSystemView): Mark as implemented.
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;
}
}