Package snap.text

Class TextDoc

All Implemented Interfaces:
CharSequence, Cloneable, PropChange.DoChange, CharSequenceX
Direct Known Subclasses:
CodeDoc, RichText, SubText

public class TextDoc extends PropObject implements CharSequenceX, Cloneable
This class is the basic text storage class, holding a list of TextLine.
  • Field Details

  • Constructor Details

    • TextDoc

      public TextDoc()
      Constructor.
  • Method Details

    • addDefaultLine

      protected void addDefaultLine()
      Adds a default line.
    • isRichText

      public boolean isRichText()
      Whether this text supports multiple styles (font, color, etc.).
    • getSourceURL

      public WebURL getSourceURL()
      Returns the source URL.
    • setSourceURL

      public void setSourceURL(WebURL aURL)
      Sets the Source URL.
    • getSourceFile

      public WebFile getSourceFile()
      Returns the source file.
    • length

      public int length()
      Returns the number of characters in the text.
      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
    • getString

      public String getString()
      Returns the string for the text.
    • setString

      public void setString(String aString)
      Sets the text to the given string.
    • isDefaultTextStyleSet

      public boolean isDefaultTextStyleSet()
      Returns whether the default text style is explicitly set (vs. coming from parent).
    • getDefaultStyle

      public TextStyle getDefaultStyle()
      Returns the default text style for text.
    • setDefaultStyle

      public void setDefaultStyle(TextStyle aStyle)
      Sets the default text style.
    • getDefaultLineStyle

      public TextLineStyle getDefaultLineStyle()
      Returns the default line style for text.
    • setDefaultLineStyle

      public void setDefaultLineStyle(TextLineStyle aLineStyle)
      Sets the default line style.
    • getParentTextStyle

      public TextStyle getParentTextStyle()
      Returns the current style for TextDoc parent/container (probably a TextArea).
    • setParentTextStyle

      public void setParentTextStyle(TextStyle aStyle)
      Sets the current style for TextDoc parent/container (probably a TextArea).
    • isTextModified

      public boolean isTextModified()
      Returns whether text is modified.
    • setTextModified

      public void setTextModified(boolean aValue)
      Sets whether text is modified.
    • addChars

      public void addChars(CharSequence theChars)
      Adds characters with attributes to this text at given index.
    • addChars

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

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

      public void replaceChars(CharSequence theChars, int aStart, int anEnd)
      Replaces chars in given range, with given String, using the given attributes.
    • replaceChars

      public void replaceChars(CharSequence theChars, TextStyle theStyle, int aStart, int anEnd)
      Replaces chars in given range, with given String, using the given attributes.
    • addTextDoc

      public void addTextDoc(TextDoc aTextDoc, int anIndex)
      Adds given TextDoc to this text at given index.
    • setStyle

      public void setStyle(TextStyle aStyle, int aStart, int anEnd)
      Sets a given style to a given range.
    • setStyleValue

      public void setStyleValue(Object aValue)
      Sets a given style value to given value for a given range.
    • setStyleValue

      public void setStyleValue(Object aValue, int aStart, int aEnd)
      Sets a given style value to given value for a given range.
    • setStyleValue

      public void setStyleValue(String aKey, Object aValue)
      Sets a given attribute to a given value for a given range.
    • setStyleValue

      public void setStyleValue(String aKey, Object aValue, int aStart, int anEnd)
      Sets a given attribute to a given value for a given range.
    • setLineStyle

      public void setLineStyle(TextLineStyle aStyle, int aStart, int anEnd)
      Sets a given style to a given range.
    • setLineStyleValue

      public void setLineStyleValue(String aKey, Object aValue, int aStart, int anEnd)
      Sets a given style to a given range.
    • getLineCount

      public int getLineCount()
      Returns the number of block in this doc.
    • getLine

      public TextLine getLine(int anIndex)
      Returns the individual block in this doc.
    • getLines

      public List<TextLine> getLines()
      Returns the list of blocks.
    • addLine

      protected void addLine(TextLine aLine, int anIndex)
      Adds a block at given index.
    • removeLine

      protected void removeLine(int anIndex)
      Removes the block at given index.
    • createLine

      protected TextLine createLine()
      Creates a new TextLine for use in this text.
    • getLineLongest

      public TextLine getLineLongest()
      Returns the longest line.
    • clear

      public void clear()
      Clears the text.
    • getPrefWidth

      public double getPrefWidth()
      Returns the width of text.
    • getPrefWidth

      public double getPrefWidth(int anIndex)
      Returns the width of text from given index.
    • getLineForCharIndex

      public TextLine getLineForCharIndex(int anIndex)
      Returns the block at the given char index.
    • getLineLast

      public TextLine getLineLast()
      Returns the last block.
    • getRunForCharIndex

      public TextRun getRunForCharIndex(int charIndex)
      Returns the TextRun that contains the given char index.
    • 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.
    • getFontForCharIndex

      public Font getFontForCharIndex(int charIndex)
      Returns the Font for run at given character index.
    • getStyleForCharIndex

      public TextStyle getStyleForCharIndex(int charIndex)
      Returns the TextStyle for the run at the given character index.
    • getStyleForCharRange

      public TextStyle getStyleForCharRange(int startIndex, int endIndex)
      Returns the TextStyle for the run for given char range.
    • getLineStyleForCharIndex

      public TextLineStyle getLineStyleForCharIndex(int charIndex)
      Returns the TextLineStyle for the run at the given character index.
    • isUnderlined

      public boolean isUnderlined()
      Returns whether text contains an underlined run.
    • setUnderlined

      public void setUnderlined(boolean aFlag)
      Sets text to be underlined.
    • getAlignX

      public HPos getAlignX()
      Returns the horizontal alignment of the first paragraph of the text.
    • setAlignX

      public void setAlignX(HPos anAlignX)
      Sets the horizontal alignment of the text.
    • getStartCharIndex

      public int getStartCharIndex()
      Returns the start char index (always 0, unless this is SubText).
    • scaleFonts

      public void scaleFonts(double aScale)
      Scales all the fonts in text by given factor.
    • indexOf

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

      public boolean isPropChangeEnabled()
      Returns whether property change is enabled.
    • setPropChangeEnabled

      public void setPropChangeEnabled(boolean aValue)
      Sets whether property change is enabled.
    • createTokensForTextLine

      protected TextToken[] createTokensForTextLine(TextLine aTextLine)
      Creates TextTokens for a TextLine.
    • updateLines

      protected void updateLines(int anIndex)
      Updates Lines (Index, Start) from index line to text end.
    • readFromSourceURL

      public void readFromSourceURL(WebURL aURL)
      Load TextDoc from source URL.
    • writeToSourceFile

      public void writeToSourceFile() throws Exception
      Write TextDoc text to source file.
      Throws:
      Exception
    • clone

      public TextDoc clone()
      Standard clone implementation.
      Overrides:
      clone in class PropObject
    • toStringProps

      public String toStringProps()
      Standard toStringProps implementation.
      Overrides:
      toStringProps in class PropObject
    • newFromSource

      public static TextDoc newFromSource(Object aSource)
      Returns a new TextDoc from given source.