org.fest.swing.finder
Class JFileChooserFinder

java.lang.Object
  extended by org.fest.swing.finder.ComponentFinderTemplate<JFileChooser>
      extended by org.fest.swing.finder.JFileChooserFinder

public class JFileChooserFinder
extends ComponentFinderTemplate<JFileChooser>

Understands a finder for JFileChoosers. 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 JFileChooser by name, using the default lookup time (5 seconds):

 JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser().using(robot);
 

Where robot is an instance of Robot.

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

 JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser().withTimeout(10000).using(robot);
 
We can also specify the time unit:
 JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser().withTimeout(10, SECONDS).using(robot);
 

This examples shows how to find a JFileChooser using a GenericTypeMatcher:

 GenericTypeMatcher<JFileChooser> matcher = new GenericTypeMatcher<JFileChooser>() {
   protected boolean isMatching(JFileChooser fileChooser) {
     return fileChooser.getCurrentDirectory().getAbsolutePath().equals("c:\\temp");
   }
 };
 JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser(matcher).using(robot);
 

Author:
Alex Ruiz

Constructor Summary
protected JFileChooserFinder()
          Creates a new JFileChooserFinder.
protected JFileChooserFinder(GenericTypeMatcher<? extends JFileChooser> matcher)
          Creates a new JFileChooserFinder.
protected JFileChooserFinder(String name)
          Creates a new JFileChooserFinder.
 
Method Summary
protected  JFileChooser cast(Component c)
          Casts the given Component to JFileChooser.
static JFileChooserFinder findFileChooser()
          Creates a new JFileChooserFinder capable of looking up a JFileChooser.
static JFileChooserFinder findFileChooser(GenericTypeMatcher<? extends JFileChooser> matcher)
          Creates a new JFileChooserFinder capable of looking up a JFileChooser using the given matcher.
static JFileChooserFinder findFileChooser(String name)
          Creates a new JFileChooserFinder capable of looking up a JFileChooser by name.
 JFileChooserFixture using(Robot robot)
          Finds a JFileChooser by name or type.
 JFileChooserFinder withTimeout(long timeout)
          Sets the timeout for this finder.
 JFileChooserFinder 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

JFileChooserFinder

protected JFileChooserFinder()
Creates a new JFileChooserFinder. This finder looks up a JFileChooser by type.


JFileChooserFinder

protected JFileChooserFinder(String name)
Creates a new JFileChooserFinder.

Parameters:
name - the name of the FileChooser to look for.

JFileChooserFinder

protected JFileChooserFinder(GenericTypeMatcher<? extends JFileChooser> matcher)
Creates a new JFileChooserFinder.

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

findFileChooser

public static JFileChooserFinder findFileChooser()
Creates a new JFileChooserFinder capable of looking up a JFileChooser.

Returns:
the created finder.

findFileChooser

public static JFileChooserFinder findFileChooser(String name)
Creates a new JFileChooserFinder capable of looking up a JFileChooser by name.

Parameters:
name - the name of the file chooser to find.
Returns:
the created finder.

findFileChooser

public static JFileChooserFinder findFileChooser(GenericTypeMatcher<? extends JFileChooser> matcher)
Creates a new JFileChooserFinder capable of looking up a JFileChooser using the given matcher.

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

using

public JFileChooserFixture using(Robot robot)
Finds a JFileChooser by name or type.

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

withTimeout

public JFileChooserFinder withTimeout(long timeout)
Sets the timeout for this finder. The JFileChooser to find should be found within the given time period.

Overrides:
withTimeout in class ComponentFinderTemplate<JFileChooser>
Parameters:
timeout - the number of milliseconds before stopping the search.
Returns:
this finder.
Throws:
IllegalArgumentException - if the timeout is a negative number.

withTimeout

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

Overrides:
withTimeout in class ComponentFinderTemplate<JFileChooser>
Parameters:
timeout - the period of time the search should be performed.
unit - the time unit for timeout.
Returns:
this finder.
Throws:
NullPointerException - if the time unit is null.
IllegalArgumentException - if the timeout is a negative number.

cast

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

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


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