RichTextModel (JavaFX 27)
Description: declaration: module: jfx.incubator.richtext, package: jfx.incubator.scene.control.richtext.model, class: RichTextModel

# Class RichTextModel

java.lang.Object
jfx.incubator.scene.control.richtext.model.StyledTextModel
jfx.incubator.scene.control.richtext.model.RichTextModel

public class RichTextModel extends StyledTextModel
Editable, in-memory `StyledTextModel` based on a collection of styled segments.

This model is suitable for relatively small documents as it has neither disk storage backing nor storage of incremental changes.

Since:
  24

- ## Nested Class Summary

  ### Nested classes/interfaces declared in class StyledTextModel

  `StyledTextModel.Listener`

- ## Property Summary

  Properties
  Type
  Property
  Description
  `final DoubleProperty`
  `defaultTabStops`
  Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph's `StyleAttributeMap.TAB_STOPS` attribute, if any.

  ### Properties declared in class StyledTextModel

  `redoable, undoable`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final double`
  `DEFAULT_TAB_STOPS_DISABLED`
  This value of the `defaultTabStopsProperty()` disables the default tab stops, making a tab characters appear as a single space.
  `static final double`
  `DEFAULT_TAB_STOPS_FIXED`
  This value of the `defaultTabStopsProperty()` results in a legacy behavior where the tab spacing corresponds to 8 spaces.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RichTextModel()`
  Constructs the empty model.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `applyParagraphStyle(int index, StyleAttributeMap attrs)`
  Applies paragraph styles in the specified paragraph.
  `protected void`
  `applyStyle(int index, int start, int end, StyleAttributeMap attrs, boolean merge)`
  Applies style to the specified text range within a single paragraph.
  `final DoubleProperty`
  `defaultTabStopsProperty()`
  Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph's `StyleAttributeMap.TAB_STOPS` attribute, if any.
  `final double`
  `getDefaultTabStops()`
  Gets the value of the `defaultTabStops` property.
  `RichParagraph`
  `getParagraph(int index)`
  Returns a `RichParagraph` at the given model index.
  `String`
  `getPlainText(int index)`
  Returns the plain text string for the specified paragraph.
  `StyleAttributeMap`
  `getStyleAttributeMap(StyleResolver resolver, TextPos pos)`
  Returns the `StyleAttributeMap` of the character at the specified position's `charIndex`.
  `protected void`
  `insertLineBreak(int index, int offset)`
  Inserts a line break at the specified position.
  `protected void`
  `insertParagraph(int index, Supplier<Region> generator)`
  Inserts a paragraph that contains a single `Region`.
  `protected int`
  `insertTextSegment(int index, int offset, String text, StyleAttributeMap attrs)`
  This method is called to insert a single styled text segment at the given position.
  `final boolean`
  `isWritable()`
  Indicates whether the model supports content modifications made via `applyStyle()`, `replace()`, `undo()`, `redo()` methods.
  `protected RichParagraph.Builder`
  `prepareParagraph(int index)`
  Prepares the paragraph by populating a builder with the paragraph content.
  `protected void`
  `removeRange(TextPos start, TextPos end)`
  Removes the specified text range.
  `final void`
  `setDefaultTabStops(double value)`
  Sets the value of the `defaultTabStops` property.
  `protected void`
  `setParagraphStyle(int index, StyleAttributeMap attrs)`
  Replaces the paragraph styles in the specified paragraph.
  `int`
  `size()`
  Returns the number of paragraphs in the model.

  ### Methods declared in class StyledTextModel

  `addListener, applyStyle, clamp, clearUndoRedo, documentProperties, export, exportParagraph, fireChangeEvent, fireStyleChangeEvent, getDataFormatHandler, getDocumentEnd, getEndOfParagraphTextPos, getLineEnding, getMarker, getParagraphLength, getSupportedAttributes, getSupportedDataFormats, handleDocumentProperties, isRedoable, isUndoable, isUndoRedoEnabled, read, redo, redoableProperty, registerDataFormatHandler, removeDataFormatHandler, removeListener, replace, replace, setLineEnding, setUndoRedoEnabled, undo, undoableProperty, versionString, write`

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Property Details

  - ### defaultTabStops

    public final DoubleProperty defaultTabStopsProperty
    Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph's `StyleAttributeMap.TAB_STOPS` attribute, if any. This is a fixed repeating distance (in pixels) to the next tab stop computed at regular intervals relative to the document content leading edge.

    Value `DEFAULT_TAB_STOPS_FIXED` results in a legacy behavior where the tab spacing corresponds to 8 spaces. This may result in milasigned columns when different text segments use different fonts. The value `DEFAULT_TAB_STOPS_DISABLED` disables the default interval, rendering tab character as a single space.

    Default value:
      DEFAULT_TAB_STOPS_FIXED
    Since:
      27
    See Also:
      - `getDefaultTabStops()`
      - `setDefaultTabStops(double)`
      - `defaultTabStopsProperty()`

