ActionConfig Overview
Introduction
ActionConfig is the new foundation for configuring automation actions in Brobot. It replaces the monolithic ActionOptions
class with a more modular, type-safe hierarchy of configuration classes.
Why ActionConfig?
The previous ActionOptions
class had several limitations:
- One size fits all: A single class tried to handle configuration for all action types
- Type safety: No compile-time checking for action-specific options
- Complexity: Many fields were only relevant to specific actions
- Maintenance: Adding new actions required modifying the central ActionOptions class
ActionConfig solves these problems by:
- Modularity: Each action has its own configuration class
- Type safety: The compiler ensures you're using the right options for each action
- Clarity: Each configuration class only contains relevant fields
- Extensibility: New actions can be added without modifying existing code
The ActionConfig Hierarchy
ActionConfig (abstract base)
├── BaseFindOptions (abstract)
│ ├── PatternFindOptions
│ ├── HistogramFindOptions
│ ├── MotionFindOptions
│ └── VanishOptions
├── ClickOptions
├── TypeOptions
├── MouseMoveOptions
├── MouseDownOptions
├── MouseUpOptions
├── ScrollMouseWheelOptions
├── DefineRegionOptions
├── HighlightOptions
├── DragOptions
├── ClickUntilOptions
└── PlaybackOptions
Key Concepts
1. Builder Pattern
All ActionConfig classes use the builder pattern for construction:
ClickOptions click = new ClickOptions.Builder()
.setNumberOfClicks(2)
.setPauseBeforeBegin(0.5)
.build();
2. Fluent Chaining
Actions can be chained together using the then()
method:
BaseFindOptions findAndClick = new PatternFindOptions.Builder()
.setSimilarity(0.9)
.then(new ClickOptions.Builder()
.setNumberOfClicks(1)
.build())
.build();
3. Composition Over Inheritance
Shared configurations like MousePressOptions
are composed rather than inherited:
ClickOptions rightClick = new ClickOptions.Builder()
.setNumberOfClicks(1)
.setPressOptions(new MousePressOptions.Builder()
.setButton(MouseButton.RIGHT)
.build())
.build();
Common Base Properties
All ActionConfig classes inherit these properties from the base class:
pauseBeforeBegin
- Delay before starting the actionpauseAfterEnd
- Delay after completing the actionillustrate
- Whether to create visual feedbacksuccessCriteria
- Custom success validationsubsequentActions
- Chained actions to execute
Getting Started
To start using ActionConfig:
- Choose the appropriate Options class for your action
- Use the builder to configure it
- Pass it to the
action.perform()
method - Process the
ActionResult
Example:
// Find and click a button
ActionResult result = action.perform(
new PatternFindOptions.Builder()
.setSimilarity(0.85)
.then(new ClickOptions.Builder()
.setNumberOfClicks(1)
.build())
.build(),
buttonImage
);
if (result.isSuccess()) {
System.out.println("Button clicked successfully!");
}
Next Steps
- Quick Migration Reference - Learn how to migrate from ActionOptions
- Code Examples - See ActionConfig in action
- Fluent API Guide - Master the fluent API patterns
- API Reference - Detailed API documentation