Class MarkupTextSegmentRenderer

java.lang.Object
uno.anahata.asi.swing.agi.message.part.text.AbstractTextSegmentRenderer
uno.anahata.asi.swing.agi.message.part.text.MarkupTextSegmentRenderer

public class MarkupTextSegmentRenderer extends AbstractTextSegmentRenderer
Renders a markdown text segment into a WrappingEditorPane. This class extends AbstractTextSegmentRenderer and handles the conversion of markdown to HTML and applying appropriate styling.
Author:
anahata
  • Field Details

    • markdownParser

      private final com.vladsch.flexmark.parser.Parser markdownParser
      The Flexmark markdown parser.
    • htmlRenderer

      private final com.vladsch.flexmark.html.HtmlRenderer htmlRenderer
      The Flexmark HTML renderer.
    • isThought

      private final boolean isThought
      Whether this segment represents a model thought.
    • innerComponent

      private WrappingEditorPane innerComponent
      The inner text component.
  • Constructor Details

    • MarkupTextSegmentRenderer

      public MarkupTextSegmentRenderer(AgiPanel agiPanel, String initialContent, boolean isThought)
      Constructs a new MarkupTextSegmentRenderer.
      Parameters:
      agiPanel - The agi panel instance.
      initialContent - The initial markdown content for this segment.
      isThought - True if the text represents a model thought, false otherwise.
  • Method Details

    • render

      public boolean render()
      Renders or updates the segment's JComponent based on the current content. This method should be called to ensure the component reflects the latest content. It should handle diffing internally to avoid unnecessary re-creation of components. It reuses the existing WrappingEditorPane if available and updates its content only if the markdown text has changed.
      Specified by:
      render in class AbstractTextSegmentRenderer
      Returns:
      True if a visual update occurred, false otherwise.
    • updateStyleSheet

      private void updateStyleSheet(StyleSheet sheet)
    • updateTheme

      public void updateTheme()
      Forces the renderer to refresh its visual styling (e.g., colors, fonts) to align with the active Look and Feel.

      Overridden to clear the render cache and force a complete HTML text rebuild with the fresh theme colors.

      Overrides:
      updateTheme in class AbstractTextSegmentRenderer
    • matches

      public boolean matches(TextSegmentDescriptor descriptor)
      Determines if this renderer can handle the given segment descriptor. Subclasses must implement this to specify their compatibility. A MarkupTextSegmentRenderer handles TextSegmentType.TEXT descriptors.
      Specified by:
      matches in class AbstractTextSegmentRenderer
      Parameters:
      descriptor - The TextSegmentDescriptor to check.
      Returns:
      True if this renderer can handle the descriptor, false otherwise.