- ## Field Details

  - ### DEFAULT_TAB_STOPS_FIXED

    public static final double DEFAULT_TAB_STOPS_FIXED
    This value of the `defaultTabStopsProperty()` results in a legacy behavior where the tab spacing corresponds to 8 spaces. This may result in milasigned columns when different text segments use different fonts.
    Since:
      27
    See Also:
      - Constant Field Values

  - ### DEFAULT_TAB_STOPS_DISABLED

    public static final double DEFAULT_TAB_STOPS_DISABLED
    This value of the `defaultTabStopsProperty()` disables the default tab stops, making a tab characters appear as a single space.
    Since:
      27
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### RichTextModel

    public RichTextModel()
    Constructs the empty model.

- ## Method Details

  - ### defaultTabStopsProperty

    public final DoubleProperty defaultTabStopsProperty()
    Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph's `StyleAttributeMap.TAB_STOPS` attribute, if any. This is a fixed repeating distance (in pixels) to the next tab stop computed at regular intervals relative to the document content leading edge.

    Value `DEFAULT_TAB_STOPS_FIXED` results in a legacy behavior where the tab spacing corresponds to 8 spaces. This may result in milasigned columns when different text segments use different fonts. The value `DEFAULT_TAB_STOPS_DISABLED` disables the default interval, rendering tab character as a single space.

    Default value:
      DEFAULT_TAB_STOPS_FIXED
    Returns:
      the default tab stop interval property
    Since:
      27
    See Also:
      - `getDefaultTabStops()`
      - `setDefaultTabStops(double)`

  - ### setDefaultTabStops

    public final void setDefaultTabStops(double value)
    Sets the value of the `defaultTabStops` property.
    Property description:
      Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph's `StyleAttributeMap.TAB_STOPS` attribute, if any. This is a fixed repeating distance (in pixels) to the next tab stop computed at regular intervals relative to the document content leading edge.

      Value `DEFAULT_TAB_STOPS_FIXED` results in a legacy behavior where the tab spacing corresponds to 8 spaces. This may result in milasigned columns when different text segments use different fonts. The value `DEFAULT_TAB_STOPS_DISABLED` disables the default interval, rendering tab character as a single space.

    Default value:
      DEFAULT_TAB_STOPS_FIXED
    Parameters:
      `value` - the value for the `defaultTabStops` property
    Since:
      27
    See Also:
      - `getDefaultTabStops()`
      - `defaultTabStopsProperty()`

  - ### getDefaultTabStops

    public final double getDefaultTabStops()
    Gets the value of the `defaultTabStops` property.
    Property description:
      Specifies the default tab stop interval for tabs beyond the last stop provided by the paragraph's `StyleAttributeMap.TAB_STOPS` attribute, if any. This is a fixed repeating distance (in pixels) to the next tab stop computed at regular intervals relative to the document content leading edge.

      Value `DEFAULT_TAB_STOPS_FIXED` results in a legacy behavior where the tab spacing corresponds to 8 spaces. This may result in milasigned columns when different text segments use different fonts. The value `DEFAULT_TAB_STOPS_DISABLED` disables the default interval, rendering tab character as a single space.

    Default value:
      DEFAULT_TAB_STOPS_FIXED
    Returns:
      the value of the `defaultTabStops` property
    Since:
      27
    See Also:
      - `setDefaultTabStops(double)`
      - `defaultTabStopsProperty()`

  - ### isWritable

    public final boolean isWritable()
    Description copied from class: `StyledTextModel`
    Indicates whether the model supports content modifications made via `applyStyle()`, `replace()`, `undo()`, `redo()` methods.

    Note that even when this method returns `false`, the model itself may still update its content and fire the change events as a response, for example, to changes in its backing data storage.

    Specified by:
      `isWritable` in class `StyledTextModel`
    Returns:
      true if the model supports content modifications

  - ### size

    public int size()
    Description copied from class: `StyledTextModel`
    Returns the number of paragraphs in the model.
    Specified by:
      `size` in class `StyledTextModel`
    Returns:
      number of paragraphs

  - ### getPlainText

    public String getPlainText(int index)
    Description copied from class: `StyledTextModel`
    Returns the plain text string for the specified paragraph. The returned text string cannot be null and must not contain any control characters other than TAB. The callers must ensure that the value of `index` is within the valid document range, since doing otherwise might result in an exception or undetermined behavior.
    Specified by:
      `getPlainText` in class `StyledTextModel`
    Parameters:
      `index` - the paragraph index in the range (0...`StyledTextModel.size()`)
    Returns:
      the non-null paragraph text string

  - ### getParagraph

    public RichParagraph getParagraph(int index)
    Description copied from class: `StyledTextModel`
    Returns a `RichParagraph` at the given model index. The callers must ensure that the value of `index` is within the valid document range, since doing otherwise might result in an exception or undetermined behavior.

    This method makes no guarantees that the same paragraph instance will be returned for the same model index.

    Specified by:
      `getParagraph` in class `StyledTextModel`
    Parameters:
      `index` - the paragraph index in the range (0...`StyledTextModel.size()`)
    Returns:
      the instance of `RichParagraph`

  - ### prepareParagraph

    protected RichParagraph.Builder prepareParagraph(int index)
    Prepares the paragraph by populating a builder with the paragraph content. This method allows the custom model to add highlights and decorations without affecting the base class storage model.
    Parameters:
      `index` - the paragraph index
    Returns:
      the builder
    Since:
      26

  - ### insertTextSegment

    protected int insertTextSegment(int index, int offset, String text, StyleAttributeMap attrs)
    Description copied from class: `StyledTextModel`
    This method is called to insert a single styled text segment at the given position.
    Specified by:
      `insertTextSegment` in class `StyledTextModel`
    Parameters:
      `index` - the paragraph index
      `offset` - the insertion offset within the paragraph
      `text` - the text to insert
      `attrs` - the style attributes
    Returns:
      the number of characters inserted

  - ### insertLineBreak

    protected void insertLineBreak(int index, int offset)
    Description copied from class: `StyledTextModel`
    Inserts a line break at the specified position.
    Specified by:
      `insertLineBreak` in class `StyledTextModel`
    Parameters:
      `index` - the model index
      `offset` - the text offset

  - ### removeRange

    protected void removeRange(TextPos start, TextPos end)
    Description copied from class: `StyledTextModel`
    Removes the specified text range. This method gets called only if the model is editable. The caller guarantees that `start` precedes `end`.
    Specified by:
      `removeRange` in class `StyledTextModel`
    Parameters:
      `start` - the start of the range to be removed
      `end` - the end of the range to be removed, expected to be greater than the start position

  - ### insertParagraph

    protected void insertParagraph(int index, Supplier<Region> generator)
    Description copied from class: `StyledTextModel`
    Inserts a paragraph that contains a single `Region`.

    The model should not cache or otherwise retain references to the created `Region`s, as they might be requested multiple times during the lifetime of the model, or by different views.

    This method allows for embedding `Control`s that handle user input. In this case, the model should declare necessary properties and provide bidirectional bindings between the properties in the model and the corresponding properties in the control, as well as handle copy, paste, writing to and reading from I/O streams.

    Specified by:
      `insertParagraph` in class `StyledTextModel`
    Parameters:
      `index` - model index
      `generator` - code that will be used to create a Node instance

  - ### applyParagraphStyle

    protected void applyParagraphStyle(int index, StyleAttributeMap attrs)
    Description copied from class: `StyledTextModel`
    Applies paragraph styles in the specified paragraph.
    Specified by:
      `applyParagraphStyle` in class `StyledTextModel`
    Parameters:
      `index` - the paragraph index
      `attrs` - the paragraph attributes

  - ### setParagraphStyle

    protected void setParagraphStyle(int index, StyleAttributeMap attrs)
    Description copied from class: `StyledTextModel`
    Replaces the paragraph styles in the specified paragraph.
    Specified by:
      `setParagraphStyle` in class `StyledTextModel`
    Parameters:
      `index` - the paragraph index
      `attrs` - the paragraph attributes

  - ### applyStyle

    protected void applyStyle(int index, int start, int end, StyleAttributeMap attrs, boolean merge)
    Description copied from class: `StyledTextModel`
    Applies style to the specified text range within a single paragraph. The `end` argument may exceed the paragraph length, in which case the outcome should be the same as supplying the paragraph length value.
    Specified by:
      `applyStyle` in class `StyledTextModel`
    Parameters:
      `index` - the paragraph index
      `start` - the start offset
      `end` - the end offset
      `attrs` - the character attributes
      `merge` - determines whether to merge with or completely replace the existing attribute map

  - ### getStyleAttributeMap

    public StyleAttributeMap getStyleAttributeMap(StyleResolver resolver, TextPos pos)
    Description copied from class: `StyledTextModel`
    Returns the `StyleAttributeMap` of the character at the specified position's `charIndex`. When at the end of the document, returns the attributes of the last character.
    Specified by:
      `getStyleAttributeMap` in class `StyledTextModel`
    Parameters:
      `resolver` - the style resolver
      `pos` - the text position
    Returns:
      the style attributes, non-null