Package snap.text
Class TextBlock
java.lang.Object
snap.props.PropObject
snap.text.TextBlock
- All Implemented Interfaces:
CharSequence
,Cloneable
,PropChange.DoChange
,CharSequenceX
,XMLArchiver.Archivable
public class TextBlock
extends PropObject
implements CharSequenceX, Cloneable, XMLArchiver.Archivable
This class is the basic text storage class, holding a list of TextLine.
-
Field Summary
Modifier and TypeFieldDescriptionprotected TextLineStyle
protected TextStyle
protected int
protected double
protected double
protected 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Called to activate undo.void
addChars
(CharSequence theChars) Adds characters to this text.void
addChars
(CharSequence theChars, int anIndex) Adds characters to this text at given index.protected void
addCharsToLine
(CharSequence theChars, TextStyle theStyle, int charIndex, TextLine textLine, boolean charsHaveNewline) Adds a block of chars to line - each block is guaranteed to either have no newlines or end with newline.void
addCharsWithStyle
(CharSequence theChars, TextStyle theStyle) Adds characters with given style to this text.void
addCharsWithStyle
(CharSequence theChars, TextStyle theStyle, int anIndex) Adds characters with given style to this text at given index.protected void
Adds a block at given index.void
addTextBlock
(TextBlock textBlock, int anIndex) Adds given TextBlock to this text at given index.char
charAt
(int anIndex) Returns the char value at the specified index.void
clear()
Clears the text.clone()
Standard clone implementation.copyForRange
(int aStart, int aEnd) Returns a copy of this text for given char range.protected TextLine
Creates a new TextLine for use in this text.protected TextToken[]
createTokensForTextLine
(TextLine aTextLine) Creates TextTokens for a TextLine.protected void
firePropChange
(PropChange aPC) Override to register undo.fromXML
(XMLArchiver anArchiver, XMLElement anElement) XMLArchiver.Archivable unarchival.double
Returns the y for alignment.Returns the horizontal alignment of the first paragraph of the text.Returns the current bounds.int
getCharIndexForXY
(double anX, double aY) Returns the character index for the given x/y point.Returns the default font.Returns the default line style for text.Returns the default text color.Returns the default text style for text.int
Returns the end char in source TextBlock.getFontForCharIndex
(int charIndex) Returns the Font for run at given character index.double
Returns the height.Returns the last text line (or null if none).getLine
(int anIndex) Returns the individual block in this doc.int
Returns the number of block in this doc.getLineForCharIndex
(int charIndex) Returns the block at the given char index.getLineForY
(double aY) Returns the line for the given y value.Returns the longest line.getLines()
Returns the list of blocks.getLineStyleForCharIndex
(int charIndex) Returns the TextLineStyle for the run at the given character index.double
getMaxX()
Returns the max X.double
getMaxY()
Returns the max Y.getPathForCharRange
(int aStartCharIndex, int aEndCharIndex) Returns a path for two char indexes - it will be a simple box with extensions for first/last lines.double
Returns the preferred height.double
Returns the width of text.double
getPrefWidthForStartCharIndex
(int startCharIndex) Returns the width of text from given start char index.getRunForCharIndex
(int charIndex) Returns the TextRun that contains the given char index.getRunForCharRange
(int startIndex, int endIndex) Returns the TextRun for the given char range (usually just run for start, but can be next run if at boundary).getRunIterForCharRange
(int startCharIndex, int endCharIndex) Returns a TextRunIter to easily traverse the runs for a given range of chars.Returns the root text block.int
Returns the start char index (always 0, unless this is SubText).Returns the string for the text.getTextStyleForCharIndex
(int charIndex) Returns the TextStyle for the run at the given character index.getTextStyleForCharRange
(int startIndex, int endIndex) Returns the TextStyle for the run for given char range.getTokenForCharIndex
(int charIndex) Returns the token at given char index.TextRun[]
getUnderlineRuns
(Rect aRect) Returns underlined runs for text box.Returns the text undoer.double
getWidth()
Returns the width.double
getX()
Returns the X location.double
getY()
Returns the Y location.int
Returns the index of given string.boolean
Returns whether property change is enabled.boolean
Whether this text supports multiple styles (font, color, etc.).boolean
Returns whether text is modified.boolean
Returns whether text contains an underlined run.protected void
joinLineWithNextLine
(TextLine textLine) Joins given line with next line.int
length()
Returns the number of characters in the text.protected void
moveLineCharsToNextLine
(TextLine textLine, int startCharIndex) Move line chars from given start char index to line end to next line.void
Paint TextBox to given painter.void
Paint TextBox to given painter.redo()
Called to redo the last text change.void
removeChars
(int aStartCharIndex, int anEndCharIndex) Removes characters in given range.protected void
removeCharsFromLine
(int startCharIndex, int endCharIndex, TextLine textLine) Remove chars from line.protected void
removeLine
(int anIndex) Removes the block at given index.void
replaceChars
(CharSequence theChars, int aStart, int anEnd) Replaces chars in given range, with given String, using the given attributes.void
replaceChars
(CharSequence theChars, TextStyle theStyle, int aStart, int anEnd) Replaces chars in given range, with given String, using the given attributes.protected void
resetLineYForLinesAfterIndex
(int lineIndex) Resets Line Y positions for lines after given line index.void
scaleFonts
(double aScale) Scales all the fonts in text by given factor.void
Sets the horizontal alignment of the text.void
setBounds
(double aX, double aY, double aW, double aH) Sets the rect location and size.void
Sets the rect location and size.void
setDefaultFont
(Font aFont) Sets the default font.void
setDefaultLineStyle
(TextLineStyle aLineStyle) Sets the default line style.void
setDefaultTextColor
(Color aColor) Sets the default text color.void
setDefaultTextStyle
(TextStyle aStyle) Sets the default text style.void
setHeight
(double aValue) Sets the width.void
setLineStyle
(TextLineStyle aStyle, int aStart, int anEnd) Sets a given style to a given range.void
setLineStyleValue
(String aKey, Object aValue, int aStart, int anEnd) Sets a given style to a given range.void
setPropChangeEnabled
(boolean aValue) Sets whether property change is enabled.void
setRichText
(boolean aValue) Sets whether text supports multiple styles.void
Sets the text to the given string.void
setStyleValue
(Object aValue) Sets a given style value to given value for a given range.void
setStyleValue
(Object aValue, int aStart, int aEnd) Sets a given style value to given value for a given range.void
setStyleValue
(String aKey, Object aValue, int aStart, int anEnd) Sets a given attribute to a given value for a given range.void
setTextModified
(boolean aValue) Sets whether text is modified.void
setTextStyle
(TextStyle textStyle, int aStart, int anEnd) Sets the given text style for given range.void
setUnderlined
(boolean aFlag) Sets text to be underlined.void
setWidth
(double aValue) Sets the width.void
setX
(double anX) Sets the X location.void
setY
(double aY) Sets the Y location.protected TextLine
splitLineAtIndex
(TextLine textLine, int anIndex) Splits given line at given character index and adds remainder to text and returns it.subSequence
(int aStart, int anEnd) Returns a new char sequence that is a subsequence of this sequence.Standard toStringProps implementation.toXML
(XMLArchiver anArchiver) XMLArchiver.Archivable archival.undo()
Called to undo the last text change.protected void
undoerAddPropChange
(PropChange anEvent) Adds a property change to undoer.protected void
updateLine
(TextLine textLine, int newIndex, int newStartCharIndex) Updates an individual line for new index and start char index.protected void
updateLines
(int anIndex) Updates Lines (Index, Start) from index line to text end.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
-
_lines
-
_length
protected int _length -
_defaultTextStyle
-
_defaultLineStyle
-
_prefW
protected double _prefW -
_propChangeEnabled
protected boolean _propChangeEnabled -
_mouseY
protected double _mouseY -
Chars_Prop
- See Also:
-
Style_Prop
- See Also:
-
LineStyle_Prop
- See Also:
-
DefaultTextStyle_Prop
- See Also:
-
TextModified_Prop
- See Also:
-
-
Constructor Details
-
TextBlock
public TextBlock()Constructor. -
TextBlock
public TextBlock(boolean isRich) Constructor with option to make rich text.
-
-
Method Details
-
createLine
Creates a new TextLine for use in this text. -
isRichText
public boolean isRichText()Whether this text supports multiple styles (font, color, etc.). -
setRichText
public void setRichText(boolean aValue) Sets whether text supports multiple styles. -
getSourceText
Returns the root text block. -
length
public int length()Returns the number of characters in the text.- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int anIndex) Returns the char value at the specified index.- Specified by:
charAt
in interfaceCharSequence
-
subSequence
Returns a new char sequence that is a subsequence of this sequence.- Specified by:
subSequence
in interfaceCharSequence
-
getString
Returns the string for the text. -
setString
Sets the text to the given string. -
getDefaultTextStyle
Returns the default text style for text. -
setDefaultTextStyle
Sets the default text style. -
getDefaultLineStyle
Returns the default line style for text. -
setDefaultLineStyle
Sets the default line style. -
getDefaultFont
Returns the default font. -
setDefaultFont
Sets the default font. -
getDefaultTextColor
Returns the default text color. -
setDefaultTextColor
Sets the default text color. -
isTextModified
public boolean isTextModified()Returns whether text is modified. -
setTextModified
public void setTextModified(boolean aValue) Sets whether text is modified. -
addChars
Adds characters to this text. -
addChars
Adds characters to this text at given index. -
addCharsWithStyle
Adds characters with given style to this text. -
addCharsWithStyle
Adds characters with given style to this text at given index. -
addCharsToLine
protected void addCharsToLine(CharSequence theChars, TextStyle theStyle, int charIndex, TextLine textLine, boolean charsHaveNewline) Adds a block of chars to line - each block is guaranteed to either have no newlines or end with newline. -
moveLineCharsToNextLine
Move line chars from given start char index to line end to next line. -
removeChars
public void removeChars(int aStartCharIndex, int anEndCharIndex) Removes characters in given range. -
removeCharsFromLine
Remove chars from line. -
replaceChars
Replaces chars in given range, with given String, using the given attributes. -
replaceChars
Replaces chars in given range, with given String, using the given attributes. -
splitLineAtIndex
Splits given line at given character index and adds remainder to text and returns it. -
joinLineWithNextLine
Joins given line with next line. -
addTextBlock
Adds given TextBlock to this text at given index. -
setTextStyle
Sets the given text style for given range. -
setStyleValue
Sets a given style value to given value for a given range. -
setStyleValue
Sets a given style value to given value for a given range. -
setStyleValue
Sets a given attribute to a given value for a given range. -
setLineStyle
Sets a given style to a given range. -
setLineStyleValue
Sets a given style to a given range. -
getLineCount
public int getLineCount()Returns the number of block in this doc. -
getLine
Returns the individual block in this doc. -
getLines
Returns the list of blocks. -
addLine
Adds a block at given index. -
removeLine
protected void removeLine(int anIndex) Removes the block at given index. -
getLineLongest
Returns the longest line. -
clear
public void clear()Clears the text. -
getLineForCharIndex
Returns the block at the given char index. -
getLastLine
Returns the last text line (or null if none). -
getRunForCharIndex
Returns the TextRun that contains the given char index. -
getRunForCharRange
Returns the TextRun for the given char range (usually just run for start, but can be next run if at boundary). -
getRunIterForCharRange
Returns a TextRunIter to easily traverse the runs for a given range of chars. -
getTokenForCharIndex
Returns the token at given char index. -
getFontForCharIndex
Returns the Font for run at given character index. -
getTextStyleForCharIndex
Returns the TextStyle for the run at the given character index. -
getTextStyleForCharRange
Returns the TextStyle for the run for given char range. -
getLineStyleForCharIndex
Returns the TextLineStyle for the run at the given character index. -
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. -
isUnderlined
public boolean isUnderlined()Returns whether text contains an underlined run. -
setUnderlined
public void setUnderlined(boolean aFlag) Sets text to be underlined. -
getAlignX
Returns the horizontal alignment of the first paragraph of the text. -
setAlignX
Sets the horizontal alignment of the text. -
getStartCharIndex
public int getStartCharIndex()Returns the start char index (always 0, unless this is SubText). -
getEndCharIndex
public int getEndCharIndex()Returns the end char in source TextBlock. -
scaleFonts
public void scaleFonts(double aScale) Scales all the fonts in text by given factor. -
indexOf
Returns the index of given string. -
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. -
getAlignedY
public double getAlignedY()Returns the y for alignment. -
getPathForCharRange
Returns a path for two char indexes - it will be a simple box with extensions for first/last lines. -
isPropChangeEnabled
public boolean isPropChangeEnabled()Returns whether property change is enabled. -
setPropChangeEnabled
public void setPropChangeEnabled(boolean aValue) Sets whether property change is enabled. -
paint
Paint TextBox to given painter. -
paintLine
Paint TextBox to given painter. -
getPrefWidth
public double getPrefWidth()Returns the width of text. -
getPrefWidthForStartCharIndex
public double getPrefWidthForStartCharIndex(int startCharIndex) Returns the width of text from given start char index. -
getPrefHeight
public double getPrefHeight()Returns the preferred height. -
createTokensForTextLine
Creates TextTokens for a TextLine. -
resetLineYForLinesAfterIndex
protected void resetLineYForLinesAfterIndex(int lineIndex) Resets Line Y positions for lines after given line index. -
updateLines
protected void updateLines(int anIndex) Updates Lines (Index, Start) from index line to text end. -
updateLine
Updates an individual line for new index and start char index. -
getUnderlineRuns
Returns underlined runs for text box. -
activateUndo
public void activateUndo()Called to activate undo. -
getUndoer
Returns the text undoer. -
undo
Called to undo the last text change. -
redo
Called to redo the last text change. -
undoerAddPropChange
Adds a property change to undoer. -
firePropChange
Override to register undo.- Overrides:
firePropChange
in classPropObject
-
copyForRange
Returns a copy of this text for given char range. -
clone
Standard clone implementation.- Overrides:
clone
in classPropObject
-
toStringProps
Standard toStringProps implementation.- Overrides:
toStringProps
in classPropObject
-
toXML
XMLArchiver.Archivable archival.- Specified by:
toXML
in interfaceXMLArchiver.Archivable
-
fromXML
XMLArchiver.Archivable unarchival.- Specified by:
fromXML
in interfaceXMLArchiver.Archivable
-