Class RSyntaxTextAreaTextResourceViewer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class RSyntaxTextAreaTextResourceViewer extends AbstractTextResourceViewer
A specialized viewer for textual resources using RSyntaxTextArea.

This viewer implements the AbstractTextResourceViewer contract, providing high-fidelity syntax highlighting and a professional Edit/Save experience for standalone environments.

Fidelity Singularity: For virtual resources (snippets), this viewer uses a single RSyntax component pair for both View and Edit modes to prevent library-level gutter duplication and layout desyncs.

Author:
anahata
See Also:
  • Field Details

    • previewArea

      private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea previewArea
      The RSyntax area used for the preview/viewport card.
    • editorArea

      private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea editorArea
      The RSyntax area used for the editor card.
    • previewScrollPane

      private org.fife.ui.rtextarea.RTextScrollPane previewScrollPane
      The scroll pane wrapping the preview area.
    • editorScrollPane

      private org.fife.ui.rtextarea.RTextScrollPane editorScrollPane
      The scroll pane wrapping the editor area.
  • Constructor Details

    • RSyntaxTextAreaTextResourceViewer

      public RSyntaxTextAreaTextResourceViewer(AgiPanel agiPanel, Resource resource)
      Constructs a new RSyntaxTextAreaTextResourceViewer.
      Parameters:
      agiPanel - The parent panel.
      resource - The resource to render.
    • RSyntaxTextAreaTextResourceViewer

      public RSyntaxTextAreaTextResourceViewer(AbstractAsiContainer container, Resource resource)
      Constructs a new RSyntaxTextAreaTextResourceViewer bound to a container context.
      Parameters:
      container - The parent container.
      resource - The resource to render.
  • Method Details

    • createPreviewComponent

      protected JComponent createPreviewComponent()
      Creates the read-only preview component for displaying processed resource content.

      Implementation details: Creates a read-only RSyntaxTextArea wrapped in an RTextScrollPane. If previewAsEditor is true, this method returns a dummy panel as the editor component will handle both modes to prevent gutter duplication.

      Specified by:
      createPreviewComponent in class AbstractTextResourceViewer
      Returns:
      The preview component.
    • createEditorComponent

      protected JComponent createEditorComponent()
      Creates the editable high-fidelity component for full-file modifications.

      Implementation details: Creates an editable RSyntaxTextArea wrapped in an RTextScrollPane for full-file modifications. In snippet mode, this component is used for both View and Edit states.

      Specified by:
      createEditorComponent in class AbstractTextResourceViewer
      Returns:
      The editor component.
    • createRSyntaxArea

      private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea createRSyntaxArea()
      Internal factory for RSyntaxTextArea with standard ASI styling.
      Returns:
      A styled RSyntaxTextArea instance.
    • setComponentEditable

      protected void setComponentEditable(boolean editable)
      Authoritatively toggles the editability of the internal text component.

      Implementation details: Authoritatively toggles the editability of the internal components. If snippets are using the single-component strategy, it only affects the editorArea.

      Specified by:
      setComponentEditable in class AbstractTextResourceViewer
      Parameters:
      editable - true to allow input.
    • onEditorActivated

      protected void onEditorActivated()
      Hook invoked when switching to the editor card.

      Implementation details: Loads the full text content from the resource handle into the editor area and resets the caret position to ensure a clean editing start.

      Specified by:
      onEditorActivated in class AbstractTextResourceViewer
    • onPreviewActivated

      protected void onPreviewActivated()
      Hook invoked when returning to the preview card.

      Implementation details: Disables the editor's editability and triggers a synchronization with the resource's latest viewport data.

      Specified by:
      onPreviewActivated in class AbstractTextResourceViewer
    • getEditorContent

      public String getEditorContent()
      Retrieves the current text content from the editor component for persistence.

      Implementation details: Returns the current text from the underlying RSyntaxTextArea.

      Specified by:
      getEditorContent in class AbstractTextResourceViewer
      Returns:
      The content string.
    • updatePreviewContent

      protected void updatePreviewContent(String content)
      Pushes incremental or full content updates to the preview component. Used for streaming fidelity during generation.

      Implementation details: Authoritative streaming ingestion point. Updates the active RSyntax area with incremental content, ensuring bit-by-bit generation fidelity.

      Specified by:
      updatePreviewContent in class AbstractTextResourceViewer
      Parameters:
      content - The new preview content.
    • syncWithResource

      protected void syncWithResource()
      Synchronizes UI controls with current resource state.

      SENSING PURITY: The Capability View always displays the full, authoritative source content from the handle. Semantic viewport processing (tail/grep) is only visible to the model in the RAG view.

      Implementation details: Performs a complete UI synchronization with the resource state. Ensures snippets are visible immediately by falling back to the handle's text if the viewport cache is not yet populated.

      Overrides:
      syncWithResource in class AbstractTextResourceViewer
    • getScrollPane

      public JScrollPane getScrollPane()
      Returns the internal scroll pane used by the concrete implementation.
      Specified by:
      getScrollPane in class AbstractTextResourceViewer
      Returns:
      The JScrollPane instance.
    • getPreferredSize

      public Dimension getPreferredSize()

      When vertical scrolling is disabled, ensures sufficient height so the horizontal scrollbar does not obscure the bottom line of text.

      Overrides:
      getPreferredSize in class JComponent
    • configureScrollBehavior

      protected void configureScrollBehavior()
      Discovers the internal JScrollPane and applies the current scroll behavior settings.

      Implementation details: Finds the JScrollPane inside the assembled host frame and installs the boundary-aware redispatcher on the "Event Leaf" component.

      Implementation details: Recursively finds the internal RSyntaxTextArea and installs the boundary-aware mouse wheel redispatcher to enable scroll passthrough.

      Overrides:
      configureScrollBehavior in class AbstractTextResourceViewer
    • installWheelForwarder

      private void installWheelForwarder(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea area)
      Installs the boundary-aware wheel redispatcher on an RSyntaxTextArea.
      Parameters:
      area - The text area component.
    • mapLanguageToSyntax

      public static String mapLanguageToSyntax(String language)
      Maps a language string or file name to an RSyntaxTextArea syntax style constant.
      Parameters:
      language - The language string or file name.
      Returns:
      The corresponding syntax style constant.