org.fest.swing.core
Interface ComponentFinder

All Known Implementing Classes:
BasicComponentFinder

@RunsInEDT
public interface ComponentFinder

Understands GUI Component lookup.

Author:
Alex Ruiz

Method Summary
 Component find(ComponentMatcher m)
          Finds a Component using the given ComponentMatcher.
 Component find(Container root, ComponentMatcher m)
          Finds a Component using the given ComponentMatcher in the hierarchy under the given root.
<T extends Component>
T
find(Container root, GenericTypeMatcher<T> m)
          Finds a Component using the given GenericTypeMatcher in the hierarchy under the given root.
<T extends Component>
T
find(GenericTypeMatcher<T> m)
          Finds a Component using the given GenericTypeMatcher.
 Collection<Component> findAll(ComponentMatcher m)
          Returns all the Components that match the search criteria specified in the given ComponentMatcher.
 Collection<Component> findAll(Container root, ComponentMatcher m)
          Returns all the Components under the given root that match the search criteria specified in the given ComponentMatcher.
<T extends Component>
Collection<T>
findAll(Container root, GenericTypeMatcher<T> m)
          Returns all the Components under the given root that match the search criteria specified in the given GenericTypeMatcher.
<T extends Component>
Collection<T>
findAll(GenericTypeMatcher<T> m)
          Returns all the Components that match the search criteria specified in the given GenericTypeMatcher.
 Component findByLabel(Container root, String label)
          Finds a Component by the text of its associated JLabel, in the hierarchy under the given root.
 Component findByLabel(Container root, String label, boolean showing)
          Finds a Component by the text of its associated JLabel, in the hierarchy under the given root.
<T extends Component>
T
findByLabel(Container root, String label, Class<T> type)
          Finds a Component by the text of its associated JLabel and type, in the hierarchy under the given root.
<T extends Component>
T
findByLabel(Container root, String label, Class<T> type, boolean showing)
          Finds a Component by the text of its associated JLabel and type, in the hierarchy under the given root.
 Component findByLabel(String label)
           Finds a Component by by the text of its associated JLabel.
 Component findByLabel(String label, boolean showing)
          Finds a Component by by the text of its associated JLabel.
<T extends Component>
T
findByLabel(String label, Class<T> type)
          Finds a Component by the text of its associated JLabel and type.
<T extends Component>
T
findByLabel(String label, Class<T> type, boolean showing)
          Finds a Component by the text of its associated JLabel and type.
 Component findByName(Container root, String name)
          Finds a Component by name, in the hierarchy under the given root.
 Component findByName(Container root, String name, boolean showing)
          Finds a Component by name, in the hierarchy under the given root.
<T extends Component>
T
findByName(Container root, String name, Class<T> type)
          Finds a Component by name and type, in the hierarchy under the given root.
<T extends Component>
T
findByName(Container root, String name, Class<T> type, boolean showing)
          Finds a Component by name and type, in the hierarchy under the given root.
 Component findByName(String name)
           Finds a Component by name.
 Component findByName(String name, boolean showing)
          Finds a Component by name.
<T extends Component>
T
findByName(String name, Class<T> type)
          Finds a Component by name and type.
<T extends Component>
T
findByName(String name, Class<T> type, boolean showing)
          Finds a Component by name and type.
<T extends Component>
T
findByType(Class<T> type)
          Finds a Component by type.
<T extends Component>
T
findByType(Class<T> type, boolean showing)
          Finds a Component by type.
<T extends Component>
T
findByType(Container root, Class<T> type)
           Finds a Component by type in the hierarchy under the given root.
<T extends Component>
T
findByType(Container root, Class<T> type, boolean showing)
          Finds a Component by type in the hierarchy under the given root.
 boolean includeHierarchyIfComponentNotFound()
          Returns whether the message in a ComponentLookupException should include the current component hierarchy.
 void includeHierarchyIfComponentNotFound(boolean newValue)
          Updates whether the message in a ComponentLookupException should include the current component hierarchy.
 ComponentPrinter printer()
          Returns the ComponentPrinter in this finder.
 

Method Detail

printer

ComponentPrinter printer()
Returns the ComponentPrinter in this finder.

Returns:
the ComponentPrinter in this finder.

findByType

<T extends Component> T findByType(Class<T> type)
Finds a Component by type. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Example:

 JTextField textbox = finder.findByType(JTextField.class);
 

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
type - the type of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope

findByType

<T extends Component> T findByType(Class<T> type,
                                   boolean showing)
Finds a Component by type. For example:

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
type - the type of the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByType(Class)

findByType

<T extends Component> T findByType(Container root,
                                   Class<T> type)

Finds a Component by type in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Let's assume we have the following JFrame containing a JTextField:

 JFrame myFrame = new JFrame();
 myFrame.add(new JTextField());
 

