Class ContextPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
uno.anahata.asi.swing.agi.context.ContextPanel
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
A panel dedicated to displaying and managing the available AI context
(history, tools, providers, and resources) using a hierarchical JXTreeTable.
This panel provides a JNDI-style view of the entire AI context. It uses a split-pane layout with a tree table on the left and a detail area on the right that switches panels based on the selected node type.
- Author:
- anahata
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AgiThe active agi session.private final AgiPanelThe parent agi panel.private booleanFlag indicating token calculation is currently running in the background.private ObjectThe currently selected domain object to prevent redundant rendering.private final Map<Class<?>, BiConsumer<Object, JPanel>> Registry for mapping domain types to custom UI configurers.private final JPanelContainer for the detail panels, using CardLayout for switching.private final CardLayoutLayout for switching between detail panels.private EdtPropertyChangeListenerListener for history changes to trigger tree refreshes.private booleanFlag to ensure initComponents is only called once.private final ScrollablePanelContainer for dynamically created message or part panels.private final ContextProviderPanelPanel for displaying context provider details.private booleanFlag indicating a refresh is in progress, used to mute selection events and flicker.private final ResourcePanelPanel for displaying V2 resource details.private EdtPropertyChangeListenerListener for resource changes to trigger tree refreshes.private final ToolkitPanelPanel for displaying toolkit details.private final ToolPanelPanel for displaying tool details.private final org.jdesktop.swingx.JXTreeTableThe tree table component for the context hierarchy.private ContextTreeTableModelThe model for the tree table.Fields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidTriggers an initial refresh when the component is added to the UI.private voidapplyColumnWidth(int modelIndex, int preferredWidth, int minWidth) Helper method to apply width to a specific column identified by its model index.private voidAuthoritatively applies the standard column widths to the tree table.private JScrollPanecreateScrollPane(Component component) Standardizes a component within a borderless scroll pane.getAgi()Gets the active agi session.Gets the parent agi panel.Captures the current expansion state of the tree.voidInitializes the components and layout of the panel.private voidopenResource(Resource res) Delegates resource opening to the active ResourceUI strategy.voidpopulateCustomConfig(Object obj, JPanel panel) Populates a panel with custom configuration UI for a given object, if registered.final voidrefresh(boolean structural) Refreshes the data in the tree table while preserving expansion state and column widths.voidTriggers a background recalculation of token counts (Convenience no-arg version).voidrefreshTokens(Runnable onDone) Triggers a background recalculation of token counts.<T> voidregisterCustomConfig(Class<T> type, BiConsumer<T, JPanel> configurer) Registers a custom UI configurer for a specific domain object type.private voidRegisters the default configuration UIs for core components.voidreload()Reloads the panel with the new agi state.private voidrestoreExpandedPaths(Set<TreePath> expandedPaths) Restores the expansion state of the tree.private voidConfigures the popup menu and double-click behavior for the tree table.private voidSets up property change listeners for the current agi session.private voidupdateMessagePartDetail(JPanel panel) Updates the message/part detail area with the given panel.Methods inherited from class JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
agiPanel
The parent agi panel. -
agi
The active agi session. -
treeTable
private final org.jdesktop.swingx.JXTreeTable treeTableThe tree table component for the context hierarchy. -
treeTableModel
The model for the tree table. -
detailContainer
Container for the detail panels, using CardLayout for switching. -
detailLayout
Layout for switching between detail panels. -
toolPanel
Panel for displaying tool details. -
toolkitPanel
Panel for displaying toolkit details. -
providerPanel
Panel for displaying context provider details. -
resourcePanel
Panel for displaying V2 resource details. -
messagePartDetailPanel
Container for dynamically created message or part panels. -
currentSelectedDomainObject
The currently selected domain object to prevent redundant rendering. -
refreshing
private boolean refreshingFlag indicating a refresh is in progress, used to mute selection events and flicker. -
calculatingTokens
private boolean calculatingTokensFlag indicating token calculation is currently running in the background. -
customConfigRegistry
Registry for mapping domain types to custom UI configurers. -
historyListener
Listener for history changes to trigger tree refreshes. -
resourcesListener
Listener for resource changes to trigger tree refreshes. -
initialized
private boolean initializedFlag to ensure initComponents is only called once.
-
-
Constructor Details
-
ContextPanel
Constructs a new ContextPanel.- Parameters:
agiPanel- The parent agi panel.
-
-
Method Details
-
createScrollPane
Standardizes a component within a borderless scroll pane.- Parameters:
component- The component to wrap.- Returns:
- The scroll pane.
-
registerDefaultCustomConfigs
private void registerDefaultCustomConfigs()Registers the default configuration UIs for core components. -
registerCustomConfig
Registers a custom UI configurer for a specific domain object type.- Type Parameters:
T- The type of the domain object.- Parameters:
type- The class of the domain object.configurer- A consumer that populates a provided JPanel based on the object instance.
-
populateCustomConfig
-
setupListeners
private void setupListeners()Sets up property change listeners for the current agi session. -
getAgiPanel
-
getAgi
-
initComponents
public void initComponents()Initializes the components and layout of the panel. -
setupInteractions
private void setupInteractions()Configures the popup menu and double-click behavior for the tree table. -
openResource
Delegates resource opening to the active ResourceUI strategy.- Parameters:
res- The resource to open.
-
applyColumnWidths
private void applyColumnWidths()Authoritatively applies the standard column widths to the tree table. This method ensures the 'Name' column maintains its 400px width and token columns are correctly sized.It uses model-to-view conversion to ensure the correct columns are targeted even if the user has reordered or hidden them.
-
applyColumnWidth
private void applyColumnWidth(int modelIndex, int preferredWidth, int minWidth) Helper method to apply width to a specific column identified by its model index.- Parameters:
modelIndex- The index of the column in the model.preferredWidth- The desired preferred width.minWidth- The minimum width (optional, use 0 to skip).
-
updateMessagePartDetail
Updates the message/part detail area with the given panel.- Parameters:
panel- The panel to display.
-
reload
public void reload()Reloads the panel with the new agi state. -
refresh
public final void refresh(boolean structural) Refreshes the data in the tree table while preserving expansion state and column widths.- Parameters:
structural- If true, the underlying model is rebuilt (e.g. on session switch).
-
getExpandedPaths
-
restoreExpandedPaths
-
refreshTokens
Triggers a background recalculation of token counts.- Parameters:
onDone- Optional callback to run after tokens are refreshed.
-
refreshTokens
public void refreshTokens()Triggers a background recalculation of token counts (Convenience no-arg version). -
addNotify
public void addNotify()Triggers an initial refresh when the component is added to the UI.- Overrides:
addNotifyin classJComponent
-

