Package snap.view

Class TextArea

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

public class TextArea extends View
A view subclass for displaying and editing a TextDoc (using TextBox).
  • Field Details

  • Constructor Details

    • TextArea

      public TextArea()
      Creates a new TextArea.
  • Method Details

    • getTextBox

      public TextBox getTextBox()
      Returns the text that is being edited.
    • setTextBox

      public void setTextBox(TextBox aTextBox)
      Returns the text box used to layout text.
    • createTextBox

      protected TextBox createTextBox()
      Creates a new TextBox.
    • getTextDoc

      public TextDoc getTextDoc()
      Returns the TextDoc.
    • setTextDoc

      public void setTextDoc(TextDoc aTextDoc)
      Sets the TextDoc.
    • 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.
    • 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.
    • getFont

      public Font getFont()
      Returns the font of the current selection or cursor.
      Overrides:
      getFont in class View
    • 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
    • getTextColor

      public Color getTextColor()
      Returns the color of the current selection or cursor.
    • setTextColor

      public void setTextColor(Paint aColor)
      Sets the color of the current selection or cursor.
    • getTextFill

      public Paint getTextFill()
      Returns the color of the current selection or cursor.
    • setTextFill

      public void setTextFill(Paint aColor)
      Sets the color of the current selection or cursor.
    • getTextBorder

      public Border getTextBorder()
      Returns whether current selection is outlined.
    • setTextBorder

      public void setTextBorder(Border aBorder)
      Sets whether current selection is outlined.
    • 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.
    • getStyleForCharIndex

      public TextStyle getStyleForCharIndex(int anIndex)
      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(String aStr, Object... theAttrs)
      Adds the given string to end of text.
    • addChars

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

      public void addChars(String aStr, 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(String aString)
      Replaces the current selection with the given string.
    • replaceChars

      public void replaceChars(String aString, TextStyle aStyle, int aStart, int anEnd, boolean doUpdateSel)
      Replaces the current selection with the given string.
    • replaceCharsWithTextDoc

      public void replaceCharsWithTextDoc(TextDoc aTextDoc, int aStart, int anEnd, boolean doUpdateSel)
      Replaces the current selection with the given TextDoc.
    • replaceCharsWithContent

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

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

      public void selectBackward(boolean isShiftDown)
      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 TextBoxLine getLine(int anIndex)
      Returns the individual line at given index.
    • getLineLast

      public TextBoxLine getLineLast()
      Returns the last line.
    • getLineForCharIndex

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

      public TextBoxToken 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.
    • 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 boolean undo()
      Called to undo the last edit operation in the editor.
    • redo

      public boolean redo()
      Called to redo the last undo operation in the editor.
    • undoerAddPropChange

      protected void undoerAddPropChange(PropChange anEvent)
      Adds a property change to undoer.
    • undoerSaveChanges

      public void undoerSaveChanges()
      Saves changes to undoer.
    • getUndoSelection

      protected Object getUndoSelection()
      Returns a selection object for undoer.
    • textDocDidPropChange

      protected void textDocDidPropChange(PropChange aPC)
      Called when TextDoc 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
    • getTextBoxBounds

      protected Rect getTextBoxBounds()
      Sets the Text.Rect from text area.
    • setTextBoxBounds

      protected void setTextBoxBounds()
      Sets the Text.Rect from text area.
    • 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
    • fromXML

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