Package snap.text
Class TextDoc
java.lang.Object
snap.props.PropObject
snap.text.TextDoc
- All Implemented Interfaces:
CharSequence
,Cloneable
,PropChange.DoChange
,CharSequenceX
This class is the basic text storage class, holding a list of TextLine.
-
Field Summary
Modifier and TypeFieldDescriptionprotected TextLineStyle
protected TextStyle
protected int
protected TextStyle
protected boolean
protected double
static final String
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
addChars
(CharSequence theChars) Adds characters with attributes to this text at given index.void
addChars
(CharSequence theChars, TextStyle theStyle, int anIndex) Adds characters with attributes to this text at given index.protected void
Adds a default line.protected void
Adds a block at given index.void
addTextDoc
(TextDoc aTextDoc, int anIndex) Adds given TextDoc 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.protected TextLine
Creates a new TextLine for use in this text.protected TextToken[]
createTokensForTextLine
(TextLine aTextLine) Creates TextTokens for a TextLine.Returns the horizontal alignment of the first paragraph of the text.Returns the default line style for text.Returns the default text style for text.getFontForCharIndex
(int charIndex) Returns the Font for run at given character index.getLine
(int anIndex) Returns the individual block in this doc.int
Returns the number of block in this doc.getLineForCharIndex
(int anIndex) Returns the block at the given char index.Returns the last block.Returns the longest line.getLines()
Returns the list of blocks.getLineStyleForCharIndex
(int charIndex) Returns the TextLineStyle for the run at the given character index.Returns the current style for TextDoc parent/container (probably a TextArea).double
Returns the width of text.double
getPrefWidth
(int anIndex) Returns the width of text from given 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).Returns the last run.Returns the source file.Returns the source URL.int
Returns the start char index (always 0, unless this is SubText).Returns the string for the text.getStyleForCharIndex
(int charIndex) Returns the TextStyle for the run at the given character index.getStyleForCharRange
(int startIndex, int endIndex) Returns the TextStyle for the run for given char range.int
Returns the index of given string.boolean
Returns whether the default text style is explicitly set (vs.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.int
length()
Returns the number of characters in the text.static TextDoc
newFromSource
(Object aSource) Returns a new TextDoc from given source.void
readFromSourceURL
(WebURL aURL) Load TextDoc from source URL.void
removeChars
(int aStart, int anEnd) Removes characters in given range.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.void
scaleFonts
(double aScale) Scales all the fonts in text by given factor.void
Sets the horizontal alignment of the text.void
setDefaultLineStyle
(TextLineStyle aLineStyle) Sets the default line style.void
setDefaultStyle
(TextStyle aStyle) Sets the default text style.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
setParentTextStyle
(TextStyle aStyle) Sets the current style for TextDoc parent/container (probably a TextArea).void
setPropChangeEnabled
(boolean aValue) Sets whether property change is enabled.void
setSourceURL
(WebURL aURL) Sets the Source URL.void
Sets the text to the given string.void
Sets a given style to a given range.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) Sets a given attribute to a 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
setUnderlined
(boolean aFlag) Sets text to be underlined.subSequence
(int aStart, int anEnd) Returns a new char sequence that is a subsequence of this sequence.Standard toStringProps implementation.protected void
updateLines
(int anIndex) Updates Lines (Index, Start) from index line to text end.void
Write TextDoc text to source file.Methods inherited from class snap.props.PropObject
addDeepChangeListener, addPropChangeListener, addPropChangeListener, firePropChange, firePropChange, firePropChange, getPropDefault, getPropForName, getPropParent, getPropSet, getPropsForArchival, getPropsForArchivalExtra, getPropValue, initProps, isPropDefault, processPropChange, removeDeepChangeListener, removePropChangeListener, removePropChangeListener, setPropValue, 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, indexOfNewline, isAfterLineEnd, isLastCharNewline, isLineEnd, isLineEndChar, isWhiteSpace, lastIndexAfterNewline, lastIndexOfNewline, startsWith
-
Field Details
-
_lines
-
_length
protected int _length -
_defaultTextStyle
-
_defaultLineStyle
-
_parentTextStyle
-
_propChangeEnabled
protected boolean _propChangeEnabled -
_width
protected double _width -
Chars_Prop
- See Also:
-
Style_Prop
- See Also:
-
LineStyle_Prop
- See Also:
-
DefaultTextStyle_Prop
- See Also:
-
ParentTextStyle_Prop
- See Also:
-
TextModified_Prop
- See Also:
-
-
Constructor Details
-
TextDoc
public TextDoc()Constructor.
-
-
Method Details
-
addDefaultLine
protected void addDefaultLine()Adds a default line. -
isRichText
public boolean isRichText()Whether this text supports multiple styles (font, color, etc.). -
getSourceURL
Returns the source URL. -
setSourceURL
Sets the Source URL. -
getSourceFile
Returns the source file. -
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. -
isDefaultTextStyleSet
public boolean isDefaultTextStyleSet()Returns whether the default text style is explicitly set (vs. coming from parent). -
getDefaultStyle
Returns the default text style for text. -
setDefaultStyle
Sets the default text style. -
getDefaultLineStyle
Returns the default line style for text. -
setDefaultLineStyle
Sets the default line style. -
getParentTextStyle
Returns the current style for TextDoc parent/container (probably a TextArea). -
setParentTextStyle
Sets the current style for TextDoc parent/container (probably a TextArea). -
isTextModified
public boolean isTextModified()Returns whether text is modified. -
setTextModified
public void setTextModified(boolean aValue) Sets whether text is modified. -
addChars
Adds characters with attributes to this text at given index. -
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. -
replaceChars
Replaces chars in given range, with given String, using the given attributes. -
addTextDoc
Adds given TextDoc to this text at given index. -
setStyle
Sets a given style to a 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. -
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. -
createLine
Creates a new TextLine for use in this text. -
getLineLongest
Returns the longest line. -
clear
public void clear()Clears the text. -
getPrefWidth
public double getPrefWidth()Returns the width of text. -
getPrefWidth
public double getPrefWidth(int anIndex) Returns the width of text from given index. -
getLineForCharIndex
Returns the block at the given char index. -
getLineLast
Returns the last block. -
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). -
getRunLast
Returns the last run. -
getFontForCharIndex
Returns the Font for run at given character index. -
getStyleForCharIndex
Returns the TextStyle for the run at the given character index. -
getStyleForCharRange
Returns the TextStyle for the run for given char range. -
getLineStyleForCharIndex
Returns the TextLineStyle for the run at the given character index. -
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). -
scaleFonts
public void scaleFonts(double aScale) Scales all the fonts in text by given factor. -
indexOf
Returns the index of given string. -
isPropChangeEnabled
public boolean isPropChangeEnabled()Returns whether property change is enabled. -
setPropChangeEnabled
public void setPropChangeEnabled(boolean aValue) Sets whether property change is enabled. -
createTokensForTextLine
Creates TextTokens for a TextLine. -
updateLines
protected void updateLines(int anIndex) Updates Lines (Index, Start) from index line to text end. -
readFromSourceURL
Load TextDoc from source URL. -
writeToSourceFile
Write TextDoc text to source file.- Throws:
Exception
-
clone
Standard clone implementation.- Overrides:
clone
in classPropObject
-
toStringProps
Standard toStringProps implementation.- Overrides:
toStringProps
in classPropObject
-
newFromSource
Returns a new TextDoc from given source.
-