Class RichText
Immutable styled text: a sequence of runs, each a string with one TextStyle, and inline
objects -- fields, note references, pictures and embedded components -- each of which takes
exactly one character, OBJECT.
Adjacent text runs with equal styles are merged and empty runs are dropped, so two texts that
read the same and look the same are equals. An object run is never merged.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAccumulates runs into aRichText.static interfaceComputes a new style from an old one, forrestyle.static classReceives the runs of a text in order. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionThis text followed by another.delete(int start, int end) This text without the characters in[start, end).The text as a reader sees it: a field shows its result, a note reference its mark, and other objects nothing.booleanTwo texts are equal when they have the same runs and objects.inthashCode()A hash consistent withequals.booleanWhether the text holds any inline object.This text withinsertplaced at an offset.booleanisEmpty()Whether the text has no characters.intlength()The number of characters.objectAt(int offset) The inline object at a character offset.static RichTextA text holding one inline object.static RichTextPlain text in the default style.static RichTextText in a single style.The characters without formatting.restyle(int start, int end, RichText.StyleMapper mapper) Restyles the characters in[start, end).intrunCount()The number of runs, inline objects included.runObject(int index) The inline object of one run.runStyle(int index) The style of one run.runText(int index) The characters of one run;OBJECTfor an inline object.styleAt(int offset) The style at a character offset.styles()The distinct styles used, in order of first use.substring(int start, int end) The characters in[start, end)with their styles and objects.toString()The plain text, for debugging.voidvisit(RichText.Visitor visitor) Calls the visitor once per run, in order.withObject(int offset, Inline object) This text with the object atoffsetreplaced.
-
Field Details
-
OBJECT
public static final char OBJECTThe character an inline object occupies, U+FFFC OBJECT REPLACEMENT CHARACTER.- See Also:
-
EMPTY
The empty text.
-
-
Method Details
-
of
-
of
-
of
-
length
public int length()The number of characters.
Returns
the length
-
isEmpty
public boolean isEmpty()Whether the text has no characters.
Returns
true when empty
-
runCount
public int runCount()The number of runs, inline objects included.
Returns
the run count
-
runText
The characters of one run;
OBJECTfor an inline object.Parameters
index: the run, from zero
Returns
the run's text
-
runStyle
The style of one run.
Parameters
index: the run, from zero
Returns
the run's style
-
runObject
The inline object of one run.
Parameters
index: the run, from zero
Returns
the object, or null for a text run
-
objectAt
The inline object at a character offset.
Parameters
offset: the character offset
Returns
the object, or null when the character is not an object
-
hasObjects
public boolean hasObjects()Whether the text holds any inline object.
Returns
true when it does
-
plainText
The characters without formatting. Every inline object is one
OBJECTcharacter.Returns
the plain text
-
displayText
The text as a reader sees it: a field shows its result, a note reference its mark, and other objects nothing.
Returns
the readable text
-
styleAt
The style at a character offset. At the end of the text, and for an empty text, this is the style of the last run, so text typed there continues it.
Parameters
offset: the character offset
Returns
the style in effect
-
visit
Calls the visitor once per run, in order.
Parameters
visitor: the receiver
-
substring
The characters in
[start, end)with their styles and objects.Parameters
-
start: the first offset, inclusive -
end: the last offset, exclusive
Returns
the slice
-
-
insert
-
delete
This text without the characters in
[start, end).Parameters
-
start: the first offset, inclusive -
end: the last offset, exclusive
Returns
the new text
-
-
append
-
restyle
Restyles the characters in
[start, end).Parameters
-
start: the first offset, inclusive -
end: the last offset, exclusive -
mapper: computes each run's new style from its old one
Returns
the new text
-
-
withObject
-
styles
-
equals
-
hashCode
-
toString
-