org.fest.swing.finder
Class JOptionPaneFinder

java.lang.Object
  extended by org.fest.swing.finder.ComponentFinderTemplate<JOptionPane>
      extended by org.fest.swing.finder.JOptionPaneFinder

public class JOptionPaneFinder
extends ComponentFinderTemplate<JOptionPane>

Understands a finder for JOptionPanes. Lookups are performed till a file chooser is found, or until the given time to perform the lookup is over. The default lookup time is 5 seconds.

This example illustrates finding a JOptionPane by name, using the default lookup time (5 seconds):

 JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane().using(robot);
 

Where robot is an instance of Robot.

This example shows how to find a JOptionPane by type using a lookup time of 10 seconds:

 JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane().withTimeout(10000).using(robot);
 
We can also specify the time unit:
 JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane().withTimeout(10, SECONDS).using(robot);
 

This example shows how to find a JOptionPane using a GenericTypeMatcher:

 GenericTypeMatcher<JOptionPane> matcher = new GenericTypeMatcher<JOptionPane>() {
   protected boolean isMatching(JOptionPane optionPane) {
     return "A message".equals(optionPane.getMessage());
   }
 };
 JOptionPaneFixture optionPane = JOptionPaneFinder.findOptionPane(matcher).using(robot);
 

Author:
Yvonne Wang, Alex Ruiz

Constructor Summary
protected JOptionPaneFinder()
          Creates a new JOptionPaneFinder.
protected JOptionPaneFinder(GenericTypeMatcher<? extends JOptionPane> matcher)
          Creates a new JOptionPaneFinder.
 
Method Summary
protected  JOptionPane cast(Component c)
          Casts the given Component to JOptionPane.
static JOptionPaneFinder findOptionPane()
          Creates a new JOptionPaneFinder capable of looking up a JOptionPane.
static JOptionPaneFinder findOptionPane(GenericTypeMatcher<? extends JOptionPane> matcher)
          Creates a new JOptionPaneFinder capable of looking up a JOptionPane using the given matcher.
 JOptionPaneFixture using(Robot robot)
          Finds a JOptionPane by name or type.
 JOptionPaneFinder withTimeout(long timeout)
          Sets the timeout for this finder.
 JOptionPaneFinder withTimeout(long timeout, TimeUnit unit)
          Sets the timeout for this finder.
 
Methods inherited from class org.fest.swing.finder.ComponentFinderTemplate
findComponentWith
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JOptionPaneFinder

protected JOptionPaneFinder()
Creates a new JOptionPaneFinder. This finder looks up a JOptionPane by type.


JOptionPaneFinder

protected JOptionPaneFinder(GenericTypeMatcher<? extends JOptionPane> matcher)
Creates a new JOptionPaneFinder.

Parameters:
matcher - specifies the search criteria to use when looking up a JOptionPane.
Method Detail

findOptionPane

public static JOptionPaneFinder findOptionPane()
Creates a new JOptionPaneFinder capable of looking up a JOptionPane.

Returns:
the created finder.

findOptionPane

public static JOptionPaneFinder findOptionPane(GenericTypeMatcher<? extends JOptionPane> matcher)
Creates a new JOptionPaneFinder capable of looking up a JOptionPane using the given matcher.

Parameters:
matcher - the given matcher.
Returns:
the created finder.

using

public JOptionPaneFixture using(Robot robot)
Finds a JOptionPane by name or type.

Specified by:
using in class ComponentFinderTemplate<JOptionPane>
Parameters:
robot - contains the underlying finding to delegate the search to.
Returns:
a JOptionPaneFixture managing the found JOptionPane.
Throws:
WaitTimedOutError - if a JOptionPane could not be found.

withTimeout

public JOptionPaneFinder withTimeout(long timeout)
Sets the timeout for this finder. The window to search should be found within the given time period.

Overrides:
withTimeout in class ComponentFinderTemplate<JOptionPane>
Parameters:
timeout - the number of milliseconds before stopping the search.
Returns:
this finder.

withTimeout

public JOptionPaneFinder withTimeout(long timeout,
                                     TimeUnit unit)
Sets the timeout for this finder. The window to search should be found within the given time period.

Overrides:
withTimeout in class ComponentFinderTemplate<JOptionPane>
Parameters:
timeout - the period of time the search should be performed.
unit - the time unit for timeout.
Returns:
this finder.

cast

protected JOptionPane cast(Component c)
Casts the given Component to JOptionPane.

Specified by:
cast in class ComponentFinderTemplate<JOptionPane>
Parameters:
c - the given Component.
Returns:
the given Component, casted to JFileChooser.


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