java.lang.Object
io.github.jspinak.brobot.actions.composites.methods.drag.Drag
All Implemented Interfaces:
ActionInterface

@Component public class Drag extends Object implements ActionInterface
Performs drag-and-drop operations between GUI elements in the Brobot model-based automation framework.

Drag is a composite action in the Action Model (α) that combines multiple basic actions to implement complex drag-and-drop interactions. It seamlessly handles dragging between various target types including visually identified elements (Image Matches), screen areas (Regions), and specific coordinates (Locations), providing a unified interface for all drag operations.

Architecture:

  • Composite Design: Combines Find actions with platform-specific drag operations
  • Two-phase Execution: First finds the 'from' location, then the 'to' location
  • Flexible Targeting: Supports Image Matches, Regions, and Locations for both source and destination
  • Result Tracking: Returns a defined region representing the drag path

Supported drag patterns:

  • Image to Image: Drag from one visual element to another
  • Image to Region: Drag from a visual element to a screen area
  • Location to Location: Precise coordinate-based dragging
  • Any combination of Image Match, Region, or Location

Common use cases:

  • Moving files between folders in file managers
  • Rearranging items in lists or grids
  • Drawing or selecting areas in graphics applications
  • Adjusting sliders or other draggable UI controls
  • Drag-based gesture interactions in modern applications

Implementation details:

  • Uses ObjectCollection #1 for the 'from' location
  • Uses ObjectCollection #2 for the 'to' location
  • Returns matches for the 'to' location, not the 'from' location
  • Adds a DefinedRegion to matches with drag path coordinates
  • Supports offset adjustments for precise positioning

In the model-based approach, Drag actions represent high-level GUI interactions that would otherwise require multiple coordinated low-level actions. By encapsulating the complexity of drag-and-drop operations, the framework enables more natural and maintainable automation scripts that closely mirror human interactions with the GUI.

Since:
1.0
See Also:
  • Constructor Details

  • Method Details

    • perform

      public void perform(Matches matches, ObjectCollection... objectCollections)
      The two Actions used are Find and Drag. Find is used twice, once for the 'from' Match and once for the 'to' Match. Matches with the 'to' Match. The 'from' Match is not returned. It additionally returns a DefinedRegion with x,y as the DragFrom Location and x2,y2 as the DragTo Location.
      Specified by:
      perform in interface ActionInterface
      Parameters:
      matches - has mostly options for Drag but also a few options for Find
      objectCollections - ObjectCollection #1 for the 'from' Match, and #2 for the 'to' Match.