diff options
author | Anthony Balkissoon <abalkiss@redhat.com> | 2005-10-11 18:34:07 +0000 |
---|---|---|
committer | Anthony Balkissoon <abalkiss@redhat.com> | 2005-10-11 18:34:07 +0000 |
commit | 3d0cef53d2099333dfb88bc5697e5a77fb8940c2 (patch) | |
tree | 716e521ea9e5513a5e1d3ff5bacc6ae43124bde6 /javax/swing/text/PlainView.java | |
parent | 2c64bf8a0322d69af774bb922b968ad20234cc01 (diff) | |
download | classpath-3d0cef53d2099333dfb88bc5697e5a77fb8940c2.tar.gz |
2005-10-11 Anthony Balkissoon <abalkiss@redhat.com>
* javax/swing/plaf/basic/BasicTextUI.java:
(viewToModel): Implemented.
* javax/swing/text/DefaultCaret.java:
(mousePressed): Implemented.
* javax/swing/text/PlainView.java:
(viewToModel): Implemented.
Diffstat (limited to 'javax/swing/text/PlainView.java')
-rw-r--r-- | javax/swing/text/PlainView.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/javax/swing/text/PlainView.java b/javax/swing/text/PlainView.java index 71eba1730..38ac0f528 100644 --- a/javax/swing/text/PlainView.java +++ b/javax/swing/text/PlainView.java @@ -294,8 +294,32 @@ public class PlainView extends View */ public int viewToModel(float x, float y, Shape a, Position.Bias[] b) { - // FIXME: not implemented - return 0; + Rectangle rec = a.getBounds(); + Document doc = getDocument(); + Element root = doc.getDefaultRootElement(); + + // PlainView doesn't support line-wrapping so we can find out which + // Element was clicked on just by the y-position + int lineClicked = (int) (y - rec.y) / metrics.getHeight(); + if (lineClicked >= root.getElementCount()) + return getEndOffset() - 1; + + Element line = root.getElement(lineClicked); + Segment s = new Segment(); + + int start = line.getStartOffset(); + int end = line.getEndOffset(); + try + { + doc.getText(start, end - start, s); + } + catch (BadLocationException ble) + { + //this should never happen + } + + int pos = Utilities.getTabbedTextOffset(s, metrics, rec.x, (int)x, this, start); + return Math.max (0, pos); } /** |