Class UICapture

java.lang.Object
uno.anahata.asi.swing.internal.UICapture

public class UICapture extends Object
A native-aware utility for capturing visual snapshots of the host's desktop environment and individual Swing frames.

This class serves as the Vision Bridge for the ASI, allowing it to observe both its own UI and other application windows currently visible to the user. It manages the storage and lifecycle of screenshot artifacts within the ASI work directory.

Author:
anahata
  • Field Details

    • TIMESTAMP_FORMAT

      public static final SimpleDateFormat TIMESTAMP_FORMAT
      Standard timestamp format for screenshot filenames to ensure chronological ordering.
    • SCREENSHOTS_DIR

      public static final Path SCREENSHOTS_DIR
      The dedicated subdirectory within the ASI working folder for visual artifacts.
  • Constructor Details

    • UICapture

      public UICapture()
  • Method Details

    • screenshotAllScreens

      public static List<Path> screenshotAllScreens() throws Exception
      Captures an image of every physical display device connected to the host system.

      This method uses Robot to perform low-level hardware scrapes, ensuring that the screenshots reflect exactly what the user sees on their monitors.

      Returns:
      A list of Paths to the generated PNG artifacts.
      Throws:
      IOException - if the native capture or file write operation fails.
      Exception
    • getSafeScreenCapture

      public static BufferedImage getSafeScreenCapture(Rectangle bounds) throws AWTException
      Performs a hardware screen capture using environment-aware safe bounds.
      Parameters:
      bounds - The bounds
      Returns:
      The captured image.
      Throws:
      AWTException - if the Robot cannot be initialized.
    • getSafeScreenCapture

      public static BufferedImage getSafeScreenCapture(GraphicsDevice gd) throws AWTException
      Takes a screenshot of a given screen, must be called on the EDT.
      Parameters:
      gd - the physical screen device.
      Returns:
      the captured BufferedImage.
      Throws:
      AWTException - if the Robot class cannot be initialized on this graphics device.
    • screenshotToFile

      public static Path screenshotToFile(int deviceIdx) throws Exception
      Captures a high-fidelity image of a specific physical display device.

      This method is the atomic operation for multi-screen capture. It ensures that the requested display index exists before attempting the hardware scrape. It uses getSafeScreenCapture(GraphicsDevice) to avoid Wayland-specific issues.

      Parameters:
      deviceIdx - The 0-based index of the graphics device.
      Returns:
      The Path to the generated PNG artifact.
      Throws:
      IOException - if the capture or disk write operation fails.
      Exception
    • screenshotAllWindows

      public static List<Path> screenshotAllWindows() throws InterruptedException, InvocationTargetException, IOException
      Enumerates and captures all visible application windows currently registered with the AWT Frame manager.

      EDT Awareness: This method orchestrates a synchronous wait on the EDT to perform the paint() operation safely, ensuring visual consistency with the current UI state.

      Returns:
      A list of Paths to the captured window snapshots.
      Throws:
      InterruptedException - if the EDT wait is interrupted.
      InvocationTargetException - if the paint operation fails.
      IOException - if the file write fails.
    • screenshotComponent

      public static byte[] screenshotComponent(Component comp) throws IOException
      Captures a single Swing component by painting its current state into an off-screen buffer.

      This is the most granular vision tool, used for capturing specific UI elements (like a single chart or a conversation part) without capturing the surrounding window clutter.

      Parameters:
      comp - The component to capture.
      Returns:
      The raw PNG bytes of the capture.
      Throws:
      IOException - if the capture or encoding fails.