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
Since:
24
  • Field Details Link icon

    • LINE_BREAK Link icon

      public static final StyledSegment LINE_BREAK
      A styled segment that represents a line break
  • Method Details Link icon

    • getType Link icon

      public abstract StyledSegment.Type getType()
      Returns the type of this StyledSegment.
      Returns:
      the type
    • getText Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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
    • of Link icon

      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 Link icon

      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
    • ofInlineNode Link icon

      public static StyledSegment ofInlineNode(Supplier<Node> generator)
      Creates a StyledSegment which consists of a single inline Node.
      Parameters:
      generator - the code to create a Node instance
      Returns:
      the StyledSegment instance
    • ofRegion Link icon

      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 Link icon

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