diff options
author | Roman Kennke <roman@kennke.org> | 2005-11-03 14:09:21 +0000 |
---|---|---|
committer | Roman Kennke <roman@kennke.org> | 2005-11-03 14:09:21 +0000 |
commit | 41eb3e42580f46f069b65e572b5ca157b270531f (patch) | |
tree | 2472899e2601543d643961d8afec7a0052ca1235 | |
parent | 1efaea11d595782f2ce3d99cd34aac678dd4ad8e (diff) | |
download | classpath-41eb3e42580f46f069b65e572b5ca157b270531f.tar.gz |
2005-11-02 Roman Kennke <kennke@aicas.com>
* javax/swing/text/Utilities.java
(getPositionAbove): New utility method.
(getPositionBelow): New utility method.
(getParagraphElement): Special case for StyledDocuments.
* javax/swing/text/View.java
(getNextVisualPositionFrom): New abstract method.
* javax/swing/text/ComponentView.java
(getNextVisualPositionFrom): New method.
* javax/swing/text/CompositeView.java
(getNextVisualPositionFrom): New method.
* javax/swing/text/FlowView.java
(LogicalView.getNextVisualPositionFrom): New method.
* javax/swing/text/GlyphView.java
(getNextVisualPositionFrom): New method.
* javax/swing/text/IconView.java
(getNextVisualPositionFrom): New method.
* javax/swing/text/PlainView.java
(getNextVisualPositionFrom): New method.
* javax/swing/text/WrappedPlainView.java
(WrappedLine.getNextVisualPositionFrom): New method.
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | javax/swing/text/ComponentView.java | 32 | ||||
-rw-r--r-- | javax/swing/text/CompositeView.java | 30 | ||||
-rw-r--r-- | javax/swing/text/FlowView.java | 32 | ||||
-rw-r--r-- | javax/swing/text/GlyphView.java | 30 | ||||
-rw-r--r-- | javax/swing/text/IconView.java | 32 | ||||
-rw-r--r-- | javax/swing/text/PlainView.java | 31 | ||||
-rw-r--r-- | javax/swing/text/Utilities.java | 75 | ||||
-rw-r--r-- | javax/swing/text/View.java | 26 | ||||
-rw-r--r-- | javax/swing/text/WrappedPlainView.java | 31 |
10 files changed, 338 insertions, 4 deletions
@@ -1,5 +1,28 @@ 2005-11-02 Roman Kennke <kennke@aicas.com> + * javax/swing/text/Utilities.java + (getPositionAbove): New utility method. + (getPositionBelow): New utility method. + (getParagraphElement): Special case for StyledDocuments. + * javax/swing/text/View.java + (getNextVisualPositionFrom): New abstract method. + * javax/swing/text/ComponentView.java + (getNextVisualPositionFrom): New method. + * javax/swing/text/CompositeView.java + (getNextVisualPositionFrom): New method. + * javax/swing/text/FlowView.java + (LogicalView.getNextVisualPositionFrom): New method. + * javax/swing/text/GlyphView.java + (getNextVisualPositionFrom): New method. + * javax/swing/text/IconView.java + (getNextVisualPositionFrom): New method. + * javax/swing/text/PlainView.java + (getNextVisualPositionFrom): New method. + * javax/swing/text/WrappedPlainView.java + (WrappedLine.getNextVisualPositionFrom): New method. + +2005-11-02 Roman Kennke <kennke@aicas.com> + * javax/swing/text/DefaultCaret.java (BlinkTimerListener): New inner class. Listens for when the blink timer fires and updates the visible flag accordingly. diff --git a/javax/swing/text/ComponentView.java b/javax/swing/text/ComponentView.java index 366dc1c38..16112c8f4 100644 --- a/javax/swing/text/ComponentView.java +++ b/javax/swing/text/ComponentView.java @@ -41,6 +41,8 @@ import java.awt.Component; import java.awt.Graphics; import java.awt.Shape; +import javax.swing.SwingConstants; + /** * A {@link View} implementation that is able to render arbitrary * {@link Component}s. This uses the attribute @@ -176,4 +178,34 @@ public class ComponentView extends View // FIXME: Implement this properly. return 0; } + + /** + * 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."); + } } diff --git a/javax/swing/text/CompositeView.java b/javax/swing/text/CompositeView.java index 6d8ca912f..dd157ef84 100644 --- a/javax/swing/text/CompositeView.java +++ b/javax/swing/text/CompositeView.java @@ -658,4 +658,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."); + } } diff --git a/javax/swing/text/FlowView.java b/javax/swing/text/FlowView.java index 5f23ba987..fd6785b6f 100644 --- a/javax/swing/text/FlowView.java +++ b/javax/swing/text/FlowView.java @@ -45,6 +45,7 @@ import java.awt.Shape; import java.util.Iterator; import java.util.Vector; +import javax.swing.SwingConstants; import javax.swing.event.DocumentEvent; /** @@ -395,6 +396,37 @@ public abstract class FlowView extends BoxView throw new AssertionError("This method must not be called in " + "LogicalView."); } + + /** + * 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 + { + assert false : "getNextVisualPositionFrom() must not be called in " + + "LogicalView"; + return 0; + } } /** diff --git a/javax/swing/text/GlyphView.java b/javax/swing/text/GlyphView.java index b516d20e4..eb1fadd4f 100644 --- a/javax/swing/text/GlyphView.java +++ b/javax/swing/text/GlyphView.java @@ -1060,4 +1060,34 @@ public class GlyphView extends View implements TabableView, Cloneable return painter.getNextVisualPositionFrom(this, pos, bias, a, direction, biasRet); } + + /** + * 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."); + } } diff --git a/javax/swing/text/IconView.java b/javax/swing/text/IconView.java index c7e22b6c3..6dd0f7ad3 100644 --- a/javax/swing/text/IconView.java +++ b/javax/swing/text/IconView.java @@ -41,6 +41,8 @@ package javax.swing.text; import java.awt.Graphics; import java.awt.Shape; +import javax.swing.SwingConstants; + // TODO: Implement this class. public class IconView extends View @@ -125,4 +127,34 @@ public class IconView // FIXME: not implemented return 0; } + + /** + * 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."); + } } diff --git a/javax/swing/text/PlainView.java b/javax/swing/text/PlainView.java index 07351ade9..8cd69fc37 100644 --- a/javax/swing/text/PlainView.java +++ b/javax/swing/text/PlainView.java @@ -46,6 +46,7 @@ import java.awt.Graphics; import java.awt.Rectangle; import java.awt.Shape; +import javax.swing.SwingConstants; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent.ElementChange; @@ -529,5 +530,35 @@ public class PlainView extends View implements TabExpander lineBuffer = new Segment(); return lineBuffer; } + + /** + * 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."); + } } diff --git a/javax/swing/text/Utilities.java b/javax/swing/text/Utilities.java index a2d2d6feb..7830b2fca 100644 --- a/javax/swing/text/Utilities.java +++ b/javax/swing/text/Utilities.java @@ -40,8 +40,12 @@ package javax.swing.text; 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 @@ public class Utilities * * @return the paragraph element at <code>offset</code> */ - 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 <code>offset</code>. + * + * @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 <code>offset</code> + * + * @throws BadLocationException if <code>offset</code> 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 <code>offset</code>. + * + * @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 <code>offset</code> + * + * @throws BadLocationException if <code>offset</code> 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; } } diff --git a/javax/swing/text/View.java b/javax/swing/text/View.java index 7b3039cfb..daab347d7 100644 --- a/javax/swing/text/View.java +++ b/javax/swing/text/View.java @@ -594,4 +594,30 @@ public abstract class View implements SwingConstants 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 <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 abstract int getNextVisualPositionFrom(JTextComponent c, int pos, + Position.Bias b, int d, + Position.Bias[] biasRet) + throws BadLocationException; } diff --git a/javax/swing/text/WrappedPlainView.java b/javax/swing/text/WrappedPlainView.java index 5b70c9df2..090d4ab5f 100644 --- a/javax/swing/text/WrappedPlainView.java +++ b/javax/swing/text/WrappedPlainView.java @@ -45,6 +45,7 @@ import java.awt.Graphics; 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 @@ public class WrappedPlainView extends BoxView implements TabExpander currLineStart = currLineEnd; } } + + /** + * 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."); + } } } |