If we want to get a reference to the JTextField in that particular JFrame without going through the whole AWT component hierarchy, we could simply specify:

 JTextField textbox = finder.findByType(myFrame, JTextField.class);
 

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
root - the root used as the starting point of the search.
type - the type of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope

findByType

<T extends Component> T findByType(Container root,
                                   Class<T> type,
                                   boolean showing)
Finds a Component by type in the hierarchy under the given root.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
root - the root used as the starting point of the search.
showing - indicates whether the component to find should be visible (or showing) or not.
type - the type of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByType(Container, Class)

findByLabel

Component findByLabel(String label)

Finds a Component by by the text of its associated JLabel. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Let's assume we have the JTextField with a JLabel with text "Name";

 JLabel label = new JLabel("Name");
 JTextField textbox = new JTextField();
 label.setLabelFor(textBox);
 

To get a reference to this JTextField by the text of its associated JLabel, we can specify:

 JTextField textBox = (JTextField) finder.findByLabel("Name");
 

Please note that you need to cast the result of the lookup to the right type. To avoid casting, please use one of following:

  1. findByLabel(String, Class)
  2. findByLabel(String, Class, boolean)
  3. findByLabel(Container, String, Class)
  4. findByLabel(Container, String, Class, boolean)

Parameters:
label - the text of the JLabel associated to the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
JLabel.getLabelFor(), JLabel.setLabelFor(Component), Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope

findByLabel

<T extends Component> T findByLabel(String label,
                                    Class<T> type)
Finds a Component by the text of its associated JLabel and type. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
label - the text of the JLabel associated to the component to find.
type - the type of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByLabel(String), JLabel.getLabelFor(), JLabel.setLabelFor(Component), Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope

findByLabel

<T extends Component> T findByLabel(String label,
                                    Class<T> type,
                                    boolean showing)
Finds a Component by the text of its associated JLabel and type.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
label - the text of the JLabel associated to the component to find.
type - the type of the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByLabel(String), JLabel.getLabelFor(), JLabel.setLabelFor(Component)

findByLabel

Component findByLabel(String label,
                      boolean showing)
Finds a Component by by the text of its associated JLabel.

Parameters:
label - the text of the JLabel associated to the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByLabel(String), JLabel.getLabelFor(), JLabel.setLabelFor(Component)

findByLabel

Component findByLabel(Container root,
                      String label)
Finds a Component by the text of its associated JLabel, in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Parameters:
root - the root used as the starting point of the search.
label - the text of the JLabel associated to the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByLabel(String), JLabel.getLabelFor(), JLabel.setLabelFor(Component), Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope

findByLabel

Component findByLabel(Container root,
                      String label,
                      boolean showing)
Finds a Component by the text of its associated JLabel, in the hierarchy under the given root.

Parameters:
root - the root used as the starting point of the search.
label - the text of the JLabel associated to the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByLabel(String), JLabel.getLabelFor(), JLabel.setLabelFor(Component)

findByLabel

<T extends Component> T findByLabel(Container root,
                                    String label,
                                    Class<T> type)
Finds a Component by the text of its associated JLabel and type, in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
root - the root used as the starting point of the search.
label - the text of the JLabel associated to the component to find.
type - the type of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByLabel(String), JLabel.getLabelFor(), JLabel.setLabelFor(Component), Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope

findByLabel

<T extends Component> T findByLabel(Container root,
                                    String label,
                                    Class<T> type,
                                    boolean showing)
Finds a Component by the text of its associated JLabel and type, in the hierarchy under the given root.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
root - the root used as the starting point of the search.
label - the text of the JLabel associated to the component to find.
type - the type of the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByLabel(String), JLabel.getLabelFor(), JLabel.setLabelFor(Component)

findByName

Component findByName(String name)

Finds a Component by name. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Let's assume we have the JTextField with name "myTextBox";

 JTextField textbox = new JTextField();
 textBox.setName("myTextBox");
 

To get a reference to this JTextField by its name, we can specify:

 JTextField textBox = (JTextField) finder.findByName("myTextBox");
 

Please note that you need to cast the result of the lookup to the right type. To avoid casting, please use one of following:

  1. findByName(String, Class)
  2. findByName(String, Class, boolean)
  3. findByName(Container, String, Class)
  4. findByName(Container, String, Class, boolean)

Parameters:
name - the name of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope

findByName

<T extends Component> T findByName(String name,
                                   Class<T> type)
Finds a Component by name and type. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
name - the name of the component to find.
type - the type of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope, findByName(String)

findByName

<T extends Component> T findByName(String name,
                                   Class<T> type,
                                   boolean showing)
Finds a Component by name and type.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
name - the name of the component to find.
type - the type of the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByName(String)

findByName

Component findByName(String name,
                     boolean showing)
Finds a Component by name.

Parameters:
name - the name of the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByName(String)

findByName

Component findByName(Container root,
                     String name)
