Class AbstractTextSegmentRenderer

java.lang.Object
uno.anahata.asi.swing.agi.message.part.text.AbstractTextSegmentRenderer
Direct Known Subclasses:
CodeBlockSegmentRenderer, MarkupTextSegmentRenderer

public abstract class AbstractTextSegmentRenderer extends Object
Abstract base class for rendering individual text segments (e.g., markdown text or code blocks). It manages the component, current content, and provides a mechanism for diff-based updates.
Author:
anahata
  • Field Details

    • agiPanel

      protected final AgiPanel agiPanel
      The parent agi panel.
    • agiConfig

      protected final SwingAgiConfig agiConfig
      The agi configuration.
    • component

      protected JComponent component
      The actual Swing component being rendered.
    • currentContent

      protected String currentContent
      The raw content for this segment.
    • lastRenderedContent

      protected String lastRenderedContent
      The content that was last rendered into the component.
    • closed

      protected boolean closed
      Whether the segment is fully closed/complete. For code blocks, this is true if the closing backticks are present.
  • Constructor Details

    • AbstractTextSegmentRenderer

      public AbstractTextSegmentRenderer(AgiPanel agiPanel, String initialContent)
      Constructs a new AbstractTextSegmentRenderer.
      Parameters:
      agiPanel - The agi panel instance.
      initialContent - The initial raw content for this segment.
  • Method Details

    • render

      public abstract 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.
      Returns:
      True if a visual update occurred, false otherwise.
    • updateContent

      public void updateContent(String newContent)
      Updates the current content of this segment. The next call to render() will reflect this new content.
      Parameters:
      newContent - The new raw content for this segment.
    • hasContentChanged

      protected boolean hasContentChanged()
      Checks if the current content is different from the last rendered content.
      Returns:
      True if the content has changed, false otherwise.
    • contentRendered

      protected void contentRendered()
      Sets the last rendered content to the current content. This should be called after a successful render operation.
    • updateComponentContent

      protected void updateComponentContent(String content)
      Pushes incremental content updates to the visual component. This is the authoritative ingestion point for streaming responses.
      Parameters:
      content - The new segment content.
    • updateTheme

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

      public abstract boolean matches(TextSegmentDescriptor descriptor)
      Determines if this renderer can handle the given segment descriptor. Subclasses must implement this to specify their compatibility.
      Parameters:
      descriptor - The TextSegmentDescriptor to check.
      Returns:
      True if this renderer can handle the descriptor, false otherwise.