Package snap.text
Class TextBox
java.lang.Object
snap.text.TextBox
This class manages a TextDoc to be rendered and edited in a bounding area.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTextBox()
Constructor.TextBox
(CharSequence theChars) Creates a new TextBox initialized with the given String and no attributes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChars
(CharSequence theChars, TextStyle theStyle, int anIndex) Adds characters with attributes to this text at given index.protected void
addLinesForCharRange
(int aLineIndex, int aStartCharIndex, int aEndCharIndex) Removes the lines from given char index to given char index.char
charAt
(int anIndex) Returns the char value at the specified index.protected TextBoxLine
createTextBoxLine
(TextLine aTextLine, int startCharIndex, int aLineIndex) Create and return TextBoxLines for given TextLine, start char index and line index.protected TextDoc
Creates the default TextDoc.double
Returns the y for alignment.Returns the Y alignment.Returns the current bounds.Returns the bounds path.int
getCharIndexForXY
(double anX, double aY) Returns the character index for the given x/y point.int
Returns the end char in TextDoc.double
Returns the font scale of the text box.double
Returns the height.getLine
(int anIndex) Returns the individual text line in this text.int
Returns the number of lines in this text.getLineForCharIndex
(int anIndex) Returns the TextLine at the given char index.getLineForY
(double aY) Returns the line for the given y value.Returns the last line.Returns the longest line.getLines()
Returns the list of lines.protected double
getMaxHitX
(double aY, double aH) Returns the max x value that doesn't hit right border for given y/height.double
getMaxX()
Returns the max X.double
getMaxY()
Returns the max Y.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.getPathForCharRange
(int aStartCharIndex, int aEndCharIndex) Returns a path for two char indexes - it will be a a simple box with extensions for first/last lines.double
getPrefHeight
(double aW) Returns the preferred height.double
getPrefWidth
(double aH) Returns the preferred width.int
Returns the start char in TextDoc.Returns the string for the text.Returns the TextDoc.int
Returns the number of characters in the text.getTokenForCharIndex
(int anIndex) Returns the token at given index.getUnderlineRuns
(Rect aRect) Returns underlined runs for text box.double
getWidth()
Returns the width.double
getX()
Returns the X location.double
getY()
Returns the Y location.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 text supports multiple styles.boolean
Returns whether this text box couldn't fit all text.boolean
Returns whether text box contains an underlined run.boolean
Returns whether to wrap lines that overrun bounds.int
length()
Returns the number of chars currently in text box.void
Paint TextBox to given painter.void
removeChars
(int aStart, int anEnd) Removes characters in given range.protected void
removeLinesForCharRange
(int startCharIndex, int endCharIndex) Removes the lines from given char index to given char index, extended to cover entire TextDoc.TextLines.void
replaceChars
(CharSequence theChars, TextStyle theStyle, int aStart, int anEnd) Replaces chars in given range, with given String, using the given attributes.void
Scales font sizes of all text in TextBox to fit in bounds by finding/setting FontScale.void
Sets the Y alignment.void
setBounds
(double aX, double aY, double aW, double aH) Sets the rect location and size.void
Sets the rect location and size.void
setBoundsPath
(Shape aPath) Sets the bounds path.void
setFontScale
(double aValue) Sets the font scale of the text box.void
setHeight
(double aValue) Sets the width.void
setHyphenate
(boolean aValue) Sets whether layout tries to hyphenate wrapped words.void
setLinked
(boolean aValue) Returns whether text is linked to another text (and shouldn't add lines below bottom border).protected void
Updates all lines.void
setRichText
(boolean aValue) Sets whether text supports multiple styles.void
setStartCharIndex
(int charIndex) Sets the start char in TextDoc.void
Sets the text to the given string.void
setTextDoc
(TextDoc aTextDoc) Sets the TextDoc.protected void
setUpdateBounds
(int aStart, int aEnd) Sets the update bounds (in characters from start and from end).void
setWidth
(double aValue) Sets the width.void
setWrapLines
(boolean aValue) Sets whether to wrap lines that overrun bounds.void
setX
(double anX) Sets the X location.void
setY
(double aY) Sets the Y location.protected void
textDocChangedChars
(int aStart, int aEnd) Called when chars changed in TextDoc to track range in box and text to be synchronized.protected void
Updates lines for TextDoc changes.toString()
Standard toString implementation.protected void
update()
Updates text box.protected void
updateLines
(int aStartCharIndex, int textBoxEndCharIndex, int textDocEndCharIndex) Updates lines for given char start and an old/new char end.
-
Field Details
-
_fontScale
protected double _fontScale
-
-
Constructor Details
-
TextBox
public TextBox()Constructor. -
TextBox
Creates a new TextBox initialized with the given String and no attributes.
-
-
Method Details
-
getTextDoc
Returns the TextDoc. -
setTextDoc
Sets the TextDoc. -
createTextDoc
Creates the default TextDoc. -
isRichText
public boolean isRichText()Returns whether text supports multiple styles. -
setRichText
public void setRichText(boolean aValue) Sets whether text supports multiple styles. -
getX
public double getX()Returns the X location. -
setX
public void setX(double anX) Sets the X location. -
getY
public double getY()Returns the Y location. -
setY
public void setY(double aY) Sets the Y location. -
getWidth
public double getWidth()Returns the width. -
setWidth
public void setWidth(double aValue) Sets the width. -
getHeight
public double getHeight()Returns the height. -
setHeight
public void setHeight(double aValue) Sets the width. -
getBounds
Returns the current bounds. -
setBounds
Sets the rect location and size. -
setBounds
public void setBounds(double aX, double aY, double aW, double aH) Sets the rect location and size. -
getMaxX
public double getMaxX()Returns the max X. -
getMaxY
public double getMaxY()Returns the max Y. -
getAlignY
Returns the Y alignment. -
setAlignY
Sets the Y alignment. -
getAlignedY
public double getAlignedY()Returns the y for alignment. -
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 TextDoc. -
setStartCharIndex
public void setStartCharIndex(int charIndex) Sets the start char in TextDoc. -
getEndCharIndex
public int getEndCharIndex()Returns the end char in TextDoc. -
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. -
length
public int length()Returns the number of chars currently in text box. -
charAt
public char charAt(int anIndex) Returns the char value at the specified index. -
getTextDocLength
public int getTextDocLength()Returns the number of characters in the text. -
getString
Returns the string for the text. -
setString
Sets the text to the given string. -
addChars
Adds characters with attributes to this text at given index. -
removeChars
public void removeChars(int aStart, int anEnd) Removes characters in given range. -
replaceChars
Replaces chars in given range, with given String, using the given attributes. -
getLineCount
public int getLineCount()Returns the number of lines in this text. -
getLine
Returns the individual text line in this text. -
getLines
Returns the list of lines. -
getLineForCharIndex
Returns the TextLine at the given char index. -
getLineLast
Returns the last line. -
getLineLongest
Returns the longest line. -
textDocDidPropChange
Updates lines for TextDoc changes. -
textDocChangedChars
protected void textDocChangedChars(int aStart, int aEnd) Called when chars changed in TextDoc to track range in box and text to be synchronized. -
setNeedsUpdateAll
protected void setNeedsUpdateAll()Updates all lines. -
setUpdateBounds
protected void setUpdateBounds(int aStart, int aEnd) Sets the update bounds (in characters from start and from end). -
update
protected void update()Updates text box. -
updateLines
protected void updateLines(int aStartCharIndex, int textBoxEndCharIndex, int textDocEndCharIndex) Updates lines for given char start and an old/new char end. -
addLinesForCharRange
protected void addLinesForCharRange(int aLineIndex, int aStartCharIndex, int aEndCharIndex) Removes the lines from given char index to given char index. -
createTextBoxLine
Create and return TextBoxLines for given TextLine, start char index and line index. -
removeLinesForCharRange
protected void removeLinesForCharRange(int startCharIndex, int endCharIndex) Removes the lines from given char index to given char index, extended to cover entire TextDoc.TextLines. -
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. -
getTokenForCharIndex
Returns the token at given index. -
isUnderlined
public boolean isUnderlined()Returns whether text box contains an underlined run. -
getUnderlineRuns
Returns underlined runs for text box. -
getLineForY
Returns the line for the given y value. -
getCharIndexForXY
public int getCharIndexForXY(double anX, double aY) Returns the character index for the given x/y point. -
getPathForCharRange
Returns a path for two char indexes - it will be a a simple box with extensions for first/last lines. -
paint
Paint TextBox to given painter. -
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. -
toString
Standard toString implementation.
-