Package org.fxmisc.richtext.model

Defines the support classes and operations related to EditableStyledDocument, the immutable model of rich-text content that can be rendered and edited.

An EditableStyledDocument acts as an immutable model for rich-text content that will be rendered by an object implementing the TextEditingArea interface. A StyledDocument is composed of a list of Paragraphs. Paragraphs are nothing more than an object containing a paragraph style (type PS), a list of a generic segments (type SEG), and a list of generic styles (type S) that can apply to a segment. Most of the time, either EditableStyledDocument or ReadOnlyStyledDocument are being used to implement that interface.

The document can include more than just text; thus, the segment generic can be specified as regular text (String) or as an Either (e.g. Either<String, Image> or as a nested Either (e.g. Either<String, Either<Image, Either<Circle, Square>) if one wanted to have four different kinds of segments (ways to specify a segment generic in a way that still makes the code easy to read are not described here).

To allow these generics, one must supply a SegmentOps object that can correctly operate on the generic segments and their generic styles. In addition, a TextOps adds one more method to its base interface by adding a method that maps a String to a given segment. For text-based custom segments, one should use SegmentOpsBase and for node-based custom segments, one should use NodeSegmentOpsBase.

The document also uses StyleSpans to store styles in a memory-efficient way. To construct one, use StyleSpans.singleton(org.fxmisc.richtext.model.StyleSpan) or StyleSpansBuilder.

To navigate throughout the document, read through the javadoc of TwoDimensional and TwoDimensional.Bias. Also, read the difference between "position" and "index" in StyledDocument.getAbsolutePosition(int, int).

To serialize things correctly, see Codec and its static factory methods.

Lastly, the EditableStyledDocument can emit PlainTextChanges or RichTextChanges that can be used to undo/redo various changes.

See Also:
EditableStyledDocument, Paragraph, SegmentOps, TwoDimensional, TwoDimensional.Bias
Skip navigation links