org.fest.swing.fixture
Class GenericComponentFixture<T extends Component>

java.lang.Object
  extended by org.fest.swing.fixture.ComponentFixture<T>
      extended by org.fest.swing.fixture.GenericComponentFixture<T>
Type Parameters:
T - the type of Component 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();
   }
 }

 

Author:
Simeon H.K. Fitch

Field Summary
 
Fields inherited from class org.fest.swing.fixture.ComponentFixture
BACKGROUND_PROPERTY, FONT_PROPERTY, FOREGROUND_PROPERTY, robot, target
 
Constructor Summary
GenericComponentFixture(Robot robot, ComponentDriver driver, T target)
          Creates a new GenericComponentFixture using a provided driver.
GenericComponentFixture(Robot robot, T target)
          Creates a new GenericComponentFixture.
 
Method Summary
 GenericComponentFixture<T> click()
          Simulates a user clicking this fixture's GUI component.
 GenericComponentFixture<T> click(MouseButton button)
          Simulates a user clicking this fixture's GUI component.
 GenericComponentFixture<T> click(MouseClickInfo mouseClickInfo)
          Simulates a user clicking this fixture's GUI component.
 GenericComponentFixture<T> doubleClick()
          Simulates a user double-clicking this fixture's GUI component.
protected  ComponentDriver driver()
          Returns the ComponentDriver used by this fixture.
protected  void driver(ComponentDriver newDriver)
          Sets the ComponentDriver to be used by this fixture.
 GenericComponentFixture<T> focus()
          Gives input focus to this fixture's GUI component.
 GenericComponentFixture<T> pressAndReleaseKey(KeyPressInfo keyPressInfo)
          Simulates a user pressing given key with the given modifiers on this fixture's GUI component.
 GenericComponentFixture<T> pressAndReleaseKeys(int... keyCodes)
          Simulates a user pressing and releasing the given keys on this fixture's GUI component.
 GenericComponentFixture<T> pressKey(int keyCode)
          Simulates a user pressing given key on this fixture's GUI component.
 GenericComponentFixture<T> releaseKey(int keyCode)
          Simulates a user releasing the given key on this fixture's GUI component.
 GenericComponentFixture<T> requireDisabled()
          Asserts that this fixture's GUI component is disabled.
 GenericComponentFixture<T> requireEnabled()
          Asserts that this fixture's GUI component is enabled.
 GenericComponentFixture<T> requireEnabled(Timeout timeout)
          Asserts that this fixture's GUI component is enabled.
 GenericComponentFixture<T> requireFocused()
          Asserts that this fixture's GUI component has input focus.
 GenericComponentFixture<T> requireNotVisible()
          Asserts that this fixture's GUI component is not visible.
 GenericComponentFixture<T> requireVisible()
          Asserts that this fixture's GUI component is visible.
 GenericComponentFixture<T> rightClick()
          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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericComponentFixture

public GenericComponentFixture(Robot robot,
                               T target)
Creates a new GenericComponentFixture.

Parameters:
robot - performs simulation of user events on the given target component.
target - the target Component to be managed by this fixture.
Throws:
NullPointerException - if robot is null.
NullPointerException - if target is null.

GenericComponentFixture

public GenericComponentFixture(Robot robot,
                               ComponentDriver driver,
                               T target)
Creates a new GenericComponentFixture using a provided driver.

Parameters:
robot - performs simulation of user events on the given target component.
driver - provided driver to handle input requests.
target - the target Component to be managed by this fixture.
Throws:
NullPointerException - if robot is null.
NullPointerException - if driver is null.
NullPointerException - if target is null.
Method Detail

driver

protected final void driver(ComponentDriver newDriver)
Sets the ComponentDriver to be used by this fixture.

Parameters:
newDriver - the new ComponentDriver.
Throws:
NullPointerException - if the given driver is null.

driver

protected final ComponentDriver driver()
Returns the ComponentDriver used by this fixture.

Returns:
the driver used by this fixture.

click

public GenericComponentFixture<T> click()
Simulates a user clicking this fixture's GUI component.

Specified by:
click in interface MouseInputSimulationFixture
Returns:
this fixture.

click

