Package snap.view

Class TextArea

All Implemented Interfaces:
PropChange.DoChange, XMLArchiver.Archivable
Direct Known Subclasses:
DevPaneConsoleTextArea, TextView

public class TextArea extends ParentView
A view subclass for displaying and editing a TextBlock.
  • Field Details

  • Constructor Details

    • TextArea

      public TextArea()
      Constructor.
    • TextArea

      public TextArea(boolean isRichText)
      Constructor with option for RichText.
    • TextArea

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

    • getTextAdapter

      public TextAdapter getTextAdapter()
      Returns the text adapter.
    • createTextAdapter

      protected TextAdapter createTextAdapter(TextBlock textBlock)
      Override to create TextAreaKeys.
    • getTextBlock

      public TextBlock getTextBlock()
      Returns the text block that holds the text.
    • getSourceText

      public TextBlock getSourceText()
      Returns the root text block.
    • setSourceText

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

      public String getText()
      Returns the plain string of the text being edited.
      Overrides:
      getText in class View
    • setText

      public void setText(String aString)
      Set text string of text editor.
      Overrides:
      setText in class View
    • isEditable

      public boolean isEditable()
      Returns whether Text shape is editable.
    • setEditable

      public void setEditable(boolean aValue)
      Sets whether Text shape is editable.
    • 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.
    • isUndoActivated

      public boolean isUndoActivated()
      Returns whether undo is activated.
    • setUndoActivated

      public void setUndoActivated(boolean aValue)
      Called to activate undo.
    • isSyncTextFont

      public boolean isSyncTextFont()
      Returns whether to synchronize text area font with text block.
    • setSyncTextFont

      public void setSyncTextFont(boolean aValue)
      Sets whether to synchronize text area font with text block.
    • isSpellChecking

      public boolean isSpellChecking()
      Returns whether editor is doing check-as-you-type spelling.
    • isRichText

      public boolean isRichText()
      Returns whether text supports multiple styles.
    • setRichText

      public void setRichText(boolean aValue)
      Sets whether text supports multiple styles.
    • getDefaultTextStyle

      public TextStyle getDefaultTextStyle()
      Returns the default text style for text.
    • setDefaultTextStyle

      public void setDefaultTextStyle(TextStyle textStyle)
      Sets the default text style for text.
    • setDefaultTextStyleString

      public void setDefaultTextStyleString(String styleString)
      Sets default text style for given style string.
    • getDefaultLineStyle

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

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

      public int length()
      Returns the number of characters in the text string.
    • charAt

      public char charAt(int anIndex)
      Returns the individual character at given index.
    • isSelEmpty

      public boolean isSelEmpty()
      Returns whether the selection is empty.
    • getSelIndex

      public int getSelIndex()
      Returns the final character index of the selection (usually SelEnd).
    • getSelStart

      public int getSelStart()
      Returns the character index of the start of the text selection.
    • getSelEnd

      public int getSelEnd()
      Returns the character index of the end of the text selection.
    • getSel

      public TextSel getSel()
      Returns the text selection.
    • setSel

      public void setSel(int newStartEnd)
      Sets the character index of the text cursor.
    • setSel

      public void setSel(int aStart, int aEnd)
      Sets the character index of the start and end of the text selection.
    • selectAll

      public void selectAll()
      Selects all the characters in the text editor.
    • getTextFont

      public Font getTextFont()
      Returns the font of the text block.
    • setTextFont

      public void setTextFont(Font aFont)
      Sets the font of the text block.
    • getTextColor

      public Color getTextColor()
      Returns the color of the current selection or cursor.
      Overrides:
      getTextColor in class View
    • setTextColor

      public void setTextColor(Color aColor)
      Sets the color of the current selection or cursor.
      Overrides:
      setTextColor in class View
    • getFormat

      public TextFormat getFormat()
      Returns the format of the current selection or cursor.
    • setFormat

      public void setFormat(TextFormat aFormat)
      Sets the format of the current selection or cursor, after trying to expand the selection to encompass currently selected, @-sign delineated key.
    • isUnderlined

      public boolean isUnderlined()
      Returns whether TextView is underlined.
    • setUnderlined

      public void setUnderlined(boolean aValue)
      Sets whether TextView is underlined.
    • addChars

      public void addChars(CharSequence theChars)
      Adds the given chars to end of text.
    • addChars

      public void addChars(CharSequence theChars, int charIndex)
      Adds the given chars at given char index.
    • addCharsWithStyle

      public void addCharsWithStyle(CharSequence theChars, TextStyle textStyle)
      Adds the given chars with given style to text end.
    • addCharsWithStyle

      public void addCharsWithStyle(CharSequence theChars, TextStyle textStyle, int charIndex)
      Adds the given chars with given style to text at given index.
    • addCharsWithStyleString

      public void addCharsWithStyleString(CharSequence theChars, String styleString)
      Adds the given chars to text with given style string.
    • removeChars

      public void removeChars(int aStart, int anEnd)
      Deletes the given range of chars.
    • replaceChars

      public void replaceChars(CharSequence theChars)
      Replaces the current selection with the given string.
    • replaceChars

      public void replaceChars(CharSequence theChars, int startCharIndex, int endCharIndex)
      Replaces the current selection with the given string.
    • replaceCharsWithStyle

      public void replaceCharsWithStyle(CharSequence theChars, TextStyle textStyle, int aStart, int anEnd)
      Replaces the current selection with the given string.
    • delete

      public void delete()
      Deletes the current selection.
    • replaceCharsWithContent

      public void replaceCharsWithContent(Object theContent)
      Replaces the current selection with the given contents (TextBlock or String).
    • clear

      public void clear()
      Clears the text.
    • getLineCount

      public int getLineCount()
      Returns the number of lines.
    • getLine

      public TextLine getLine(int anIndex)
      Returns the individual line at given index.
    • getLineForCharIndex

      public TextLine getLineForCharIndex(int anIndex)
      Returns the line for the given character index.
    • getTokenForCharIndex

      public TextToken getTokenForCharIndex(int anIndex)
      Returns the token for given character index.
    • getCharIndexForXY

      public int getCharIndexForXY(double anX, double aY)
      Returns the char index for given point in text coordinate space.
    • paintFront

      protected void paintFront(Painter aPntr)
      Paint text.
      Overrides:
      paintFront in class View
    • processEvent

      public void processEvent(ViewEvent anEvent)
      Process event. Make this public so TextArea can be used to edit text outside of normal Views.
      Overrides:
      processEvent in class View
    • mousePressed

      protected void mousePressed(ViewEvent anEvent)
      Handles mouse pressed.
    • mouseDragged

      protected void mouseDragged(ViewEvent anEvent)
      Handles mouse dragged.
    • mouseReleased

      protected void mouseReleased(ViewEvent anEvent)
      Handles mouse released.
    • mouseMoved

      protected void mouseMoved(ViewEvent anEvent)
      Handle MouseMoved.
    • keyPressed

      protected void keyPressed(ViewEvent anEvent)
      Called when a key is pressed.
    • keyTyped

      protected void keyTyped(ViewEvent anEvent)
      Called when a key is typed.
    • keyReleased

      protected void keyReleased(ViewEvent anEvent)
      Called when a key is released.
    • processActionEvent

      protected void processActionEvent(ViewEvent anEvent)
      Called when action event is received.
    • 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.
    • scaleTextToFit

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

      public void cut()
      Copies the current selection onto the clip board, then deletes the current selection.
    • copy

      public void copy()
      Copies the current selection onto the clipboard.
    • paste

      public void paste()
      Pasts the current clipboard data over the current selection.
    • getClipboardContent

      protected Object getClipboardContent(Clipboard clipboard)
      Returns the clipboard content.
    • getUndoer

      public Undoer getUndoer()
      Returns the undoer.
    • undo

      public void undo()
      Called to undo the last text change.
    • redo

      public void redo()
      Called to redo the last text change.
    • getPrefWidthImpl

      protected double getPrefWidthImpl(double aH)
      Returns the width needed to display all characters.
      Overrides:
      getPrefWidthImpl in class View
    • getPrefHeightImpl

      protected double getPrefHeightImpl(double aW)
      Returns the height needed to display all characters.
      Overrides:
      getPrefHeightImpl in class View
    • setFont

      public void setFont(Font aFont)
      Sets the font of the current selection or cursor.
      Overrides:
      setFont in class ParentView
    • parentFontChanged

      protected void parentFontChanged()
      Override to update font.
      Overrides:
      parentFontChanged in class ParentView
    • handleTextAdapterPropChange

      protected void handleTextAdapterPropChange(PropChange aPC)
      Called when TextAdapter has prop change.
    • handleSourceTextPropChange

      protected void handleSourceTextPropChange(PropChange aPC)
      Called when SourceText changes (chars added, updated or deleted).
    • isHyphenating

      public static boolean isHyphenating()
      Returns whether layout tries to hyphenate wrapped words.
    • setHyphenating

      public static void setHyphenating(boolean aValue)
      Sets whether layout tries to hyphenate wrapped words.
    • getValuePropName

      public String getValuePropName()
      Returns a mapped property name.
      Overrides:
      getValuePropName in class View
    • toString

      public String toString()
      Standard toString implementation.
      Overrides:
      toString in class PropObject
    • initProps

      protected void initProps(PropSet aPropSet)
      Override to support properties for this class.
      Overrides:
      initProps in class ParentView
    • getPropValue

      public Object getPropValue(String aPropName)
      Override to support properties for this class.
      Overrides:
      getPropValue in class ParentView
    • setPropValue

      public void setPropValue(String aPropName, Object aValue)
      Override to support properties for this class.
      Overrides:
      setPropValue in class ParentView
    • toXML

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

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