Class UICapture
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final PathThe dedicated subdirectory within the ASI working folder for visual artifacts.static final SimpleDateFormatStandard timestamp format for screenshot filenames to ensure chronological ordering. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageTakes a screenshot of a given screen, must be called on the EDT.static BufferedImagegetSafeScreenCapture(Rectangle bounds) Performs a hardware screen capture using environment-aware safe bounds.Captures an image of every physical display device connected to the host system.Enumerates and captures all visible application windows currently registered with the AWT Frame manager.static byte[]screenshotComponent(Component comp) Captures a single Swing component by painting its current state into an off-screen buffer.static PathscreenshotToFile(int deviceIdx) Captures a high-fidelity image of a specific physical display device.
-
Field Details
-
TIMESTAMP_FORMAT
Standard timestamp format for screenshot filenames to ensure chronological ordering. -
SCREENSHOTS_DIR
The dedicated subdirectory within the ASI working folder for visual artifacts.
-
-
Constructor Details
-
UICapture
public UICapture()
-
-
Method Details
-
screenshotAllScreens
Captures an image of every physical display device connected to the host system.This method uses
Robotto 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
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
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
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, IOExceptionEnumerates 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
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.
-

