Class ContextUsageBar

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ContextUsageBar extends JPanel
A high-precision UI component that renders a progress bar for context window usage.

This component acts as a real-time observer of the ContextManager, providing visual feedback on token consumption relative to the model's configured threshold. It dynamically updates its color based on usage levels and session status.

Author:
anahata
See Also:
  • Field Details

    • PERCENT_FORMAT

      private static final DecimalFormat PERCENT_FORMAT
      Formatter for percentage display.
    • NUMBER_FORMAT

      private static final NumberFormat NUMBER_FORMAT
      Formatter for raw token counts.
    • BAR_HEIGHT

      private static final int BAR_HEIGHT
      Fixed height for the usage bar.
      See Also:
    • MIN_WIDTH

      private static final int MIN_WIDTH
      Minimum width to ensure text readability.
      See Also:
    • agiPanel

      private final AgiPanel agiPanel
      The parent agi panel providing session context.
    • totalTokens

      private int totalTokens
      Current total token count in the context.
    • maxTokens

      private int maxTokens
      The maximum token threshold allowed by the configuration.
    • percentage

      private double percentage
      Normalized usage percentage (0.0 to 1.0).
    • usageText

      private String usageText
      Human-readable usage string (e.g., "45.2% (12,000 / 25,000)").
    • status

      private AgiStatus status
      The current state of the AGI session.
  • Constructor Details

    • ContextUsageBar

      public ContextUsageBar(AgiPanel agiPanel)
      Constructs a new ContextUsageBar.
      Parameters:
      agiPanel - The agi panel instance.
  • Method Details

    • reload

      public void reload()
      Reloads the bar with the new agi state.
    • refresh

      public void refresh()
      Refreshes the bar's state by querying the agi's status and context managers.
    • paintComponent

      protected void paintComponent(Graphics g)

      Renders a multi-layered usage bar with a background, a progress fill using the Barça-inspired status palette, and a centered text overlay.

      Overrides:
      paintComponent in class JComponent