summaryrefslogtreecommitdiff
path: root/javax/swing/text/CompositeView.java
diff options
context:
space:
mode:
Diffstat (limited to 'javax/swing/text/CompositeView.java')
-rw-r--r--javax/swing/text/CompositeView.java41
1 files changed, 32 insertions, 9 deletions
diff --git a/javax/swing/text/CompositeView.java b/javax/swing/text/CompositeView.java
index cd6645215..49abbb2c8 100644
--- a/javax/swing/text/CompositeView.java
+++ b/javax/swing/text/CompositeView.java
@@ -218,20 +218,43 @@ public abstract class CompositeView
throws BadLocationException
{
int childIndex = getViewIndex(pos, bias);
+ Shape ret = null;
if (childIndex != -1)
{
View child = getView(childIndex);
- Rectangle r = a.getBounds();
- childAllocation(childIndex, r);
- Shape result = child.modelToView(pos, r, bias);
- if (result == null)
- throw new AssertionError("" + child.getClass().getName()
- + ".modelToView() must not return null");
- return result;
+ Shape childAlloc = getChildAllocation(childIndex, a);
+ if (childAlloc == null)
+ ret = createDefaultLocation(a, bias);
+ Shape result = child.modelToView(pos, childAlloc, bias);
+ if (result != null)
+ ret = result;
+ else
+ ret = createDefaultLocation(a, bias);
}
else
- throw new BadLocationException("No child view for the specified location",
- pos);
+ ret = createDefaultLocation(a, bias);
+ return ret;
+ }
+
+ /**
+ * A helper method for {@link #modelToView(int, Position.Bias, int,
+ * Position.Bias, Shape)}. This creates a default location when there is
+ * no child view that can take responsibility for mapping the position to
+ * view coordinates. Depending on the specified bias this will be the
+ * left or right edge of this view's allocation.
+ *
+ * @param a the allocation for this view
+ * @param bias the bias
+ *
+ * @return a default location
+ */
+ private Shape createDefaultLocation(Shape a, Position.Bias bias)
+ {
+ Rectangle alloc = a.getBounds();
+ Rectangle location = new Rectangle(alloc.x, alloc.y, 1, alloc.height);
+ if (bias == Position.Bias.Forward)
+ location.x = alloc.x + alloc.width;
+ return location;
}
/**