Index: javax/swing/text/ComponentView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/ComponentView.java,v
retrieving revision 1.11
diff -u -r1.11 ComponentView.java
--- javax/swing/text/ComponentView.java 19 Oct 2005 14:57:30 -0000 1.11
+++ javax/swing/text/ComponentView.java 3 Nov 2005 14:08:26 -0000
@@ -41,6 +41,8 @@
import java.awt.Graphics;
import java.awt.Shape;
+import javax.swing.SwingConstants;
+
/**
* A address@hidden View} implementation that is able to render arbitrary
* address@hidden Component}s. This uses the attribute
@@ -175,5 +177,35 @@
{
// FIXME: Implement this properly.
return 0;
+ }
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position pos
in the given direction d
.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for pos
+ * @param d the direction, must be either address@hidden SwingConstants#NORTH},
+ * address@hidden SwingConstants#SOUTH}, address@hidden SwingConstants#WEST} or
+ * address@hidden SwingConstants#EAST}
+ * @param biasRet an array of address@hidden 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 pos
in the given direction
+ * d
+ *
+ * @throws BadLocationException if pos
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.");
}
}
Index: javax/swing/text/CompositeView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/CompositeView.java,v
retrieving revision 1.9
diff -u -r1.9 CompositeView.java
--- javax/swing/text/CompositeView.java 25 Oct 2005 18:54:17 -0000 1.9
+++ javax/swing/text/CompositeView.java 3 Nov 2005 14:08:26 -0000
@@ -658,4 +658,34 @@
{
return false;
}
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position pos
in the given direction d
.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for pos
+ * @param d the direction, must be either address@hidden SwingConstants#NORTH},
+ * address@hidden SwingConstants#SOUTH}, address@hidden SwingConstants#WEST} or
+ * address@hidden SwingConstants#EAST}
+ * @param biasRet an array of address@hidden 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 pos
in the given direction
+ * d
+ *
+ * @throws BadLocationException if pos
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.");
+ }
}
Index: javax/swing/text/FlowView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/FlowView.java,v
retrieving revision 1.4
diff -u -r1.4 FlowView.java
--- javax/swing/text/FlowView.java 19 Oct 2005 14:57:31 -0000 1.4
+++ javax/swing/text/FlowView.java 3 Nov 2005 14:08:26 -0000
@@ -45,6 +45,7 @@
import java.util.Iterator;
import java.util.Vector;
+import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
/**
@@ -394,6 +395,37 @@
{
throw new AssertionError("This method must not be called in "
+ "LogicalView.");
+ }
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position pos
in the given direction d
.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for pos
+ * @param d the direction, must be either address@hidden SwingConstants#NORTH},
+ * address@hidden SwingConstants#SOUTH}, address@hidden SwingConstants#WEST} or
+ * address@hidden SwingConstants#EAST}
+ * @param biasRet an array of address@hidden 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 pos
in the given direction
+ * d
+ *
+ * @throws BadLocationException if pos
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
+ {
+ assert false : "getNextVisualPositionFrom() must not be called in "
+ + "LogicalView";
+ return 0;
}
}
Index: javax/swing/text/GlyphView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GlyphView.java,v
retrieving revision 1.10
diff -u -r1.10 GlyphView.java
--- javax/swing/text/GlyphView.java 30 Oct 2005 18:02:53 -0000 1.10
+++ javax/swing/text/GlyphView.java 3 Nov 2005 14:08:26 -0000
@@ -1060,4 +1060,34 @@
return painter.getNextVisualPositionFrom(this, pos, bias, a, direction,
biasRet);
}
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position pos
in the given direction d
.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for pos
+ * @param d the direction, must be either address@hidden SwingConstants#NORTH},
+ * address@hidden SwingConstants#SOUTH}, address@hidden SwingConstants#WEST} or
+ * address@hidden SwingConstants#EAST}
+ * @param biasRet an array of address@hidden 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 pos
in the given direction
+ * d
+ *
+ * @throws BadLocationException if pos
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.");
+ }
}
Index: javax/swing/text/IconView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/IconView.java,v
retrieving revision 1.4
diff -u -r1.4 IconView.java
--- javax/swing/text/IconView.java 22 Aug 2005 11:35:23 -0000 1.4
+++ javax/swing/text/IconView.java 3 Nov 2005 14:08:26 -0000
@@ -41,6 +41,8 @@
import java.awt.Graphics;
import java.awt.Shape;
+import javax.swing.SwingConstants;
+
// TODO: Implement this class.
public class IconView
extends View
@@ -124,5 +126,35 @@
{
// FIXME: not implemented
return 0;
+ }
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position pos
in the given direction d
.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for pos
+ * @param d the direction, must be either address@hidden SwingConstants#NORTH},
+ * address@hidden SwingConstants#SOUTH}, address@hidden SwingConstants#WEST} or
+ * address@hidden SwingConstants#EAST}
+ * @param biasRet an array of address@hidden 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 pos
in the given direction
+ * d
+ *
+ * @throws BadLocationException if pos
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.");
}
}
Index: javax/swing/text/PlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v
retrieving revision 1.29
diff -u -r1.29 PlainView.java
--- javax/swing/text/PlainView.java 30 Oct 2005 22:03:50 -0000 1.29
+++ javax/swing/text/PlainView.java 3 Nov 2005 14:08:26 -0000
@@ -46,6 +46,7 @@
import java.awt.Rectangle;
import java.awt.Shape;
+import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentEvent.ElementChange;
@@ -528,6 +529,36 @@
if (lineBuffer == null)
lineBuffer = new Segment();
return lineBuffer;
+ }
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position pos
in the given direction d
.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for pos
+ * @param d the direction, must be either address@hidden SwingConstants#NORTH},
+ * address@hidden SwingConstants#SOUTH}, address@hidden SwingConstants#WEST} or
+ * address@hidden SwingConstants#EAST}
+ * @param biasRet an array of address@hidden 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 pos
in the given direction
+ * d
+ *
+ * @throws BadLocationException if pos
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.");
}
}
Index: javax/swing/text/Utilities.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/Utilities.java,v
retrieving revision 1.17
diff -u -r1.17 Utilities.java
--- javax/swing/text/Utilities.java 3 Nov 2005 11:19:29 -0000 1.17
+++ javax/swing/text/Utilities.java 3 Nov 2005 14:08:26 -0000
@@ -40,8 +40,12 @@
import java.awt.FontMetrics;
import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.Rectangle;
import java.text.BreakIterator;
+import javax.swing.SwingConstants;
+
/**
* A set of utilities to deal with text. This is used by several other classes
* inside this package.
@@ -532,10 +536,73 @@
*
* @return the paragraph element at offset
*/
- public static Element getParagraphElement(JTextComponent c, int offset)
+ public static final Element getParagraphElement(JTextComponent c, int offset)
+ {
+ Document doc = c.getDocument();
+ Element par = null;
+ if (doc instanceof StyledDocument)
+ {
+ StyledDocument styledDoc = (StyledDocument) doc;
+ par = styledDoc.getParagraphElement(offset);
+ }
+ else
+ {
+ Element root = c.getDocument().getDefaultRootElement();
+ int parIndex = root.getElementIndex(offset);
+ par = root.getElement(parIndex);
+ }
+ return par;
+ }
+
+ /**
+ * Returns the document position that is closest above to the specified x
+ * coordinate in the row containing offset
.
+ *
+ * @param c the text component
+ * @param offset the offset
+ * @param x the x coordinate
+ *
+ * @return the document position that is closest above to the specified x
+ * coordinate in the row containing offset
+ *
+ * @throws BadLocationException if offset
is not a valid offset
+ */
+ public static final int getPositionAbove(JTextComponent c, int offset, int x)
+ throws BadLocationException
{
- Element root = c.getDocument().getDefaultRootElement();
- int parIndex = root.getElementIndex(offset);
- return root.getElement(parIndex);
+ View rootView = c.getUI().getRootView(c);
+ Rectangle r = c.modelToView(offset);
+ int offs = c.viewToModel(new Point(x, r.y));
+ int pos = rootView.getNextVisualPositionFrom(c, offs,
+ Position.Bias.Forward,
+ SwingConstants.NORTH,
+ new Position.Bias[1]);
+ return pos;
+ }
+
+ /**
+ * Returns the document position that is closest below to the specified x
+ * coordinate in the row containing offset
.
+ *
+ * @param c the text component
+ * @param offset the offset
+ * @param x the x coordinate
+ *
+ * @return the document position that is closest above to the specified x
+ * coordinate in the row containing offset
+ *
+ * @throws BadLocationException if offset
is not a valid offset
+ */
+ public static final int getPositionBelow(JTextComponent c, int offset, int x)
+ throws BadLocationException
+ {
+ View rootView = c.getUI().getRootView(c);
+ Rectangle r = c.modelToView(offset);
+ int offs = c.viewToModel(new Point(x, r.y));
+ int pos = rootView.getNextVisualPositionFrom(c, offs,
+ Position.Bias.Forward,
+ SwingConstants.SOUTH,
+ new Position.Bias[1]);
+ return pos;
}
}
Index: javax/swing/text/View.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/View.java,v
retrieving revision 1.22
diff -u -r1.22 View.java
--- javax/swing/text/View.java 10 Oct 2005 19:30:26 -0000 1.22
+++ javax/swing/text/View.java 3 Nov 2005 14:08:27 -0000
@@ -594,4 +594,30 @@
for (int i = 0; i < count; ++i)
getView(i).dump(indent + 1);
}
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position pos
in the given direction d
.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for pos
+ * @param d the direction, must be either address@hidden SwingConstants#NORTH},
+ * address@hidden SwingConstants#SOUTH}, address@hidden SwingConstants#WEST} or
+ * address@hidden SwingConstants#EAST}
+ * @param biasRet an array of address@hidden 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 pos
in the given direction
+ * d
+ *
+ * @throws BadLocationException if pos
is not a valid offset in
+ * the document model
+ */
+ public abstract int getNextVisualPositionFrom(JTextComponent c, int pos,
+ Position.Bias b, int d,
+ Position.Bias[] biasRet)
+ throws BadLocationException;
}
Index: javax/swing/text/WrappedPlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/WrappedPlainView.java,v
retrieving revision 1.4
diff -u -r1.4 WrappedPlainView.java
--- javax/swing/text/WrappedPlainView.java 2 Nov 2005 19:07:01 -0000 1.4
+++ javax/swing/text/WrappedPlainView.java 3 Nov 2005 14:08:27 -0000
@@ -45,6 +45,7 @@
import java.awt.Rectangle;
import java.awt.Shape;
+import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.text.Position.Bias;
@@ -544,5 +545,35 @@
currLineStart = currLineEnd;
}
}
+
+ /**
+ * Returns the document position that is (visually) nearest to the given
+ * document position pos
in the given direction d
.
+ *
+ * @param c the text component
+ * @param pos the document position
+ * @param b the bias for pos
+ * @param d the direction, must be either address@hidden SwingConstants#NORTH},
+ * address@hidden SwingConstants#SOUTH}, address@hidden SwingConstants#WEST} or
+ * address@hidden SwingConstants#EAST}
+ * @param biasRet an array of address@hidden 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 pos
in the given direction
+ * d
+ *
+ * @throws BadLocationException if pos
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.");
+ }
}
}