public class TextSelection.Span
- Object
- TextSelection.Span
ImplementsIterable<TextSelection.Char>
Encapsulates a span of text on the screen. This can only represent
a contiguous, single row of characters.
Constructors
public Span(Component c) | Creates a new span for the given component. |
Methods
Inherited methods
Constructor details
Span
public Span(Component c)Creates a new span for the given component.
Method details
getStartPos
public int getStartPos()Gets the start position of the text.
getEndPos
public int getEndPos()Gets th end position of the text. (exclusive).
iterator
public Iterator<TextSelection.Char> iterator()Returns an
Iterator for the elements in this object.Returns
An
Iterator instance.toString
public String toString()Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + ‘@’ + Integer.toHexString(hashCode())
add
public void add(TextSelection.Char character)Adds a character to the span, updating the bounds.
getIntersection
public TextSelection.Span getIntersection(int x, int y, int w, int h)Obtains an intersection span including only the characters that intersect the given rectangle.
Parameters
xint- The x-coord of the intersection box, relative to
#getSelectionRoot() yint- The y-coord of the intersection box to
#getSelectionRoot() wint- The width of the intersection box.
hint- The height of the intersection box.
Returns
A new span containing only characters that intersect the given bounds.
getIntersection
public TextSelection.Span getIntersection(int x, int y, int w, int h, boolean withFlow)Obtains an intersection span including only the characters that intersect the given rectangle.
Parameters
xint- The x-coord of the intersection box, relative to
#getSelectionRoot() yint- The y-coord of the intersection box to
#getSelectionRoot() wint- The width of the intersection box.
hint- The height of the intersection box.
withFlowboolean- If true, this will also include any characters that should logically be selected if the user dragged over the given rectangle. E.g. If the selection began above the span, and stretches below it, the entire span should be selected (included in the intersection).
Returns
A new span with the intersection.
getIntersection
public TextSelection.Span getIntersection(Rectangle bounds, boolean withFlow)Obtains an intersection span including only the characters that intersect the given rectangle.
Parameters
boundsRectangle- The bounds of the intersection box, relative to
#getSelectionRoot() withFlowboolean- If true, this will also include any characters that should logically be selected if the user dragged over the given rectangle. E.g. If the selection began above the span, and stretches below it, the entire span should be selected (included in the intersection).
Returns
A new span with the intersection.
getIntersection
public TextSelection.Span getIntersection(Rectangle bounds)Obtains an intersection span including only the characters that intersect the given rectangle.
Parameters
boundsRectangle- The bounds of the intersection box, relative to
#getSelectionRoot()
Returns
A new span with the intersection.
charAt
public TextSelection.Char charAt(int x, int y)Gets the char at the given coordinate or null if there isn’t a char there.
Parameters
xint- x-coordinate relative to
#getSelectionRoot() yint- y-coordinate relative to
#getSelectionRoot()
first
public TextSelection.Char first()Gets the first Char in the span, or null if span is empty.
Returns
The first Char, or null.
last
public TextSelection.Char last()Gets the last Char in the span, or null if the span is empty.
Returns
The last Char or null.
size
public int size()Gets the number of Chars in the span.
subspan
public TextSelection.Span subspan(int start, int end)Gets a subspan containing the Chars between start (inclusive), and end (exclusive).
Parameters
startint- The start position of the Char to retrieve.
endint- The end position of the Char to retrieve.
Returns
A new span including only the Chars at the given positions.
getBounds
public Rectangle getBounds()Gets the bounds of the span.
Returns
the bounds
translate
public TextSelection.Span translate(int tx, int ty)Creates a translated span based on this one.
Parameters
txint- x translation in pixels.
tyint- y translation in pixels.
Returns
A new span translated.
isEmpty
public boolean isEmpty()Returns true if the span is empty.