public class TextSelection.Span

  1. Object
  2. 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

public int getStartPos()Gets the start position of the text.
public int getEndPos()Gets th end position of the text.
public Iterator<TextSelection.Char> iterator()Returns an Iterator for the elements in this object.
public String toString()Returns a string representation of the object.
public void add(TextSelection.Char character)Adds a character to the span, updating the bounds.
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.
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.
public TextSelection.Span getIntersection(Rectangle bounds, boolean withFlow)Obtains an intersection span including only the characters that intersect the given rectangle.
public TextSelection.Span getIntersection(Rectangle bounds)Obtains an intersection span including only the characters that intersect the given rectangle.
public TextSelection.Char charAt(int x, int y)Gets the char at the given coordinate or null if there isn’t a char there.
public TextSelection.Char first()Gets the first Char in the span, or null if span is empty.
public TextSelection.Char last()Gets the last Char in the span, or null if the span is empty.
public int size()Gets the number of Chars in the span.
public TextSelection.Span subspan(int start, int end)Gets a subspan containing the Chars between start (inclusive), and end (exclusive).
public Rectangle getBounds()Gets the bounds of the span.
public TextSelection.Span translate(int tx, int ty)Creates a translated span based on this one.
public boolean isEmpty()Returns true if the span is empty.

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

x int
The x-coord of the intersection box, relative to #getSelectionRoot()
y int
The y-coord of the intersection box to #getSelectionRoot()
w int
The width of the intersection box.
h int
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

x int
The x-coord of the intersection box, relative to #getSelectionRoot()
y int
The y-coord of the intersection box to #getSelectionRoot()
w int
The width of the intersection box.
h int
The height of the intersection box.
withFlow boolean
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

bounds Rectangle
The bounds of the intersection box, relative to #getSelectionRoot()
withFlow boolean
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

bounds Rectangle
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

x int
x-coordinate relative to #getSelectionRoot()
y int
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

start int
The start position of the Char to retrieve.
end int
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

tx int
x translation in pixels.
ty int
y translation in pixels.

Returns

A new span translated.

isEmpty

public boolean isEmpty()
Returns true if the span is empty.