Class AbstractTextResourceViewer

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
uno.anahata.asi.swing.agi.resources.view.AbstractTextResourceViewer
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
IntellijTextResourceViewer, NetBeansTextResourceViewer, RSyntaxTextAreaTextResourceViewer

public abstract class AbstractTextResourceViewer extends JPanel
Common base for high-fidelity text resource viewers with autonomous Edit/Save UI.

This class provides the integrated control strip containing the Edit/Save toggle.

Capability Purity: The Capability View (this component) always displays the full source content of the resource. Semantic processing like Tail, Grep, or Viewport-injected line numbers are reserved exclusively for the 'Model Perspective' (RAG) to ensure the user always has a clean, authoritative view of the source.

Author:
anahata
See Also:
  • Field Details

    • agiPanel

      protected final AgiPanel agiPanel
      The parent AgiPanel providing the session context.
    • container

      protected final AbstractAsiContainer container
      The parent AbstractAsiContainer providing the container context.
    • resource

      protected final Resource resource
      The resource orchestrator being viewed.
    • cardLayout

      protected final CardLayout cardLayout
      The layout manager for swapping between preview and editor views.
    • cardPanel

      protected final JPanel cardPanel
      The container panel for the card layout.
    • controlStrip

      protected JToolBar controlStrip
      The integrated toolbar for edit actions.
    • actionNexus

      protected JPanel actionNexus
      The panel hosting the edit and save buttons.
    • editBtn

      protected JButton editBtn
      The button to toggle between View and Edit modes.
    • cancelBtn

      protected JButton cancelBtn
      The button to cancel editing without saving.
    • copyBtn

      protected JButton copyBtn
      The button to copy the current content to clipboard.
    • editing

      protected boolean editing
      Flag indicating the current UI mode (view vs edit).
    • syncing

      private boolean syncing
      Flag used to disable listeners during UI synchronization to prevent recursive feedback loops.
    • verticalScrollEnabled

      protected boolean verticalScrollEnabled
      Flag indicating if vertical scrolling is enabled. Defaults to true (Resource Panel). Should be set to false for Chat Snippets.
    • previewAsEditor

      protected boolean previewAsEditor
      If true, the 'Preview' mode uses the high-fidelity editor component (read-only) instead of the viewport. This ensures snippets don't lose text when saving.

      Clean-Room Default: snippets (virtual resources) default to true.

    • saveAction

      The delegate responsible for persistence.
    • resourceListener

      private EdtPropertyChangeListener resourceListener
      The reactive listener for resource state changes.
  • Constructor Details

    • AbstractTextResourceViewer

      protected AbstractTextResourceViewer(AgiPanel agiPanel, Resource resource)
      Constructs a new AbstractTextResourceViewer bound to a session context.
      Parameters:
      agiPanel - The parent AgiPanel.
      resource - The text resource.
    • AbstractTextResourceViewer

      protected AbstractTextResourceViewer(AbstractAsiContainer container, Resource resource)
      Constructs a new AbstractTextResourceViewer bound to a container context.
      Parameters:
      container - The parent AbstractAsiContainer.
      resource - The text resource.
  • Method Details

    • getResource

      public Resource getResource()
      Returns the managed resource orchestrator.
      Returns:
      The resource instance.
    • initComponents

      private void initComponents()
      Initializes the UI components and assemblies the integrated control strip.
    • toggleEditMode

      public void toggleEditMode()
      Toggles between read-only viewport view and high-fidelity editor.
    • setEditing

      public void setEditing(boolean editing)
      Updates the UI to reflect the current editing state.

      For snippets, this method ensures we stay on the high-fidelity card but toggle component editability.

      Parameters:
      editing - true to enable editing.
    • setEditButtonVisible

      public void setEditButtonVisible(boolean visible)
      Controls the visibility of the Edit button in the control strip.
      Parameters:
      visible - true to show the edit button, false to hide it.
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Authoritatively configures the viewer for read-only mode. This hides the edit button and ensures the component is not in edit mode.
      Parameters:
      readOnly - true to force read-only mode.
    • setToolbarVisible

      public void setToolbarVisible(boolean visible)
      Controls the visibility of the entire integrated control strip.
      Parameters:
      visible - true to show the toolbar.
    • setVerticalScrollEnabled

      public void setVerticalScrollEnabled(boolean enabled)
      Configures whether vertical scrolling is enabled in the internal scroll pane.

      High-Fidelity Scroll Passthrough: If vertical scrolling is disabled (e.g., in chat snippets), this method recursively finds the innermost text component and installs a boundary-aware mouse wheel redispatcher.

      Parameters:
      enabled - true to enable standard vertical scrolling.
    • 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.

    • getScrollPane

      public abstract JScrollPane getScrollPane()
      Returns the internal scroll pane used by the concrete implementation.
      Returns:
      The JScrollPane instance.
    • createPreviewComponent

      protected abstract JComponent createPreviewComponent()
      Creates the read-only preview component for displaying processed resource content.
      Returns:
      The preview component.
    • createEditorComponent

      protected abstract JComponent createEditorComponent()
      Creates the editable high-fidelity component for full-file modifications.
      Returns:
      The editor component.
    • setComponentEditable

      protected abstract void setComponentEditable(boolean editable)
      Authoritatively toggles the editability of the internal text component.
      Parameters:
      editable - true to allow input.
    • onEditorActivated

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

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

      public abstract String getEditorContent()
      Retrieves the current text content from the editor component for persistence.
      Returns:
      The content string.
    • updatePreviewContent

      protected abstract void updatePreviewContent(String content)
      Pushes incremental or full content updates to the preview component. Used for streaming fidelity during generation.
      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.