summaryrefslogtreecommitdiff
path: root/javax
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-08-05 14:14:11 +0000
committerRoman Kennke <roman@kennke.org>2006-08-05 14:14:11 +0000
commit74f817684cb3dc50c49d4310ef2a43cb765bc88a (patch)
tree111565874075ee6afb8b086647b9dbed2b014fb6 /javax
parent643dbbc88590fe1a444992a7eeb77a74a11895d8 (diff)
downloadclasspath-74f817684cb3dc50c49d4310ef2a43cb765bc88a.tar.gz
2006-08-05 Roman Kennke <kennke@aicas.com>
* javax/swing/text/View.java (modelToView): Added special handling for corner case at the end of the view and for multiline views.
Diffstat (limited to 'javax')
-rw-r--r--javax/swing/text/View.java43
1 files changed, 40 insertions, 3 deletions
diff --git a/javax/swing/text/View.java b/javax/swing/text/View.java
index d8ad5f585..8e0a2c87d 100644
--- a/javax/swing/text/View.java
+++ b/javax/swing/text/View.java
@@ -611,9 +611,46 @@ public abstract class View implements SwingConstants
if (b2 != Position.Bias.Forward && b2 != Position.Bias.Backward)
throw new IllegalArgumentException
("b2 must be either Position.Bias.Forward or Position.Bias.Backward");
- Rectangle s1 = (Rectangle) modelToView(p1, a, b1);
- Rectangle s2 = (Rectangle) modelToView(p2, a, b2);
- return SwingUtilities.computeUnion(s1.x, s1.y, s1.width, s1.height, s2);
+
+ Shape s1 = modelToView(p1, a, b1);
+ // Special case for p2 == end index.
+ Shape s2;
+ if (p2 != getEndOffset())
+ {
+ s2 = modelToView(p2, a, b2);
+ }
+ else
+ {
+ try
+ {
+ s2 = modelToView(p2, a, b2);
+ }
+ catch (BadLocationException ex)
+ {
+ // Assume the end rectangle to be at the right edge of the
+ // view.
+ Rectangle aRect = a instanceof Rectangle ? (Rectangle) a
+ : a.getBounds();
+ s2 = new Rectangle(aRect.x + aRect.width - 1, aRect.y, 1,
+ aRect.height);
+ }
+ }
+
+ // Need to modify the rectangle, so we create a copy in all cases.
+ Rectangle r1 = s1.getBounds();
+ Rectangle r2 = s2 instanceof Rectangle ? (Rectangle) s2
+ : s2.getBounds();
+
+ // For multiline view, let the resulting rectangle span the whole view.
+ if (r1.y != r2.y)
+ {
+ Rectangle aRect = a instanceof Rectangle ? (Rectangle) a
+ : a.getBounds();
+ r1.x = aRect.x;
+ r1.width = aRect.width;
+ }
+
+ return SwingUtilities.computeUnion(r2.x, r2.y, r2.width, r2.height, r1);
}
/**