Class TextSelection.Span

java.lang.Object
com.codename1.ui.TextSelection.Span
All Implemented Interfaces:
Iterable<TextSelection.Char>
Enclosing class:
TextSelection

public class TextSelection.Span extends Object implements Iterable<TextSelection.Char>
Encapsulates a span of text on the screen. This can only represent a contiguous, single row of characters.
  • Constructor Details

    • Span

      public Span(Component c)

      Creates a new span for the given component.

      Parameters
      • c
  • 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()
      Specified by:
      iterator in interface Iterable<TextSelection.Char>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • add

      public void add(TextSelection.Char character)

      Adds a character to the span, updating the bounds.

      Parameters
      • character
    • 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: The x-coord of the intersection box, relative to #getSelectionRoot()

      • y: The y-coord of the intersection box to #getSelectionRoot()

      • w: The width of the intersection box.

      • h: 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: The x-coord of the intersection box, relative to #getSelectionRoot()

      • y: The y-coord of the intersection box to #getSelectionRoot()

      • w: The width of the intersection box.

      • h: The height of the intersection box.

      • withFlow: @param withFlow 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: The bounds of the intersection box, relative to #getSelectionRoot()

      • withFlow: @param withFlow 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: 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: x-coordinate relative to #getSelectionRoot()

      • y: 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: The start position of the Char to retrieve.

      • end: 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: x translation in pixels.

      • ty: y translation in pixels.

      Returns

      A new span translated.

    • isEmpty

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