Package snap.text
Class TextLine
java.lang.Object
snap.text.TextLine
- All Implemented Interfaces:
CharSequence
,Cloneable
,CharSequenceX
- Direct Known Subclasses:
RichTextLine
This class represents a line of text in a Text.
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
protected TextLineStyle
protected TextRun[]
protected StringBuffer
protected int
protected TextDoc
protected TextToken[]
protected double
protected static final TextRun[]
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addChars
(CharSequence theChars, TextStyle theStyle, int anIndex) Adds characters with attributes to this line at given index.protected void
Adds a run to line.char
charAt
(int anIndex) Returns the char value at the specified index.clone()
Standard clone implementation.copyForRange
(int aStart, int aEnd) Returns a copy of this line for given char range.protected TextRun
Creates a new run.protected TextToken[]
Creates the tokens (via TextDoc.createTokensForTextLine() to provide another hook).Returns the alignment associated with this line.int
getCharIndexForX
(double anX) Returns the character index for the given x/y point.int
Returns the end char index of this line in text.int
getIndex()
Returns the index of this line in text.Returns the last token.Returns the line style.getNext()
Returns the next line, if available.Returns the previous line, if available.getRun
(int anIndex) Returns the individual run at given index.int
Returns the number of runs for this line.getRunForCharIndex
(int anIndex) Returns the head run for the line.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.TextRun[]
getRuns()
Returns the line runs.int
Returns the start char index of this line in text.Returns the string for the line.Returns the TextDoc.getTokenForCharIndex
(int charIndex) Returns the token at or before given char index.getTokenForX
(double anX) Returns the token at index.Returns the tokens.double
getWidth()
Returns the width of line.double
getWidth
(int anIndex) Returns the width of line from given index.double
getXForCharIndex
(int anIndex) Returns the X coord for given char index.protected double
getXForTabAtIndexAndX
(int charIndex, double aX) Returns the x for tab at given x.int
Returns the index of given string in line.boolean
Returns whether line contains an underlined run.int
length()
Returns the length of this text line.void
removeChars
(int aStart, int anEnd) Removes characters in given range.protected void
removeRun
(int anIndex) Removes the run at given index.void
Sets the alignment associated with this line.void
setLineStyle
(TextLineStyle aLineStyle) Sets the line style.protected void
Sets the style for the line (propagates to runs).protected TextLine
splitLineAtIndex
(int anIndex) Splits the line at given character index.subSequence
(int aStart, int anEnd) Returns a new char sequence that is a subsequence of this sequence.toString()
Standard toString implementation.Standard toStringProps implementation.protected void
updateRuns
(int aRunIndex) Updates length due to change in given run.protected void
Updates text.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
Methods inherited from interface snap.util.CharSequenceX
getIndentLength, getIndentString, getLastChar, indexAfterNewline, indexOfNewline, isAfterLineEnd, isLastCharNewline, isLineEnd, isLineEndChar, isWhiteSpace, lastIndexAfterNewline, lastIndexOfNewline, startsWith
-
Field Details
-
_textDoc
-
_sb
-
_startCharIndex
protected int _startCharIndex -
_runs
-
_lineStyle
-
_index
protected int _index -
_width
protected double _width -
_tokens
-
EMPTY_RUNS
-
-
Constructor Details
-
TextLine
Constructor.
-
-
Method Details
-
getTextDoc
Returns the TextDoc. -
length
public int length()Returns the length of this text line.- 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
-
indexOf
Returns the index of given string in line. -
getString
Returns the string for the line. -
getStartCharIndex
public int getStartCharIndex()Returns the start char index of this line in text. -
getEndCharIndex
public int getEndCharIndex()Returns the end char index of this line in text. -
getIndex
public int getIndex()Returns the index of this line in text. -
getRunCount
public int getRunCount()Returns the number of runs for this line. -
getRun
Returns the individual run at given index. -
getRuns
Returns the line runs. -
getLineStyle
Returns the line style. -
setLineStyle
Sets the line style. -
addChars
Adds characters with attributes to this line at given index. -
removeChars
public void removeChars(int aStart, int anEnd) Removes characters in given range. -
addRun
Adds a run to line. -
removeRun
protected void removeRun(int anIndex) Removes the run at given index. -
createRun
Creates a new run. -
setStyle
Sets the style for the line (propagates to runs). -
getWidth
public double getWidth()Returns the width of line. -
getWidth
public double getWidth(int anIndex) Returns the width of line from given index. -
getRunForCharIndex
Returns the head run for the line. -
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. -
splitLineAtIndex
Splits the line at given character index. -
getXForTabAtIndexAndX
protected double getXForTabAtIndexAndX(int charIndex, double aX) Returns the x for tab at given x. -
getTokens
Returns the tokens. -
createTokens
Creates the tokens (via TextDoc.createTokensForTextLine() to provide another hook). -
getLastToken
Returns the last token. -
getTokenForCharIndex
Returns the token at or before given char index. -
getXForCharIndex
public double getXForCharIndex(int anIndex) Returns the X coord for given char index. -
getTokenForX
Returns the token at index. -
getCharIndexForX
public int getCharIndexForX(double anX) Returns the character index for the given x/y point. -
getNext
Returns the next line, if available. -
getPrevious
Returns the previous line, if available. -
getAlignX
Returns the alignment associated with this line. -
setAlignX
Sets the alignment associated with this line. -
isUnderlined
public boolean isUnderlined()Returns whether line contains an underlined run. -
updateRuns
protected void updateRuns(int aRunIndex) Updates length due to change in given run. -
updateText
protected void updateText()Updates text. -
copyForRange
Returns a copy of this line for given char range. -
clone
Standard clone implementation. -
toString
Standard toString implementation.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
toStringProps
Standard toStringProps implementation.
-