public GenericComponentFixture<T> click(MouseButton button)
Simulates a user clicking this fixture's GUI component.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
button - the button to click.
Returns:
this fixture.

click

public GenericComponentFixture<T> click(MouseClickInfo mouseClickInfo)
Simulates a user clicking this fixture's GUI component.

Specified by:
click in interface MouseInputSimulationFixture
Parameters:
mouseClickInfo - specifies the button to click and the times the button should be clicked.
Returns:
this fixture.

doubleClick

public GenericComponentFixture<T> doubleClick()
Simulates a user double-clicking this fixture's GUI component.

Specified by:
doubleClick in interface MouseInputSimulationFixture
Returns:
this fixture.

rightClick

public GenericComponentFixture<T> rightClick()
Simulates a user right-clicking this fixture's GUI component.

Specified by:
rightClick in interface MouseInputSimulationFixture
Returns:
this fixture.

focus

public GenericComponentFixture<T> focus()
Gives input focus to this fixture's GUI component.

Specified by:
focus in interface FocusableComponentFixture
Returns:
this fixture.

pressAndReleaseKey

public GenericComponentFixture<T> pressAndReleaseKey(KeyPressInfo keyPressInfo)
Simulates a user pressing given key with the given modifiers on this fixture's GUI component. Modifiers is a mask from the available InputEvent masks.

The following code listing shows how to press 'CTRL' + 'C' in a platform-safe way:

 JTextComponentFixture textBox = dialog.textBox("username");
 textBox.selectAll()
        .pressAndReleaseKey(key(VK_C).modifiers(controlOrCommandMask()));
 

Specified by:
pressAndReleaseKey in interface KeyboardInputSimulationFixture
Parameters:
keyPressInfo - specifies the key and modifiers to press.
Returns:
this fixture.

pressAndReleaseKeys

public GenericComponentFixture<T> pressAndReleaseKeys(int... keyCodes)
Simulates a user pressing and releasing the given keys on this fixture's GUI component.

Specified by:
pressAndReleaseKeys in interface KeyboardInputSimulationFixture
Parameters:
keyCodes - one or more codes of the keys to press.
Returns:
this fixture.
See Also:
KeyEvent

pressKey

public GenericComponentFixture<T> pressKey(int keyCode)
Simulates a user pressing given key on this fixture's GUI component.

Specified by:
pressKey in interface KeyboardInputSimulationFixture
Parameters:
keyCode - the code of the key to press.
Returns:
this fixture.
See Also:
KeyEvent

releaseKey

public GenericComponentFixture<T> releaseKey(int keyCode)
Simulates a user releasing the given key on this fixture's GUI component.

Specified by:
releaseKey in interface KeyboardInputSimulationFixture
Parameters:
keyCode - the code of the key to release.
Returns:
this fixture.
See Also:
KeyEvent

requireEnabled

public GenericComponentFixture<T> requireEnabled()
Asserts that this fixture's GUI component is enabled.

Specified by:
requireEnabled in interface StateVerificationFixture
Returns:
this fixture.

requireEnabled

public GenericComponentFixture<T> requireEnabled(Timeout timeout)
Asserts that this fixture's GUI component is enabled.

Specified by:
requireEnabled in interface StateVerificationFixture
Parameters:
timeout - the time this fixture will wait for the component to be enabled.
Returns:
this fixture.

requireDisabled

public GenericComponentFixture<T> requireDisabled()
Asserts that this fixture's GUI component is disabled.

Specified by:
requireDisabled in interface StateVerificationFixture
Returns:
this fixture.

requireVisible

public GenericComponentFixture<T> requireVisible()
Asserts that this fixture's GUI component is visible.

Specified by:
requireVisible in interface StateVerificationFixture
Returns:
this fixture.

requireNotVisible

public GenericComponentFixture<T> requireNotVisible()
Asserts that this fixture's GUI component is not visible.

Specified by:
requireNotVisible in interface StateVerificationFixture
Returns:
this fixture.

requireFocused

public GenericComponentFixture<T> requireFocused()
Asserts that this fixture's GUI component has input focus.

Specified by:
requireFocused in interface FocusableComponentFixture
Returns:
this fixture.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.