Package org.fest.swing.fixture
Class GenericComponentFixture<T extends Component>
java.lang.Object
org.fest.swing.fixture.ComponentFixture<T>
org.fest.swing.fixture.GenericComponentFixture<T>
- Type Parameters:
T
- the type ofComponent
that this fixture can manage.
- All Implemented Interfaces:
CommonComponentFixture
,FocusableComponentFixture
,KeyboardInputSimulationFixture
,MouseInputSimulationFixture
,StateVerificationFixture
public abstract class GenericComponentFixture<T extends Component>
extends ComponentFixture<T>
implements CommonComponentFixture
A generic component fixture providing basic keyboard and mouse input operations. Useful as a base class for
specialized fixtures providing higher level input operations for custom components.
Example:
public class MyWidget extends JComponent { ... public void paintComponent(Graphics g) { ... } ... } public class MyWidgetFixture extends GenericComponentFixture<MyWidget> { public MyWidgetFixture(Robot robot, MyWidget target) { super(robot, target); } public void clickAndDrag(Point start, Point end) { robot.pressMouse(target, start); robot.moveMouse(target, end); robot.releaseAllMouseButtons(); } }
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ComponentDriver
Delegate for constructing and passing input operations to Robot.Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
-
Constructor Summary
ConstructorsConstructorDescriptionGenericComponentFixture
(Robot robot, ComponentDriver driver, T target) Creates a new
using a provided driver.GenericComponentFixture
GenericComponentFixture
(Robot robot, T target) Creates a new
.GenericComponentFixture
-
Method Summary
Modifier and TypeMethodDescriptionclick()
Simulates a user clicking this fixture's GUI component.click
(MouseButton button) Simulates a user clicking this fixture's GUI component.click
(MouseClickInfo mouseClickInfo) Simulates a user clicking this fixture's GUI component.Simulates a user double-clicking this fixture's GUI component.protected final ComponentDriver
driver()
Returns the
used by this fixture.ComponentDriver
protected final void
driver
(ComponentDriver newDriver) Sets the
to be used by this fixture.ComponentDriver
focus()
Gives input focus to this fixture's GUI component.pressAndReleaseKey
(KeyPressInfo keyPressInfo) Simulates a user pressing given key with the given modifiers on this fixture's GUI component.pressAndReleaseKeys
(int... keyCodes) Simulates a user pressing and releasing the given keys on this fixture's GUI component.pressKey
(int keyCode) Simulates a user pressing given key on this fixture's GUI component.releaseKey
(int keyCode) Simulates a user releasing the given key on this fixture's GUI component.Asserts that this fixture's GUI component is disabled.Asserts that this fixture's GUI component is enabled.requireEnabled
(Timeout timeout) Asserts that this fixture's GUI component is enabled.Asserts that this fixture's GUI component has input focus.Asserts that this fixture's GUI component is not visible.Asserts that this fixture's GUI component is visible.Simulates a user right-clicking this fixture's GUI component.Methods inherited from class org.fest.swing.fixture.ComponentFixture
background, component, font, foreground, requireShowing, targetCastedTo, validateNotNull
-
Field Details
-
driver
Delegate for constructing and passing input operations to Robot.
-
-
Constructor Details
-
GenericComponentFixture
Creates a new
.GenericComponentFixture
- Parameters:
robot
- performs simulation of user events on the given target component.target
- the targetComponent
to be managed by this fixture.- Throws:
NullPointerException
- ifrobot
isnull
.NullPointerException
- iftarget
isnull
.
-
GenericComponentFixture
Creates a new
using a provided driver.GenericComponentFixture
- Parameters:
robot
- performs simulation of user events on the given target component.driver
- provided driver to handle input requests.target
- the targetComponent
to be managed by this fixture.- Throws:
NullPointerException
- ifrobot
isnull
.NullPointerException
- ifdriver
isnull
.NullPointerException
- iftarget
isnull
.
-
-
Method Details
-
driver
Sets the
to be used by this fixture.ComponentDriver
- Parameters:
newDriver
- the newComponentDriver
.- Throws:
NullPointerException
- if the given driver isnull
.
-
driver
Returns the
used by this fixture.ComponentDriver
- Returns:
- the driver used by this fixture.
-
click
Simulates a user clicking this fixture's GUI component.- Specified by:
click
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
-
click
Simulates a user clicking this fixture's GUI component.- Specified by:
click
in interfaceMouseInputSimulationFixture
- Parameters:
button
- the button to click.- Returns:
- this fixture.
-
click
Simulates a user clicking this fixture's GUI component.- Specified by:
click
in interfaceMouseInputSimulationFixture
- Parameters:
mouseClickInfo
- specifies the button to click and the times the button should be clicked.- Returns:
- this fixture.
-
doubleClick
Simulates a user double-clicking this fixture's GUI component.- Specified by:
doubleClick
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
-
rightClick
Simulates a user right-clicking this fixture's GUI component.- Specified by:
rightClick
in interfaceMouseInputSimulationFixture
- Returns:
- this fixture.
-
focus
Gives input focus to this fixture's GUI component.- Specified by:
focus
in interfaceFocusableComponentFixture
- Returns:
- this fixture.
-
pressAndReleaseKey
Simulates a user pressing given key with the given modifiers on this fixture's GUI component. Modifiers is a mask from the available
masks.InputEvent
The following code listing shows how to press 'CTRL' + 'C' in a platform-safe way:
JTextComponentFixture textBox = dialog.textBox("username"); textBox.selectAll() .pressAndReleaseKey(key(
).modifiers(VK_C
controlOrCommandMask
()));- Specified by:
pressAndReleaseKey
in interfaceKeyboardInputSimulationFixture
- Parameters:
keyPressInfo
- specifies the key and modifiers to press.- Returns:
- this fixture.
-
pressAndReleaseKeys
Simulates a user pressing and releasing the given keys on this fixture's GUI component.- Specified by:
pressAndReleaseKeys
in interfaceKeyboardInputSimulationFixture
- Parameters:
keyCodes
- one or more codes of the keys to press.- Returns:
- this fixture.
- See Also:
-
pressKey
Simulates a user pressing given key on this fixture's GUI component.- Specified by:
pressKey
in interfaceKeyboardInputSimulationFixture
- Parameters:
keyCode
- the code of the key to press.- Returns:
- this fixture.
- See Also:
-
releaseKey
Simulates a user releasing the given key on this fixture's GUI component.- Specified by:
releaseKey
in interfaceKeyboardInputSimulationFixture
- Parameters:
keyCode
- the code of the key to release.- Returns:
- this fixture.
- See Also:
-
requireEnabled
Asserts that this fixture's GUI component is enabled.- Specified by:
requireEnabled
in interfaceStateVerificationFixture
- Returns:
- this fixture.
-
requireEnabled
Asserts that this fixture's GUI component is enabled.- Specified by:
requireEnabled
in interfaceStateVerificationFixture
- Parameters:
timeout
- the time this fixture will wait for the component to be enabled.- Returns:
- this fixture.
-
requireDisabled
Asserts that this fixture's GUI component is disabled.- Specified by:
requireDisabled
in interfaceStateVerificationFixture
- Returns:
- this fixture.
-
requireVisible
Asserts that this fixture's GUI component is visible.- Specified by:
requireVisible
in interfaceStateVerificationFixture
- Returns:
- this fixture.
-
requireNotVisible
Asserts that this fixture's GUI component is not visible.- Specified by:
requireNotVisible
in interfaceStateVerificationFixture
- Returns:
- this fixture.
-
requireFocused
Asserts that this fixture's GUI component has input focus.- Specified by:
requireFocused
in interfaceFocusableComponentFixture
- Returns:
- this fixture.
-