Package snap.view

Class StringView

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

public class StringView extends View implements Cloneable
A view subclass to display a text string in a single style.
  • Field Details

  • Constructor Details

    • StringView

      public StringView()
      Constructor.
    • StringView

      public StringView(String aString)
      Constructor with string.
  • Method Details

    • getText

      public String getText()
      Returns the text.
      Overrides:
      getText in class View
    • setText

      public void setText(String aValue)
      Sets the text.
      Overrides:
      setText in class View
    • getTextStyle

      public TextStyle getTextStyle()
      Returns the TextStyle.
    • setTextStyle

      public void setTextStyle(TextStyle aStyle)
      Sets the TextStyle.
    • getTextFill

      public Paint getTextFill()
      Returns the text fill.
    • setTextFill

      public void setTextFill(Paint aPaint)
      Sets the text fill.
    • isFontSizing

      public boolean isFontSizing()
      Returns whether to size to font (looser) instead of glyphs (tighter).
    • setFontSizing

      public void setFontSizing(boolean aValue)
      Sets whether to size to font (looser) instead of glyphs (tighter).
    • isShrinkToFit

      public boolean isShrinkToFit()
      Returns whether text should shrink to fit.
    • setShrinkToFit

      public void setShrinkToFit(boolean aValue)
      Sets whether text should shrink to fit.
    • length

      public int length()
      Returns the text length.
    • getTextWidth

      public double getTextWidth()
      Returns the width of the string (aka the 'advance').
    • getTextHeight

      public double getTextHeight()
      Returns the height of the current string/font (aka the 'line height').
    • getAscent

      public double getAscent()
      Returns the ascent.
    • getDescent

      public double getDescent()
      Returns the descent.
    • isTextFits

      public boolean isTextFits()
      Returns whether text fits in box.
    • getTextBounds

      public Rect getTextBounds()
      Returns the text bounds.
    • getTextBounds

      public Rect getTextBounds(int aStart, int aEnd)
      Returns the text bounds for the given range of characters.
    • getCharIndexForX

      public int getCharIndexForX(double aX)
      Returns the char index for the X location.
    • setCenteredXY

      public void setCenteredXY(double aX, double aY)
      Sets the box centered around given X/Y.
    • relayout

      public void relayout()
      Override to clear size info.
      Overrides:
      relayout in class View
    • relayoutParent

      public void relayoutParent()
      Override to clear size info.
      Overrides:
      relayoutParent in class View
    • getPrefWidthImpl

      protected double getPrefWidthImpl(double aH)
      Returns the preferred width.
      Overrides:
      getPrefWidthImpl in class View
    • getPrefHeightImpl

      protected double getPrefHeightImpl(double aW)
      Returns the preferred height.
      Overrides:
      getPrefHeightImpl in class View
    • paintStringView

      public void paintStringView(Painter aPntr)
      A paint method for painting StringView outside of View hierarchy.
    • paintFront

      protected void paintFront(Painter aPntr)
      Paints StringView.
      Overrides:
      paintFront in class View
    • paintString

      protected void paintString(Painter aPntr)
      Paints StringView.
    • setFont

      public void setFont(Font aFont)
      Override to update TextRun.
      Overrides:
      setFont in class View
    • parentFontChanged

      protected void parentFontChanged()
      Override to update TextRun.
      Overrides:
      parentFontChanged in class View
    • setWidth

      public void setWidth(double aValue)
      Override to clear NeedsResize.
      Overrides:
      setWidth in class View
    • setHeight

      public void setHeight(double aValue)
      Override to clear NeedsResize.
      Overrides:
      setHeight in class View
    • clone

      public StringView clone()
      Returns a copy of this StringView.
      Overrides:
      clone in class View
    • toXML

      public XMLElement toXML(XMLArchiver anArchiver)
      XML archival.
      Specified by:
      toXML in interface XMLArchiver.Archivable
      Overrides:
      toXML in class View
    • fromXML

      public View fromXML(XMLArchiver anArchiver, XMLElement anElement)
      XML unarchival.
      Specified by:
      fromXML in interface XMLArchiver.Archivable
      Overrides:
      fromXML in class View