Finds a Component by name, in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Parameters:
root - the root used as the starting point of the search.
name - the name of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope, findByName(String)

findByName

Component findByName(Container root,
                     String name,
                     boolean showing)
Finds a Component by name, in the hierarchy under the given root.

Parameters:
root - the root used as the starting point of the search.
name - the name of the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByName(String)

findByName

<T extends Component> T findByName(Container root,
                                   String name,
                                   Class<T> type)
Finds a Component by name and type, in the hierarchy under the given root. If this finder is attached to a Robot, it will use the component lookup scope in the Robot's Settings to determine whether the component to find should be showing or not. If this finder is not attached to any Robot, the component to find does not have to be showing.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
root - the root used as the starting point of the search.
name - the name of the component to find.
type - the type of the component to find.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
Robot.settings(), Settings.componentLookupScope(), ComponentLookupScope, findByName(String)

findByName

<T extends Component> T findByName(Container root,
                                   String name,
                                   Class<T> type,
                                   boolean showing)
Finds a Component by name and type, in the hierarchy under the given root.

Type Parameters:
T - the parameterized type of the component to find.
Parameters:
root - the root used as the starting point of the search.
name - the name of the component to find.
type - the type of the component to find.
showing - indicates whether the component to find should be visible (or showing) or not.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.
See Also:
findByName(String)

find

Component find(ComponentMatcher m)
Finds a Component using the given ComponentMatcher. The given matcher will be evaluated in the event dispatch thread. Implementations of ComponentMatcher do not need to be concerned about the event dispatch thread.

Parameters:
m - the matcher to use to find the component of interest.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.

find

<T extends Component> T find(GenericTypeMatcher<T> m)
Finds a Component using the given GenericTypeMatcher. The given matcher will be evaluated in the event dispatch thread. Implementations of GenericTypeMatcher do not need to be concerned about the event dispatch thread.

Type Parameters:
T - the type of component the given matcher can handle.
Parameters:
m - the matcher to use to find the component of interest.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.

find

<T extends Component> T find(Container root,
                             GenericTypeMatcher<T> m)
Finds a Component using the given GenericTypeMatcher in the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations of GenericTypeMatcher do not need to be concerned about the event dispatch thread.

Type Parameters:
T - the type of component the given matcher can handle.
Parameters:
root - the root used as the starting point of the search.
m - the matcher to use to find the component.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.

find

Component find(Container root,
               ComponentMatcher m)
Finds a Component using the given ComponentMatcher in the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations of ComponentMatcher do not need to be concerned about the event dispatch thread.

Parameters:
root - the root used as the starting point of the search.
m - the matcher to use to find the component.
Returns:
the found component.
Throws:
ComponentLookupException - if a matching component could not be found.
ComponentLookupException - if more than one matching component is found.

findAll

Collection<Component> findAll(ComponentMatcher m)
Returns all the Components that match the search criteria specified in the given ComponentMatcher.

Parameters:
m - the matcher to use to find the component.
Returns:
all the Components that match the search criteria specified in the given ComponentMatcher; or an empty collection, if there are no matching components.

findAll

Collection<Component> findAll(Container root,
                              ComponentMatcher m)
Returns all the Components under the given root that match the search criteria specified in the given ComponentMatcher.

Parameters:
root - the root used as the starting point of the search.
m - the matcher to use to find the component.
Returns:
all the Components under the given root that match the search criteria specified in the given ComponentMatcher; or an empty collection, if there are no matching components.

findAll

<T extends Component> Collection<T> findAll(GenericTypeMatcher<T> m)
Returns all the Components that match the search criteria specified in the given GenericTypeMatcher.

Type Parameters:
T - the generic type of component that this search supports.
Parameters:
m - the matcher to use to find the component.
Returns:
all the Components that match the search criteria specified in the given GenericTypeMatcher; or an empty collection, if there are no matching components.

findAll

<T extends Component> Collection<T> findAll(Container root,
                                            GenericTypeMatcher<T> m)
Returns all the Components under the given root that match the search criteria specified in the given GenericTypeMatcher.

Type Parameters:
T - the generic type of component that this search supports.
Parameters:
root - the root used as the starting point of the search.
m - the matcher to use to find the component.
Returns:
all the Components under the given root that match the search criteria specified in the given GenericTypeMatcher; or an empty collection, if there are no matching components.

includeHierarchyIfComponentNotFound

boolean includeHierarchyIfComponentNotFound()
Returns whether the message in a ComponentLookupException should include the current component hierarchy. The default value is true.

Returns:
true if the component hierarchy is included as part of the ComponentLookupException message, false otherwise.

includeHierarchyIfComponentNotFound

void includeHierarchyIfComponentNotFound(boolean newValue)
Updates whether the message in a ComponentLookupException should include the current component hierarchy. The default value is true.

Parameters:
newValue - the new value to set.


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