RichParagraph.Builder (JavaFX 28)
Description: declaration: module: jfx.incubator.richtext, package: jfx.incubator.scene.control.richtext.model, class: RichParagraph, class: Builder

# Class RichParagraph.Builder

java.lang.Object
jfx.incubator.scene.control.richtext.model.RichParagraph.Builder

Enclosing class:
  `RichParagraph`

public static class RichParagraph.Builder extends Object
Utility class for building immutable `RichParagraph`s.

Since:
  24

- ## Method Summary

  Modifier and Type
  Method
  Description
  `RichParagraph.Builder`
  `addHighlight(int start, int length, String... css)`
  Adds a highlight with the specified style name(s).
  `RichParagraph.Builder`
  `addHighlight(int start, int length, Color color)`
  Adds a color background highlight.
  `RichParagraph.Builder`
  `addInlineNode(Supplier<Node> generator)`
  Adds an inline node.
  `RichParagraph.Builder`
  `addInlineNode(Supplier<Node> generator, StyleAttributeMap a)`
  Adds an inline node.
  `RichParagraph.Builder`
  `addSegment(String text)`
  Adds a text segment with no styling (i.e.
  `RichParagraph.Builder`
  `addSegment(String text, int start, int end, StyleAttributeMap attrs)`
  Adds a styled text segment.
  `RichParagraph.Builder`
  `addSegment(String text, StyleAttributeMap attrs)`
  Adds a styled text segment.
  `RichParagraph.Builder`
  `addWavyUnderline(int start, int length, String... css)`
  Adds a wavy underline (typically used as a spell checker indicator) with the specified style name(s).
  `RichParagraph.Builder`
  `addWavyUnderline(int start, int length, Color color)`
  Adds a wavy underline (typically used as a spell checker indicator) with the given color.
  `RichParagraph.Builder`
  `addWithInlineAndStyleNames(String text, String style, String... css)`
  Appends a text segment styled with both the inline style and the stylesheet style names.
  `RichParagraph.Builder`
  `addWithInlineStyle(String text, String style)`
  Appends a text segment styled with the stylesheet style names.
  `RichParagraph.Builder`
  `addWithStyleNames(String text, String... css)`
  Appends a text segment styled with the stylesheet style names.
  `RichParagraph`
  `build()`
  Creates an instance of immutable `RichParagraph` from information in this `Builder`.
  `StyledSegment`
  `getSegment(int index)`
  Returns the segment at the specified index.
  `int`
  `getSegmentCount()`
  Returns the number of segments currently added to the builder.
  `RichParagraph.Builder`
  `setParagraphAttributes(StyleAttributeMap a)`
  Sets the paragraph attributes.

  ### Methods declared in class Object

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

- ## Method Details

  - ### addWavyUnderline

    public RichParagraph.Builder addWavyUnderline(int start, int length, Color color)
    Adds a wavy underline (typically used as a spell checker indicator) with the given color.
    Parameters:
      `start` - the start offset
      `length` - the end offset
      `color` - the background color
    Returns:
      this `Builder` instance

  - ### addWavyUnderline

    public RichParagraph.Builder addWavyUnderline(int start, int length, String... css)
    Adds a wavy underline (typically used as a spell checker indicator) with the specified style name(s).

    The corresponding styles should define CSS properties applicable to `Path`.

    Parameters:
      `start` - the start offset
      `length` - the end offset
      `css` - the style name(s)
    Returns:
      this `Builder` instance
    Since:
      25

  - ### addSegment

    public RichParagraph.Builder addSegment(String text)
    Adds a text segment with no styling (i.e. using default style). This convenience method is equivalent to calling `addSegment(text, StyleAttributeMap.EMPTY);`
    Parameters:
      `text` - the text to append, must not contain `\n`, cannot be null
    Returns:
      this `Builder` instance

  - ### addWithStyleNames

    public RichParagraph.Builder addWithStyleNames(String text, String... css)
    Appends a text segment styled with the stylesheet style names. The corresponding styles should define CSS properties applicable to `Text`.
    Parameters:
      `text` - non-null text string
      `css` - array of style names, cannot be null
    Returns:
      this `Builder` instance

  - ### addWithInlineAndStyleNames

    public RichParagraph.Builder addWithInlineAndStyleNames(String text, String style, String... css)
    Appends a text segment styled with both the inline style and the stylesheet style names. The corresponding styles should define CSS properties applicable to `Text`.
    Parameters:
      `text` - non-null text string
      `style` - direct style (such as `-fx-fill:red;`), or null
      `css` - array of style names
    Returns:
      this `Builder` instance

  - ### addWithInlineStyle

    public RichParagraph.Builder addWithInlineStyle(String text, String style)
    Appends a text segment styled with the stylesheet style names. The corresponding styles should define CSS properties applicable to `Text`.
    Parameters:
      `text` - non-null text string
      `style` - the inline style (example `"-fx-fill:red;"`), or null
    Returns:
      this `Builder` instance

  - ### addSegment

    public RichParagraph.Builder addSegment(String text, StyleAttributeMap attrs)
    Adds a styled text segment.
    Parameters:
      `text` - the text to append, must not contain `\n`, cannot be null
      `attrs` - the styled attributes, cannot be null
    Returns:
      this `Builder` instance

  - ### addSegment

    public RichParagraph.Builder addSegment(String text, int start, int end, StyleAttributeMap attrs)
    Adds a styled text segment.
    Parameters:
      `text` - the source non-null string
      `start` - the start offset of the input string
      `end` - the end offset of the input string
      `attrs` - the styled attributes
    Returns:
      this `Builder` instance

  - ### addHighlight

    public RichParagraph.Builder addHighlight(int start, int length, Color color)
    Adds a color background highlight. Use translucent colors to enable multiple highlights in the same region of text.
    Parameters:
      `start` - the start offset
      `length` - the end offset
      `color` - the background color
    Returns:
      this `Builder` instance

  - ### addHighlight

    public RichParagraph.Builder addHighlight(int start, int length, String... css)
    Adds a highlight with the specified style name(s). Use translucent colors to enable multiple highlights in the same region of text.

    The corresponding styles should define CSS properties applicable to `Path`.

    Parameters:
      `start` - the start offset
      `length` - the end offset
      `css` - the style name(s)
    Returns:
      this `Builder` instance
    Since:
      25

  - ### addInlineNode

    public RichParagraph.Builder addInlineNode(Supplier<Node> generator)
    Adds an inline node.

    The supplied generator must not cache or keep reference to the created Node, but the created Node can keep a reference to the model or some property therein.

    For example, a bidirectional binding between an inline control and some property in the model would synchronize the model with all the views that use it.

    Parameters:
      `generator` - the generator that provides the actual `Node`
    Returns:
      this `Builder` instance

  - ### addInlineNode

    public RichParagraph.Builder addInlineNode(Supplier<Node> generator, StyleAttributeMap a)
    Adds an inline node.

    The supplied generator must not cache or keep a reference to the created Node, but the created Node can keep a reference to the model or some property therein.

    For example, a bidirectional binding between an inline control and some property in the model would synchronize the model with all the views that use it.

    Parameters:
      `generator` - the generator that provides the actual `Node`
      `a` - the segment styles
    Returns:
      this `Builder` instance
    Since:
      27

  - ### setParagraphAttributes

    public RichParagraph.Builder setParagraphAttributes(StyleAttributeMap a)
    Sets the paragraph attributes.
    Parameters:
      `a` - the paragraph attributes
    Returns:
      this `Builder` instance

  - ### getSegmentCount

    public int getSegmentCount()
    Returns the number of segments currently added to the builder.
    Returns:
      the number of segments
    Since:
      26

  - ### getSegment

    public StyledSegment getSegment(int index)
    Returns the segment at the specified index.
    Parameters:
      `index` - the segment index
    Returns:
      the segment
    Throws:
      `IndexOutOfBoundsException` - if the index is outside of the range `0 ... getSegmentCount()-1` (inclusive)
    Since:
      26

  - ### build

    public RichParagraph build()
    Creates an instance of immutable `RichParagraph` from information in this `Builder`.
    Returns:
      the new paragraph instance