aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/text/CompositeView.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/text/CompositeView.java')
-rw-r--r--libjava/classpath/javax/swing/text/CompositeView.java66
1 files changed, 51 insertions, 15 deletions
diff --git a/libjava/classpath/javax/swing/text/CompositeView.java b/libjava/classpath/javax/swing/text/CompositeView.java
index 6776c95727a..bc626a40696 100644
--- a/libjava/classpath/javax/swing/text/CompositeView.java
+++ b/libjava/classpath/javax/swing/text/CompositeView.java
@@ -62,7 +62,7 @@ public abstract class CompositeView
/**
* The allocation of this <code>View</code> minus its insets. This is
* initialized in {@link #getInsideAllocation} and reused and modified in
- * {@link childAllocation}.
+ * {@link #childAllocation(int, Rectangle)}.
*/
Rectangle insideAllocation;
@@ -221,20 +221,17 @@ public abstract class CompositeView
if (childIndex != -1)
{
View child = getView(childIndex);
- Shape result = child.modelToView(pos, a, bias);
+ 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;
}
else
- {
- // FIXME: Handle the case when we have no child view for the given
- // position.
- throw new AssertionError("No child views found where child views are "
- + "expected. pos = " + pos + ", bias = "
- + bias);
- }
+ throw new BadLocationException("No child view for the specified location",
+ pos);
}
/**
@@ -314,6 +311,7 @@ public abstract class CompositeView
*/
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
int direction, Position.Bias[] biasRet)
+ throws BadLocationException
{
int retVal = -1;
switch (direction)
@@ -433,10 +431,16 @@ public abstract class CompositeView
*/
protected int getViewIndexAtPosition(int pos)
{
- // We have one child view allocated for each child element in
- // loadChildren(), so this should work.
- Element el = getElement();
- int index = el.getElementIndex(pos);
+ int index = -1;
+ for (int i = 0; i < children.length; i++)
+ {
+ if (children[i].getStartOffset() <= pos
+ && children[i].getEndOffset() > pos)
+ {
+ index = i;
+ break;
+ }
+ }
return index;
}
@@ -473,8 +477,8 @@ public abstract class CompositeView
insideAllocation = inside;
}
}
- inside.x = alloc.x - insets.left;
- inside.y = alloc.y - insets.top;
+ inside.x = alloc.x + insets.left;
+ inside.y = alloc.y + insets.top;
inside.width = alloc.width - insets.left - insets.right;
inside.height = alloc.height - insets.top - insets.bottom;
return inside;
@@ -594,6 +598,7 @@ public abstract class CompositeView
protected int getNextNorthSouthVisualPositionFrom(int pos, Position.Bias b,
Shape a, int direction,
Position.Bias[] biasRet)
+ throws BadLocationException
{
// FIXME: Implement this correctly.
return pos;
@@ -627,6 +632,7 @@ public abstract class CompositeView
protected int getNextEastWestVisualPositionFrom(int pos, Position.Bias b,
Shape a, int direction,
Position.Bias[] biasRet)
+ throws BadLocationException
{
// FIXME: Implement this correctly.
return pos;
@@ -649,4 +655,34 @@ public abstract class CompositeView
{
return false;
}
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position <code>pos</code> in the given direction <code>d</code>.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for <code>pos</code>
+ * @param d the direction, must be either {@link SwingConstants#NORTH},
+ * {@link SwingConstants#SOUTH}, {@link SwingConstants#WEST} or
+ * {@link SwingConstants#EAST}
+ * @param biasRet an array of {@link Position.Bias} that can hold at least
+ * one element, which is filled with the bias of the return position
+ * on method exit
+ *
+ * @return the document position that is (visually) nearest to the given
+ * document position <code>pos</code> in the given direction
+ * <code>d</code>
+ *
+ * @throws BadLocationException if <code>pos</code> is not a valid offset in
+ * the document model
+ */
+ public int getNextVisualPositionFrom(JTextComponent c, int pos,
+ Position.Bias b, int d,
+ Position.Bias[] biasRet)
+ throws BadLocationException
+ {
+ // TODO: Implement this properly.
+ throw new AssertionError("Not implemented yet.");
+ }
}