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

# Class StyledSegment

java.lang.Object
jfx.incubator.scene.control.richtext.model.StyledSegment

public abstract class StyledSegment extends Object
Data structure used to modify the styled text model.

Each instance represents:

1. a single text segment with direct style and/or style names
2. a line break
3. an inline Node
4. a paragraph containing a single Region
5. paragraph attributes
6. document properties
7. version string

Since:
  24

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `StyledSegment.Type`
  StyledSegment type

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final StyledSegment`
  `LINE_BREAK`
  A styled segment that represents a line break

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Map<String,String>`
  `getDocumentProperties()`
  Returns the document properties or `null` if the segment type is not `StyledSegment.Type.DOCUMENT_PROPERTIES`.
  `Supplier<Node>`
  `getInlineNodeGenerator()`
  This method must return a non-null value for a segment of `INLINE_NODE` type, or null in any other case.
  `Supplier<Region>`
  `getParagraphNodeGenerator()`
  This method must return a non-null value for a segment of `REGION` type, or null in any other case.
  `StyleAttributeMap`
  `getStyleAttributeMap(StyleResolver resolver)`
  This method returns StyleAttributeMap (or null) for this segment.
  `String`
  `getText()`
  Returns the text associated with this segment.
  `int`
  `getTextLength()`
  Returns the length of text in the segment, or 0 for segments that contain no text or where `getText()` returns null.
  `abstract StyledSegment.Type`
  `getType()`
  Returns the type of this StyledSegment.
  `String`
  `getVersion()`
  Returns the document version or `null` if the segment type is not `StyledSegment.Type.VERSION`.
  `static StyledSegment`
  `of(String text)`
  Creates a StyleSegment from a non-null plain text.
  `static StyledSegment`
  `of(String text, StyleAttributeMap attrs)`
  Creates a StyleSegment from a non-null plain text and style attributes.
  `static StyledSegment`
  `ofDocumentProperties(Map<String,String> props)`
  Creates a StyledSegment that contains the document properties.
  `static StyledSegment`
  `ofInlineNode(Supplier<Node> generator, StyleAttributeMap attr)`
  Creates a StyledSegment which consists of a single inline Node with the specified styles (the styles can be `null`, which is equivalent to `StyleAttributeMap.EMPTY`).
  `static StyledSegment`
  `ofParagraphAttributes(StyleAttributeMap attrs)`
  Creates a StyledSegment which contains paragraph attributes only.
  `static StyledSegment`
  `ofRegion(Supplier<Region> generator)`
  Creates a StyledSegment for a paragraph that contains a single Region.
  `static StyledSegment`
  `ofVersion(String version)`
  Creates a StyledSegment that contains the document version.
  `abstract StyledSegment`
  `subSegment(int start, int end)`
  Creates a sub-segment of this segment.

  ### Methods declared in class Object

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

- ## Field Details

  - ### LINE_BREAK

    public static final StyledSegment LINE_BREAK
    A styled segment that represents a line break

- ## Method Details

  - ### getType

    public abstract StyledSegment.Type getType()
    Returns the type of this StyledSegment.
    Returns:
      the type

  - ### getText

    public String getText()
    Returns the text associated with this segment. Must be one character for inline nodes, must be null for node paragraphs or line breaks.
    Returns:
      the segment plain text

  - ### getTextLength

    public int getTextLength()
    Returns the length of text in the segment, or 0 for segments that contain no text or where `getText()` returns null.
    Returns:
      the length in characters

  - ### getInlineNodeGenerator

    public Supplier<Node> getInlineNodeGenerator()
    This method must return a non-null value for a segment of `INLINE_NODE` type, or null in any other case.
    Returns:
      code that creates a Node instance, or null

  - ### getParagraphNodeGenerator

    public Supplier<Region> getParagraphNodeGenerator()
    This method must return a non-null value for a segment of `REGION` type, or null in any other case.
    Returns:
      code that creates a Region instance, or null

  - ### getStyleAttributeMap

    public StyleAttributeMap getStyleAttributeMap(StyleResolver resolver)
    This method returns StyleAttributeMap (or null) for this segment. When the model manages style names (instead of actual attributes), an instance of `StyleResolver` may be used to convert the style names to individual attributes. Keep in mind that different views might have different stylesheet applied and resulting in a different set of attributes.
    Parameters:
      `resolver` - the style resolver to use
    Returns:
      style attributes

  - ### subSegment

    public abstract StyledSegment subSegment(int start, int end)
    Creates a sub-segment of this segment.
    Parameters:
      `start` - the start offset
      `end` - the end offset
    Returns:
      the StyledSegment

  - ### getDocumentProperties

    public Map<String,String> getDocumentProperties()
    Returns the document properties or `null` if the segment type is not `StyledSegment.Type.DOCUMENT_PROPERTIES`.
    Returns:
      the properties or null
    Since:
      27

  - ### getVersion

    public String getVersion()
    Returns the document version or `null` if the segment type is not `StyledSegment.Type.VERSION`.
    Returns:
      the version string or null
    Since:
      27

  - ### of

    public static StyledSegment of(String text)
    Creates a StyleSegment from a non-null plain text. Important: text must not contain any characters < 0x20, except for TAB.
    Parameters:
      `text` - the segment text
    Returns:
      the StyledSegment instance

  - ### of

    public static StyledSegment of(String text, StyleAttributeMap attrs)
    Creates a StyleSegment from a non-null plain text and style attributes. Important: text must not contain any characters < 0x20, except for TAB.
    Parameters:
      `text` - the segment text
      `attrs` - the segment style attributes
    Returns:
      the StyledSegment instance

  - ### ofDocumentProperties

    public static StyledSegment ofDocumentProperties(Map<String,String> props)
    Creates a StyledSegment that contains the document properties.
    Parameters:
      `props` - the document properties
    Returns:
      the StyledSegment instance
    Since:
      27

  - ### ofVersion

    public static StyledSegment ofVersion(String version)
    Creates a StyledSegment that contains the document version.
    Parameters:
      `version` - the document version
    Returns:
      the StyledSegment instance
    Since:
      27

  - ### ofInlineNode

    public static StyledSegment ofInlineNode(Supplier<Node> generator, StyleAttributeMap attr)
    Creates a StyledSegment which consists of a single inline Node with the specified styles (the styles can be `null`, which is equivalent to `StyleAttributeMap.EMPTY`).
    Parameters:
      `generator` - the code to create a Node instance
      `attr` - the segment styles, can be null
    Returns:
      the StyledSegment instance
    Since:
      27

  - ### ofRegion

    public static StyledSegment ofRegion(Supplier<Region> generator)
    Creates a StyledSegment for a paragraph that contains a single Region.
    Parameters:
      `generator` - the code to create a Region instance
    Returns:
      the StyledSegment instance

  - ### ofParagraphAttributes

    public static StyledSegment ofParagraphAttributes(StyleAttributeMap attrs)
    Creates a StyledSegment which contains paragraph attributes only.
    Parameters:
      `attrs` - the paragraph attributes
    Returns:
      the StyledSegment instance