Package snap.text
Class TextBox
java.lang.Object
snap.props.PropObject
snap.text.TextBlock
snap.text.TextBox
- All Implemented Interfaces:
CharSequence
,Cloneable
,PropChange.DoChange
,CharSequenceX
,XMLArchiver.Archivable
This TextBlock subclass adds support for text wrapping and syncs to a source TextBlock.
-
Field Summary
Fields inherited from class snap.text.TextBlock
_defaultLineStyle, _defaultTextStyle, _length, _lines, _mouseY, _prefW, _propChangeEnabled, Chars_Prop, DefaultTextStyle_Prop, LineStyle_Prop, Style_Prop, TextModified_Prop
Fields inherited from class snap.props.PropObject
_pcs, EMPTY_OBJECT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCharsToLine
(CharSequence theChars, TextStyle theStyle, int charIndex, TextLine textLine, boolean charsHaveNewline) Override to do wrapping.void
addCharsWithStyle
(CharSequence theChars, TextStyle theStyle, int anIndex) Override to forward to source text block.copyForRange
(int aStart, int aEnd) Override to forward to source text block.protected TextToken[]
createTokensForTextLine
(TextLine aTextLine) Override to forward to source text.fromXML
(XMLArchiver anArchiver, XMLElement anElement) Override to use SourceText.double
Returns the y for alignment.Returns the Y alignment.Returns the bounds path.double
Returns the font scale of the text box.protected double
getMaxHitX
(double aY, double aH) Returns the max x value that doesn't hit right border for given y/height.protected double
getMinHitX
(double aY, double aH, double anIndent) Returns the min x value that doesn't hit left border for given y/height and indent.double
getPrefHeight
(double aW) Returns the preferred height.double
getPrefWidth
(double aH) Returns the preferred width.Returns the source TextBlock.int
Returns the start char in source TextBlock.Returns the string for the text.protected boolean
isHitRight
(double aX, double aY, double aH) Returns whether given x location and run hit right border.boolean
Returns whether layout tries to hyphenate wrapped words.boolean
isLinked()
Returns whether text is linked to another text (and shouldn't add lines below bottom border).boolean
Returns whether this text box couldn't fit all text.boolean
Returns whether to wrap lines that overrun bounds.protected void
joinLineWithNextLine
(TextLine textLine) Override to wrap joined lines.void
removeChars
(int aStartCharIndex, int anEndCharIndex) Override to forward to source text block.void
replaceChars
(CharSequence theChars, TextStyle theStyle, int aStart, int anEnd) Override to forward to source text block.void
Scales font sizes of all text in TextBox to fit in bounds by finding/setting FontScale.void
Sets the Y alignment.void
setBoundsPath
(Shape aPath) Sets the bounds path.void
setDefaultTextStyle
(TextStyle aStyle) Override to forward to source text block.void
setFontScale
(double aValue) Sets the font scale of the text box.void
setHeight
(double aValue) Override to update layout.void
setHyphenate
(boolean aValue) Sets whether layout tries to hyphenate wrapped words.void
setLineStyle
(TextLineStyle aStyle, int aStart, int anEnd) Override to forward to source text block.void
setLineStyleValue
(String aKey, Object aValue, int aStart, int anEnd) Override to forward to source text block.void
setLinked
(boolean aValue) Returns whether text is linked to another text (and shouldn't add lines below bottom border).void
setRichText
(boolean aValue) Sets whether text supports multiple styles.void
setSourceText
(TextBlock aTextBlock) Sets the source TextBlock.void
setStartCharIndex
(int charIndex) Sets the start char in source TextBlock.void
Sets the text to the given string.void
setStyleValue
(String aKey, Object aValue, int aStart, int anEnd) Override to forward to source text block.void
setTextStyle
(TextStyle textStyle, int aStart, int anEnd) Override to forward to source text block.void
setWidth
(double aValue) Override to update layout.void
setWrapLines
(boolean aValue) Sets whether to wrap lines that overrun bounds.protected void
Updates lines for TextBlock changes.toXML
(XMLArchiver anArchiver) Override to use SourceText.protected void
updateLines
(int lineIndex) Updates lines for given char start and an old/new char end.protected void
Updates all lines.protected void
updateTextForCharRange
(int startCharIndex, int endCharIndexBox, int endCharIndexBlock) Updates all lines.protected void
wrapLineIfNeeded
(TextLine textLine) Wraps given line if needed by moving chars from last token(s) to next line.Methods inherited from class snap.text.TextBlock
activateUndo, addChars, addChars, addCharsWithStyle, addLine, addTextBlock, charAt, clear, clone, createLine, firePropChange, getAlignX, getBounds, getCharIndexForXY, getDefaultFont, getDefaultLineStyle, getDefaultTextColor, getDefaultTextStyle, getEndCharIndex, getFontForCharIndex, getHeight, getLastLine, getLine, getLineCount, getLineForCharIndex, getLineForY, getLineLongest, getLines, getLineStyleForCharIndex, getMaxX, getMaxY, getPathForCharRange, getPrefHeight, getPrefWidth, getPrefWidthForStartCharIndex, getRunForCharIndex, getRunForCharRange, getRunIterForCharRange, getTextStyleForCharIndex, getTextStyleForCharRange, getTokenForCharIndex, getUnderlineRuns, getUndoer, getWidth, getX, getY, indexOf, isPropChangeEnabled, isRichText, isTextModified, isUnderlined, length, moveLineCharsToNextLine, paint, paintLine, redo, removeCharsFromLine, removeLine, replaceChars, resetLineYForLinesAfterIndex, scaleFonts, setAlignX, setBounds, setBounds, setDefaultFont, setDefaultLineStyle, setDefaultTextColor, setPropChangeEnabled, setStyleValue, setStyleValue, setTextModified, setUnderlined, setX, setY, splitLineAtIndex, subSequence, toStringProps, undo, undoerAddPropChange, updateLine
Methods inherited from class snap.props.PropObject
addDeepChangeListener, addPropChangeListener, addPropChangeListener, firePropChange, firePropChange, getPropDefault, getPropForName, getPropParent, getPropSet, getPropsForArchival, getPropsForArchivalExtra, getPropsString, getPropValue, initProps, isPropDefault, processPropChange, removeDeepChangeListener, removePropChangeListener, removePropChangeListener, setPropsString, setPropValue, setPropValues, toString
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty, toString
Methods inherited from interface snap.util.CharSequenceX
getIndentLength, getIndentString, getLastChar, indexAfterNewline, indexAfterNewlineOrEnd, indexOfNewline, isAfterLineEnd, isLastCharNewline, isLineEnd, isLineEndChar, isWhiteSpace, lastIndexAfterNewline, lastIndexOfNewline, startsWith
-
Field Details
-
_fontScale
protected double _fontScale
-
-
Constructor Details
-
TextBox
public TextBox()Constructor. -
TextBox
public TextBox(boolean isRichText) Constructor with option for rich text. -
TextBox
Constructor for source text block.
-
-
Method Details
-
getSourceText
Returns the source TextBlock.- Overrides:
getSourceText
in classTextBlock
-
setSourceText
Sets the source TextBlock. -
setRichText
public void setRichText(boolean aValue) Sets whether text supports multiple styles.- Overrides:
setRichText
in classTextBlock
-
addCharsWithStyle
Override to forward to source text block.- Overrides:
addCharsWithStyle
in classTextBlock
-
removeChars
public void removeChars(int aStartCharIndex, int anEndCharIndex) Override to forward to source text block.- Overrides:
removeChars
in classTextBlock
-
replaceChars
Override to forward to source text block.- Overrides:
replaceChars
in classTextBlock
-
setTextStyle
Override to forward to source text block.- Overrides:
setTextStyle
in classTextBlock
-
setStyleValue
Override to forward to source text block.- Overrides:
setStyleValue
in classTextBlock
-
setLineStyle
Override to forward to source text block.- Overrides:
setLineStyle
in classTextBlock
-
setLineStyleValue
Override to forward to source text block.- Overrides:
setLineStyleValue
in classTextBlock
-
setDefaultTextStyle
Override to forward to source text block.- Overrides:
setDefaultTextStyle
in classTextBlock
-
copyForRange
Override to forward to source text block.- Overrides:
copyForRange
in classTextBlock
-
addCharsToLine
protected void addCharsToLine(CharSequence theChars, TextStyle theStyle, int charIndex, TextLine textLine, boolean charsHaveNewline) Override to do wrapping.- Overrides:
addCharsToLine
in classTextBlock
-
wrapLineIfNeeded
Wraps given line if needed by moving chars from last token(s) to next line. -
getAlignY
Returns the Y alignment. -
setAlignY
Sets the Y alignment. -
getAlignedY
public double getAlignedY()Returns the y for alignment.- Overrides:
getAlignedY
in classTextBlock
-
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. -
isHyphenate
public boolean isHyphenate()Returns whether layout tries to hyphenate wrapped words. -
setHyphenate
public void setHyphenate(boolean aValue) Sets whether layout tries to hyphenate wrapped words. -
isLinked
public boolean isLinked()Returns whether text is linked to another text (and shouldn't add lines below bottom border). -
setLinked
public void setLinked(boolean aValue) Returns whether text is linked to another text (and shouldn't add lines below bottom border). -
getStartCharIndex
public int getStartCharIndex()Returns the start char in source TextBlock.- Overrides:
getStartCharIndex
in classTextBlock
-
setStartCharIndex
public void setStartCharIndex(int charIndex) Sets the start char in source TextBlock. -
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. -
getBoundsPath
Returns the bounds path. -
setBoundsPath
Sets the bounds path. -
getString
Returns the string for the text. -
setString
Sets the text to the given string. -
joinLineWithNextLine
Override to wrap joined lines.- Overrides:
joinLineWithNextLine
in classTextBlock
-
textBlockDidPropChange
Updates lines for TextBlock changes. -
updateLines
protected void updateLines(int lineIndex) Updates lines for given char start and an old/new char end.- Overrides:
updateLines
in classTextBlock
-
updateTextAll
protected void updateTextAll()Updates all lines. -
updateTextForCharRange
protected void updateTextForCharRange(int startCharIndex, int endCharIndexBox, int endCharIndexBlock) Updates all lines. -
isHitRight
protected boolean isHitRight(double aX, double aY, double aH) Returns whether given x location and run hit right border. -
getMinHitX
protected double getMinHitX(double aY, double aH, double anIndent) Returns the min x value that doesn't hit left border for given y/height and indent. -
getMaxHitX
protected double getMaxHitX(double aY, double aH) Returns the max x value that doesn't hit right border for given y/height. -
setWidth
public void setWidth(double aValue) Override to update layout. -
setHeight
public void setHeight(double aValue) Override to update layout. -
getPrefWidth
public double getPrefWidth(double aH) Returns the preferred width. -
getPrefHeight
public double getPrefHeight(double aW) Returns the preferred height. -
scaleTextToFit
public void scaleTextToFit()Scales font sizes of all text in TextBox to fit in bounds by finding/setting FontScale. -
isTextOutOfBounds
public boolean isTextOutOfBounds()Returns whether this text box couldn't fit all text. -
createTokensForTextLine
Override to forward to source text.- Overrides:
createTokensForTextLine
in classTextBlock
-
toXML
Override to use SourceText.- Specified by:
toXML
in interfaceXMLArchiver.Archivable
- Overrides:
toXML
in classTextBlock
-
fromXML
Override to use SourceText.- Specified by:
fromXML
in interfaceXMLArchiver.Archivable
- Overrides:
fromXML
in classTextBlock
-