Package snap.text

Class TextAdapter

All Implemented Interfaces:
PropChange.DoChange

public class TextAdapter extends PropObject
This class acts as an intermediary between a 'text view' and a text block, handling selection, editing, cursor input events, etc.
  • Field Details

  • Constructor Details

    • TextAdapter

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

    • getView

      public View getView()
      Returns the view.
    • setView

      public void setView(View aView)
      Sets the view.
    • getTextBlock

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

      public 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.
    • setText

      public void setText(String aString)
      Set text string of text editor.
    • 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.
    • addSourceTextPropChangeListener

      public void addSourceTextPropChangeListener(PropChangeListener propChangeListener)
      Adds a prop change listener to SourceText.
    • removeSourceTextPropChangeListener

      public void removeSourceTextPropChangeListener(PropChangeListener propChangeListener)
      Removes a prop change listener to SourceText.
    • getLinkHandler

      public BiConsumer<ViewEvent,String> getLinkHandler()
      Returns the consumer that is called when a link is activated.
    • setLinkHandler

      public void setLinkHandler(BiConsumer<ViewEvent,String> linkHandler)
      Sets the consumer that is called when a link is activated.
    • 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.
    • 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.
    • selectLine

      public void selectLine(int lineIndex)
      Selects a given line number.
    • repaintSel

      protected void repaintSel()
      Repaint the selection.
    • scrollSelToVisible

      protected void scrollSelToVisible()
      Scrolls Selection to visible.
    • 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.
    • getSelTextStyle

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

      public void setSelTextStyleValue(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)
      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).
    • 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.
    • paintAll

      public void paintAll(Painter aPntr)
      Paint selection and text.
    • paintSel

      public void paintSel(Painter aPntr)
      Paints the selection.
    • paintText

      public void paintText(Painter aPntr)
      Paint text.
    • processEvent

      public void processEvent(ViewEvent anEvent)
      Process event.
    • mousePressed

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

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

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

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

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

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

      public void keyReleased(ViewEvent anEvent)
      Called when a key is released.
    • 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).
    • updateCaretAnim

      protected void updateCaretAnim()
      Sets the caret animation to whether it's needed.
    • 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

      public 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.
    • getTextBounds

      public Rect getTextBounds()
      Returns the area bounds for given view.
    • setTextBounds

      public void setTextBounds(Rect boundsRect)
      Sets the text bounds.
    • getPrefWidth

      public double getPrefWidth()
      Returns the width needed to display all characters.
    • getPrefHeight

      public double getPrefHeight(double aW)
      Returns the height needed to display all characters.
    • handleLinkEvent

      protected void handleLinkEvent(ViewEvent anEvent, String aLink)
      Called when link is triggered.
    • handleSourceTextPropChange

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

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