Package snap.text
Class TextAdapter
java.lang.Object
snap.props.PropObject
snap.text.TextAdapter
- All Implemented Interfaces:
PropChange.DoChange
This class acts as an intermediary between a 'text view' and a text block, handling selection, editing, cursor
input events, etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TextBlock
protected View
static final String
static boolean
static final String
static final String
static final String
static final String
static final String
Fields inherited from class snap.props.PropObject
_pcs, EMPTY_OBJECT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChars
(CharSequence theChars) Adds the given chars to end of text.void
addChars
(CharSequence theChars, int charIndex) Adds the given chars at given char index.void
addCharsWithStyle
(CharSequence theChars, TextStyle textStyle) Adds the given chars with given style to text end.void
addCharsWithStyle
(CharSequence theChars, TextStyle textStyle, int charIndex) Adds the given chars with given style to text at given index.void
addCharsWithStyleString
(CharSequence theChars, String styleString) Adds the given chars to text with given style string.void
addSourceTextPropChangeListener
(PropChangeListener propChangeListener) Adds a prop change listener to SourceText.char
charAt
(int anIndex) Returns the individual character at given index.void
clear()
Clears the text.void
copy()
Copies the current selection onto the clipboard.void
cut()
Copies the current selection onto the clip board, then deletes the current selection.void
delete()
Deletes the current selection.void
Deletes the character before of the insertion point.void
Deletes the character after of the insertion point.void
Deletes the characters from the insertion point to the end of the line.int
getCharIndexForXY
(double anX, double aY) Returns the char index for given point in text coordinate space.getClipboardContent
(Clipboard clipboard) Returns the clipboard content.Returns the default line style for text.Returns the default text style for text.double
Returns the font scale of the text box.Returns the format of the current selection or cursor.getLine
(int anIndex) Returns the individual line at given index.Returns the text line alignment.int
Returns the number of lines.getLineForCharIndex
(int anIndex) Returns the line for the given character index.Returns the consumer that is called when a link is activated.double
getPrefHeight
(double aW) Returns the height needed to display all characters.double
Returns the width needed to display all characters.getSel()
Returns the text selection.int
Returns the initial character index of the selection (usually SelStart).int
Returns the character index of the end of the text selection.int
Returns the final character index of the selection (usually SelEnd).Returns the TextLineStyle for currently selection.int
Returns the character index of the start of the text selection.Returns the TextStyle for the current selection and/or input characters.Returns the root text block.getText()
Returns the plain string of the text being edited.Returns the text block that holds the text.Returns the area bounds for given view.Returns the color of the current selection or cursor.Returns the font of the text block.getTextLinkForXY
(double aX, double aY) Returns the link at given XY.getTextStyleForCharIndex
(int charIndex) Returns the style at given char index.getTokenForCharIndex
(int anIndex) Returns the token for given character index.Returns the undoer.getView()
Returns the view.protected void
handleLinkEvent
(ViewEvent anEvent, String aLink) Called when link is triggered.protected void
Called when SourceText changes (chars added, updated or deleted).void
Hides the cursor.protected boolean
Returns whether caret is needed (true when text is focused, showing and empty selection).boolean
Returns whether Text shape is editable.boolean
Returns whether the text line justifies text.boolean
Returns whether text supports multiple styles.boolean
Returns whether the selection is empty.boolean
Returns whether to show carat.boolean
Returns whether editor is doing check-as-you-type spelling.boolean
Returns whether TextView is underlined.boolean
Returns whether undo is activated.boolean
Returns whether to wrap lines that overrun bounds.void
keyPressed
(ViewEvent anEvent) Called when a key is pressed.void
keyReleased
(ViewEvent anEvent) Called when a key is released.void
Called when a key is typed.int
length()
Returns the number of characters in the text string.void
mouseDragged
(ViewEvent anEvent) Handles mouse dragged.void
mouseMoved
(ViewEvent anEvent) Handle MouseMoved.void
mousePressed
(ViewEvent anEvent) Handles mouse pressed.void
mouseReleased
(ViewEvent anEvent) Handles mouse released.void
Paint selection and text.void
Paints the selection.void
Paint text.void
paste()
Pasts the current clipboard data over the current selection.void
processEvent
(ViewEvent anEvent) Process event.void
redo()
Called to redo the last text change.void
removeChars
(int aStart, int anEnd) Deletes the given range of chars.void
removeSourceTextPropChangeListener
(PropChangeListener propChangeListener) Removes a prop change listener to SourceText.protected void
Repaint the selection.void
replaceChars
(CharSequence theChars) Replaces the current selection with the given string.void
replaceChars
(CharSequence theChars, int startCharIndex, int endCharIndex) Replaces the current selection with the given string.void
replaceCharsWithContent
(Object theContent) Replaces the current selection with the given contents (TextBlock or String).void
replaceCharsWithStyle
(CharSequence theChars, TextStyle textStyle, int aStart, int anEnd) Replaces the current selection with the given string.void
Scales font sizes of all text in TextBox to fit in bounds by finding/setting FontScale.protected void
Scrolls Selection to visible.void
Selects all the characters in the text editor.void
Moves the selection index backward a character (or if a range is selected, moves to beginning of range).void
Moves the selection index down a line, trying preserve distance from beginning of line.void
Moves the selection index forward a character (or if a range is selected, moves to end of range).void
selectLine
(int lineIndex) Selects a given line number.void
Moves the insertion point to next newline or text end.void
Moves the insertion point to the beginning of line.void
selectUp()
Moves the selection index up a line, trying to preserve distance from beginning of line.void
setDefaultLineStyle
(TextLineStyle aLineStyle) Sets the default line style.void
setDefaultTextStyle
(TextStyle textStyle) Sets the default text style for text.void
setDefaultTextStyleString
(String styleString) Sets default text style for given style string.void
setEditable
(boolean aValue) Sets whether Text shape is editable.void
setFontScale
(double aValue) Sets the font scale of the text box.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.void
setLineAlign
(HPos anAlign) Sets the text line alignment.void
setLineJustify
(boolean aValue) Sets whether the text line justifies text.void
setLinkHandler
(BiConsumer<ViewEvent, String> linkHandler) Sets the consumer that is called when a link is activated.void
setRichText
(boolean aValue) Sets whether text supports multiple styles.void
setSel
(int newStartEnd) Sets the character index of the text cursor.void
setSel
(int aStart, int aEnd) Sets the character index of the start and end of the text selection.void
setSelLineStyleValue
(String aKey, Object aValue) Sets the line attributes that are applied to current selection or newly typed chars.void
setSelTextStyleValue
(String aKey, Object aValue) Sets the attributes that are applied to current selection or newly typed chars.protected void
setShowCaret
(boolean aValue) Sets whether to show carat.void
setSourceText
(TextBlock aTextBlock) Sets the source TextBlock.void
Sets current selection to subscript.void
Sets current selection to superscript.void
Set text string of text editor.void
setTextBlock
(TextBlock aTextBlock) Sets the text block that holds the text.void
setTextBounds
(Rect boundsRect) Sets the text bounds.void
setTextColor
(Color aColor) Sets the color of the current selection or cursor.void
setTextFont
(Font aFont) Sets the font of the text block.void
setUnderlined
(boolean aValue) Sets whether TextView is underlined.void
setUndoActivated
(boolean aValue) Called to activate undo.void
Sets the view.void
setWrapLines
(boolean aValue) Sets whether to wrap lines that overrun bounds.void
Shows the cursor.toString()
Standard toString implementation.void
undo()
Called to undo the last text change.protected void
Sets the caret animation to whether it's needed.Methods inherited from class snap.props.PropObject
addDeepChangeListener, addPropChangeListener, addPropChangeListener, clone, firePropChange, firePropChange, firePropChange, getPropDefault, getPropForName, getPropParent, getPropSet, getPropsForArchival, getPropsForArchivalExtra, getPropsString, getPropValue, initProps, isPropDefault, processArchivedNode, processPropChange, processUnarchivedNode, removeDeepChangeListener, removePropChangeListener, removePropChangeListener, setPropsString, setPropValue, setPropValues, toStringProps
-
Field Details
-
_view
-
_textBlock
-
isSpellChecking
public static boolean isSpellChecking -
SNAP_RICHTEXT_TYPE
- See Also:
-
RichText_Prop
- See Also:
-
Editable_Prop
- See Also:
-
WrapLines_Prop
- See Also:
-
SourceText_Prop
- See Also:
-
Selection_Prop
- See Also:
-
-
Constructor Details
-
TextAdapter
Constructor for source text block.
-
-
Method Details
-
getView
Returns the view. -
setView
Sets the view. -
getTextBlock
Returns the text block that holds the text. -
setTextBlock
Sets the text block that holds the text. -
getSourceText
Returns the root text block. -
setSourceText
Sets the source TextBlock. -
getText
Returns the plain string of the text being edited. -
setText
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
Adds a prop change listener to SourceText. -
removeSourceTextPropChangeListener
Removes a prop change listener to SourceText. -
getLinkHandler
Returns the consumer that is called when a link is activated. -
setLinkHandler
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
Returns the default text style for text. -
setDefaultTextStyle
Sets the default text style for text. -
setDefaultTextStyleString
Sets default text style for given style string. -
getDefaultLineStyle
Returns the default line style for text. -
setDefaultLineStyle
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
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
Returns the font of the text block. -
setTextFont
Sets the font of the text block. -
getTextColor
Returns the color of the current selection or cursor. -
setTextColor
Sets the color of the current selection or cursor. -
getFormat
Returns the format of the current selection or cursor. -
setFormat
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
Returns the text line alignment. -
setLineAlign
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
Returns the style at given char index. -
getSelTextStyle
Returns the TextStyle for the current selection and/or input characters. -
setSelTextStyleValue
Sets the attributes that are applied to current selection or newly typed chars. -
getSelLineStyle
Returns the TextLineStyle for currently selection. -
setSelLineStyleValue
Sets the line attributes that are applied to current selection or newly typed chars. -
addChars
Adds the given chars to end of text. -
addChars
Adds the given chars at given char index. -
addCharsWithStyle
Adds the given chars with given style to text end. -
addCharsWithStyle
Adds the given chars with given style to text at given index. -
addCharsWithStyleString
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
Replaces the current selection with the given string. -
replaceChars
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
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
Returns the individual line at given index. -
getLineForCharIndex
Returns the line for the given character index. -
getTokenForCharIndex
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
Returns the link at given XY. -
paintAll
Paint selection and text. -
paintSel
Paints the selection. -
paintText
Paint text. -
processEvent
Process event. -
mousePressed
Handles mouse pressed. -
mouseDragged
Handles mouse dragged. -
mouseReleased
Handles mouse released. -
mouseMoved
Handle MouseMoved. -
keyPressed
Called when a key is pressed. -
keyTyped
Called when a key is typed. -
keyReleased
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
Returns the clipboard content. -
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
Returns the area bounds for given view. -
setTextBounds
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
Called when link is triggered. -
handleSourceTextPropChange
Called when SourceText changes (chars added, updated or deleted). -
toString
Standard toString implementation.- Overrides:
toString
in classPropObject
-