Package snap.text

Class TextBox

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

public class TextBox extends TextBlock
This TextBlock subclass adds support for text wrapping and syncs to a source TextBlock.
  • Field Details

    • _fontScale

      protected double _fontScale
  • Constructor Details

    • TextBox

      public TextBox()
      Constructor.
    • TextBox

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

      public TextBox(TextBlock sourceText)
      Constructor for source text block.
  • Method Details

    • getSourceText

      public TextBlock getSourceText()
      Returns the source TextBlock.
      Overrides:
      getSourceText in class TextBlock
    • setSourceText

      public void setSourceText(TextBlock aTextBlock)
      Sets the source TextBlock.
    • setRichText

      public void setRichText(boolean aValue)
      Sets whether text supports multiple styles.
      Overrides:
      setRichText in class TextBlock
    • addCharsWithStyle

      public void addCharsWithStyle(CharSequence theChars, TextStyle theStyle, int anIndex)
      Override to forward to source text block.
      Overrides:
      addCharsWithStyle in class TextBlock
    • removeChars

      public void removeChars(int aStartCharIndex, int anEndCharIndex)
      Override to forward to source text block.
      Overrides:
      removeChars in class TextBlock
    • replaceChars

      public void replaceChars(CharSequence theChars, TextStyle theStyle, int aStart, int anEnd)
      Override to forward to source text block.
      Overrides:
      replaceChars in class TextBlock
    • setTextStyle

      public void setTextStyle(TextStyle textStyle, int aStart, int anEnd)
      Override to forward to source text block.
      Overrides:
      setTextStyle in class TextBlock
    • setStyleValue

      public void setStyleValue(String aKey, Object aValue, int aStart, int anEnd)
      Override to forward to source text block.
      Overrides:
      setStyleValue in class TextBlock
    • setLineStyle

      public void setLineStyle(TextLineStyle aStyle, int aStart, int anEnd)
      Override to forward to source text block.
      Overrides:
      setLineStyle in class TextBlock
    • setLineStyleValue

      public void setLineStyleValue(String aKey, Object aValue, int aStart, int anEnd)
      Override to forward to source text block.
      Overrides:
      setLineStyleValue in class TextBlock
    • setDefaultTextStyle

      public void setDefaultTextStyle(TextStyle aStyle)
      Override to forward to source text block.
      Overrides:
      setDefaultTextStyle in class TextBlock
    • copyForRange

      public TextBlock copyForRange(int aStart, int aEnd)
      Override to forward to source text block.
      Overrides:
      copyForRange in class TextBlock
    • addCharsToLine

      protected void addCharsToLine(CharSequence theChars, TextStyle theStyle, int charIndex, TextLine textLine, boolean charsHaveNewline)
      Override to do wrapping.
      Overrides:
      addCharsToLine in class TextBlock
    • wrapLineIfNeeded

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

      public VPos getAlignY()
      Returns the Y alignment.
    • setAlignY

      public void setAlignY(VPos aPos)
      Sets the Y alignment.
    • getAlignedY

      public double getAlignedY()
      Returns the y for alignment.
      Overrides:
      getAlignedY in class TextBlock
    • isWrapLines

      public boolean isWrapLines()
      Returns whether to wrap lines that overrun bounds.
    • 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 TextBlock.
      Overrides:
      getStartCharIndex in class TextBlock
    • setStartCharIndex

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

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

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

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

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

      public String getString()
      Returns the string for the text.
      Overrides:
      getString in class TextBlock
    • setString

      public void setString(String aString)
      Sets the text to the given string.
      Overrides:
      setString in class TextBlock
    • joinLineWithNextLine

      protected void joinLineWithNextLine(TextLine textLine)
      Override to wrap joined lines.
      Overrides:
      joinLineWithNextLine in class TextBlock
    • textBlockDidPropChange

      protected void textBlockDidPropChange(PropChange aPC)
      Updates lines for TextBlock changes.
    • updateLines

      protected void updateLines(int lineIndex)
      Updates lines for given char start and an old/new char end.
      Overrides:
      updateLines in class TextBlock
    • updateTextAll

      protected void updateTextAll()
      Updates all lines.
    • updateTextForCharRange

      protected void updateTextForCharRange(int startCharIndex, int endCharIndexBox, int endCharIndexBlock)
      Updates all lines.
    • 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 TextBlock
    • setHeight

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

      public double getPrefWidth(double aH)
      Returns the preferred width.
    • getPrefHeight

      public double getPrefHeight(double aW)
      Returns the preferred height.
    • scaleTextToFit

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

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

      protected TextToken[] createTokensForTextLine(TextLine aTextLine)
      Override to forward to source text.
      Overrides:
      createTokensForTextLine in class TextBlock
    • toXML

      public XMLElement toXML(XMLArchiver anArchiver)
      Override to use SourceText.
      Specified by:
      toXML in interface XMLArchiver.Archivable
      Overrides:
      toXML in class TextBlock
    • fromXML

      public Object fromXML(XMLArchiver anArchiver, XMLElement anElement)
      Override to use SourceText.
      Specified by:
      fromXML in interface XMLArchiver.Archivable
      Overrides:
      fromXML in class TextBlock