Package snap.text

Class TextLine

java.lang.Object
snap.text.TextLine
All Implemented Interfaces:
CharSequence, Cloneable, CharSequenceX
Direct Known Subclasses:
RichTextLine

public class TextLine extends Object implements CharSequenceX, Cloneable
This class represents a line of text in a Text.
  • Field Details

    • _textDoc

      protected TextDoc _textDoc
    • _sb

      protected StringBuffer _sb
    • _startCharIndex

      protected int _startCharIndex
    • _runs

      protected TextRun[] _runs
    • _lineStyle

      protected TextLineStyle _lineStyle
    • _index

      protected int _index
    • _width

      protected double _width
    • _tokens

      protected TextToken[] _tokens
    • EMPTY_RUNS

      protected static final TextRun[] EMPTY_RUNS
  • Constructor Details

    • TextLine

      public TextLine(TextDoc aTextDoc)
      Constructor.
  • Method Details

    • getTextDoc

      public TextDoc getTextDoc()
      Returns the TextDoc.
    • length

      public int length()
      Returns the length of this text line.
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int anIndex)
      Returns the char value at the specified index.
      Specified by:
      charAt in interface CharSequence
    • subSequence

      public CharSequence subSequence(int aStart, int anEnd)
      Returns a new char sequence that is a subsequence of this sequence.
      Specified by:
      subSequence in interface CharSequence
    • indexOf

      public int indexOf(String aStr, int aStart)
      Returns the index of given string in line.
    • getString

      public String getString()
      Returns the string for the line.
    • getStartCharIndex

      public int getStartCharIndex()
      Returns the start char index of this line in text.
    • getEndCharIndex

      public int getEndCharIndex()
      Returns the end char index of this line in text.
    • getIndex

      public int getIndex()
      Returns the index of this line in text.
    • getRunCount

      public int getRunCount()
      Returns the number of runs for this line.
    • getRun

      public TextRun getRun(int anIndex)
      Returns the individual run at given index.
    • getRuns

      public TextRun[] getRuns()
      Returns the line runs.
    • getLineStyle

      public TextLineStyle getLineStyle()
      Returns the line style.
    • setLineStyle

      public void setLineStyle(TextLineStyle aLineStyle)
      Sets the line style.
    • addChars

      public void addChars(CharSequence theChars, TextStyle theStyle, int anIndex)
      Adds characters with attributes to this line at given index.
    • removeChars

      public void removeChars(int aStart, int anEnd)
      Removes characters in given range.
    • addRun

      protected void addRun(TextRun aRun, int anIndex)
      Adds a run to line.
    • removeRun

      protected void removeRun(int anIndex)
      Removes the run at given index.
    • createRun

      protected TextRun createRun()
      Creates a new run.
    • setStyle

      protected void setStyle(TextStyle aStyle)
      Sets the style for the line (propagates to runs).
    • getWidth

      public double getWidth()
      Returns the width of line.
    • getWidth

      public double getWidth(int anIndex)
      Returns the width of line from given index.
    • getRunForCharIndex

      public TextRun getRunForCharIndex(int anIndex)
      Returns the head run for the line.
    • getRunForCharRange

      public TextRun getRunForCharRange(int startIndex, int endIndex)
      Returns the TextRun for the given char range (usually just run for start, but can be next run if at boundary).
    • getRunLast

      public TextRun getRunLast()
      Returns the last run.
    • splitLineAtIndex

      protected TextLine splitLineAtIndex(int anIndex)
      Splits the line at given character index.
    • getXForTabAtIndexAndX

      protected double getXForTabAtIndexAndX(int charIndex, double aX)
      Returns the x for tab at given x.
    • getTokens

      public TextToken[] getTokens()
      Returns the tokens.
    • createTokens

      protected TextToken[] createTokens()
      Creates the tokens (via TextDoc.createTokensForTextLine() to provide another hook).
    • getLastToken

      public TextToken getLastToken()
      Returns the last token.
    • getTokenForCharIndex

      public TextToken getTokenForCharIndex(int charIndex)
      Returns the token at or before given char index.
    • getXForCharIndex

      public double getXForCharIndex(int anIndex)
      Returns the X coord for given char index.
    • getTokenForX

      public TextToken getTokenForX(double anX)
      Returns the token at index.
    • getCharIndexForX

      public int getCharIndexForX(double anX)
      Returns the character index for the given x/y point.
    • getNext

      public TextLine getNext()
      Returns the next line, if available.
    • getPrevious

      public TextLine getPrevious()
      Returns the previous line, if available.
    • getAlignX

      public HPos getAlignX()
      Returns the alignment associated with this line.
    • setAlignX

      public void setAlignX(HPos anAlign)
      Sets the alignment associated with this line.
    • isUnderlined

      public boolean isUnderlined()
      Returns whether line contains an underlined run.
    • updateRuns

      protected void updateRuns(int aRunIndex)
      Updates length due to change in given run.
    • updateText

      protected void updateText()
      Updates text.
    • copyForRange

      public TextLine copyForRange(int aStart, int aEnd)
      Returns a copy of this line for given char range.
    • clone

      public TextLine clone()
      Standard clone implementation.
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Standard toString implementation.
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • toStringProps

      public String toStringProps()
      Standard toStringProps implementation.