Package snap.view

Class TextArea

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

public class TextArea extends View
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

    • getTextBlock

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

      protected void setTextBlock(TextBlock aTextBlock)
      Sets 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.
    • 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.
    • getDefaultStyle

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

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

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

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

      public boolean isFireActionOnEnterKey()
      Returns whether text view fires action on enter key press.
    • setFireActionOnEnterKey

      public void setFireActionOnEnterKey(boolean aValue)
      Sets whether text area sends action on enter key press.
    • isFireActionOnFocusLost

      public boolean isFireActionOnFocusLost()
      Returns whether text view fires action on focus lost (if text changed).
    • setFireActionOnFocusLost

      public void setFireActionOnFocusLost(boolean aValue)
      Sets whether text area sends action on focus lost (if text changed).
    • 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.
    • getSelAnchor

      public int getSelAnchor()
      Returns the initial character index of the selection (usually SelStart).
    • 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.
    • repaintSel

      protected void repaintSel()
      Repaint the selection.
    • scrollSelToVisible

      protected void scrollSelToVisible()
      Scrolls Selection to visible.
    • setFont

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

      protected void parentFontChanged()
      Override to update font.
      Overrides:
      parentFontChanged in class View
    • 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.
    • setTextColor

      public void setTextColor(Color aColor)
      Sets the color of the current selection or cursor.
    • 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.
    • setSuperscript

      public void setSuperscript()
      Sets current selection to superscript.
    • setSubscript

      public void setSubscript()
      Sets current selection to subscript.
    • getLineAlign

      public HPos getLineAlign()
      Returns the text line alignment.
    • setLineAlign

      public void setLineAlign(HPos anAlign)
      Sets the text line alignment.
    • isLineJustify

      public boolean isLineJustify()
      Returns whether the text line justifies text.
    • setLineJustify

      public void setLineJustify(boolean aValue)
      Sets whether the text line justifies text.
    • getTextStyleForCharIndex

      public TextStyle getTextStyleForCharIndex(int charIndex)
      Returns the style at given char index.
    • getSelStyle

      public TextStyle getSelStyle()
      Returns the TextStyle for the current selection and/or input characters.
    • setSelStyleValue

      public void setSelStyleValue(String aKey, Object aValue)
      Sets the attributes that are applied to current selection or newly typed chars.
    • getSelLineStyle

      public TextLineStyle getSelLineStyle()
      Returns the TextLineStyle for currently selection.
    • setSelLineStyleValue

      public void setSelLineStyleValue(String aKey, Object aValue)
      Sets the line attributes that are applied to current selection or newly typed chars.
    • addChars

      public void addChars(CharSequence theChars, Object... theAttrs)
      Adds the given string to end of text.
    • addChars

      public void addChars(CharSequence theChars, TextStyle aStyle)
      Adds the given string with given style to text at given index.
    • addChars

      public void addChars(CharSequence theChars, TextStyle aStyle, int anIndex)
      Adds the given string with given style to text at given index.
    • delete

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

      public void delete(int aStart, int anEnd, boolean doUpdateSel)
      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.
    • replaceChars

      public void replaceChars(CharSequence theChars, TextStyle aStyle, int aStart, int anEnd, boolean doUpdateSel)
      Replaces the current selection with the given string.
    • replaceCharsWithContent

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

      public void selectForward()
      Moves the selection index forward a character (or if a range is selected, moves to end of range).
    • selectBackward

      public void selectBackward()
      Moves the selection index backward a character (or if a range is selected, moves to beginning of range).
    • selectUp

      public void selectUp()
      Moves the selection index up a line, trying to preserve distance from beginning of line.
    • selectDown

      public void selectDown()
      Moves the selection index down a line, trying preserve distance from beginning of line.
    • selectLineStart

      public void selectLineStart()
      Moves the insertion point to the beginning of line.
    • selectLineEnd

      public void selectLineEnd()
      Moves the insertion point to next newline or text end.
    • deleteBackward

      public void deleteBackward()
      Deletes the character before of the insertion point.
    • deleteForward

      public void deleteForward()
      Deletes the character after of the insertion point.
    • deleteToLineEnd

      public void deleteToLineEnd()
      Deletes the characters from the insertion point to the end of the line.
    • 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.
    • getTextLinkForXY

      public TextLink getTextLinkForXY(double aX, double aY)
      Returns the link at given XY.
    • getSelColor

      public Color getSelColor()
      Returns the selection color.
    • paintFront

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

      protected void paintSel(Painter aPntr)
      Paints the selection.
    • 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.
    • createTextAreaKeys

      protected TextAreaKeys createTextAreaKeys()
      Override to create TextAreaKeys.
    • showCursor

      public void showCursor()
      Shows the cursor.
    • hideCursor

      public void hideCursor()
      Hides the cursor.
    • isShowCaret

      public boolean isShowCaret()
      Returns whether to show carat.
    • setShowCaret

      protected void setShowCaret(boolean aValue)
      Sets whether to show carat.
    • isCaretNeeded

      protected boolean isCaretNeeded()
      Returns whether caret is needed (true when text is focused, showing and empty selection).
    • setCaretAnim

      protected void setCaretAnim()
      Sets the caret animation to whether it's needed.
    • isCaretAnim

      public boolean isCaretAnim()
      Returns whether caret is flashing.
    • setCaretAnim

      public void setCaretAnim(boolean aValue)
      Sets whether caret is flashing.
    • 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.
    • openLink

      protected void openLink(String aLink)
      Opens a given link.
    • 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.
    • handleSourceTextPropChange

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

      protected void textDidChange()
      Called when text changes in some way.
    • getDefaultFill

      public Paint getDefaultFill()
      Override to return white.
      Overrides:
      getDefaultFill in class View
    • 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
    • setWidth

      public void setWidth(double aWidth)
      Override to update getTextBlock.Rect.
      Overrides:
      setWidth in class View
    • setHeight

      public void setHeight(double aHeight)
      Override to update getTextBlock.Rect.
      Overrides:
      setHeight in class View
    • getTextBounds

      protected Rect getTextBounds()
      Sets the Text.Rect from text area.
    • updateTextBlockBounds

      protected void updateTextBlockBounds()
      Sets the TextBlock.Bounds from text bounds.
    • setParent

      protected void setParent(ParentView aPar)
      Override to update font.
      Overrides:
      setParent in class View
    • setShowing

      protected void setShowing(boolean aValue)
      Override to check caret animation and scrollSelToVisible when showing.
      Overrides:
      setShowing in class View
    • setAlign

      public void setAlign(Pos aPos)
      Override to forward to text box.
      Overrides:
      setAlign in class View
    • setFocused

      protected void setFocused(boolean aValue)
      Override to check caret animation and repaint.
      Overrides:
      setFocused in class View
    • getValuePropName

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

      public Shape getSelPath()
      Returns the path for the current selection.
    • 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.
    • toString

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

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

      protected void toXMLTextArea(XMLArchiver anArchiver, XMLElement xml)
      XML archival.
    • fromXML

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

      protected void fromXMLTextArea(XMLArchiver anArchiver, XMLElement anElement)
      XML unarchival.