Class AbstractTextSegmentRenderer
java.lang.Object
uno.anahata.asi.swing.agi.message.part.text.AbstractTextSegmentRenderer
- Direct Known Subclasses:
CodeBlockSegmentRenderer, MarkupTextSegmentRenderer
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final SwingAgiConfigThe agi configuration.protected final AgiPanelThe parent agi panel.protected booleanWhether the segment is fully closed/complete.protected JComponentThe actual Swing component being rendered.protected StringThe raw content for this segment.protected StringThe content that was last rendered into the component. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractTextSegmentRenderer(AgiPanel agiPanel, String initialContent) Constructs a new AbstractTextSegmentRenderer. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidSets the last rendered content to the current content.protected booleanChecks if the current content is different from the last rendered content.abstract booleanmatches(TextSegmentDescriptor descriptor) Determines if this renderer can handle the given segment descriptor.abstract booleanrender()Renders or updates the segment's JComponent based on the current content.protected voidupdateComponentContent(String content) Pushes incremental content updates to the visual component.voidupdateContent(String newContent) Updates the current content of this segment.voidForces the renderer to refresh its visual styling (e.g., colors, fonts) to align with the active Look and Feel.
-
Field Details
-
agiPanel
The parent agi panel. -
agiConfig
The agi configuration. -
component
The actual Swing component being rendered. -
currentContent
The raw content for this segment. -
lastRenderedContent
The content that was last rendered into the component. -
closed
protected boolean closedWhether the segment is fully closed/complete. For code blocks, this is true if the closing backticks are present.
-
-
Constructor Details
-
AbstractTextSegmentRenderer
-
-
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
-
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
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
Determines if this renderer can handle the given segment descriptor. Subclasses must implement this to specify their compatibility.- Parameters:
descriptor- TheTextSegmentDescriptorto check.- Returns:
- True if this renderer can handle the descriptor, false otherwise.
-

