Package snap.text

Class TextModelX

All Implemented Interfaces:
CharSequence, Cloneable, PropChange.DoChange, CharSequenceX, XMLArchiver.Archivable

public class TextModelX extends SourceTextModel
This TextModel subclass adds support for advanced features like text wrapping, font scaling, linking multiple text models and more.
  • Field Details

    • _fontScale

      protected double _fontScale
  • Constructor Details

    • TextModelX

      public TextModelX()
      Constructor.
    • TextModelX

      public TextModelX(boolean isRichText)
      Constructor with option for rich text.
    • TextModelX

      public TextModelX(TextModel sourceText)
      Constructor for source text.
  • Method Details

    • addCharsWithStyleImpl

      protected void addCharsWithStyleImpl(CharSequence theChars, TextStyle theStyle, int anIndex)
      Adds characters with given style to this text at given index.
      Overrides:
      addCharsWithStyleImpl in class TextModel
    • addCharsToLineFinished

      protected void addCharsToLineFinished(TextLine textLine)
      Override to handle wrap lines.
      Overrides:
      addCharsToLineFinished in class TextModel
    • wrapLineIfNeeded

      protected void wrapLineIfNeeded(TextLine textLine)
      Wraps given line if needed by moving chars from last token(s) to next line.
    • isWrapLines

      public boolean isWrapLines()
      Returns whether to wrap lines that overrun bounds.
      Overrides:
      isWrapLines in class TextModel
    • setWrapLines

      public void setWrapLines(boolean aValue)
      Sets whether to wrap lines that overrun bounds.
    • isHyphenate

      public boolean isHyphenate()
      Returns whether layout tries to hyphenate wrapped words.
    • setHyphenate

      public void setHyphenate(boolean aValue)
      Sets whether layout tries to hyphenate wrapped words.
    • isLinked

      public boolean isLinked()
      Returns whether text is linked to another text (and shouldn't add lines below bottom border).
    • setLinked

      public void setLinked(boolean aValue)
      Returns whether text is linked to another text (and shouldn't add lines below bottom border).
    • getStartCharIndex

      public int getStartCharIndex()
      Returns the start char in source text.
      Overrides:
      getStartCharIndex in class TextModel
    • setStartCharIndex

      public void setStartCharIndex(int charIndex)
      Sets the start char in source text.
    • getFontScale

      public double getFontScale()
      Returns the font scale of the text.
    • setFontScale

      public void setFontScale(double aValue)
      Sets the font scale of the text.
    • getBoundsPath

      public Shape getBoundsPath()
      Returns the bounds path.
    • setBoundsPath

      public void setBoundsPath(Shape aPath)
      Sets the bounds path.
    • isHitRight

      protected boolean isHitRight(double aX, double aY, double aH)
      Returns whether given x location and run hit right border.
    • getMinHitX

      protected double getMinHitX(double aY, double aH, double anIndent)
      Returns the min x value that doesn't hit left border for given y/height and indent.
    • getMaxHitX

      protected double getMaxHitX(double aY, double aH)
      Returns the max x value that doesn't hit right border for given y/height.
    • setWidth

      public void setWidth(double aValue)
      Override to update layout.
      Overrides:
      setWidth in class TextModel
    • setHeight

      public void setHeight(double aValue)
      Override to update layout.
      Overrides:
      setHeight in class TextModel
    • getPrefWidth

      public double getPrefWidth()
      Returns the preferred width.
      Overrides:
      getPrefWidth in class TextModel
    • scaleTextToFit

      public void scaleTextToFit()
      Scales font sizes of all text to fit in bounds by finding/setting FontScale.
    • isTextOutOfBounds

      public boolean isTextOutOfBounds()
      Returns whether this text couldn't fit all text.