public final class BasicComponentFinder extends Object implements ComponentFinder
Component lookup.| Modifier | Constructor and Description |
|---|---|
protected |
BasicComponentFinder(ComponentHierarchy hierarchy)
Creates a new
. |
protected |
BasicComponentFinder(ComponentHierarchy hierarchy,
Settings settings)
Creates a new
. |
| Modifier and Type | Method and Description |
|---|---|
Component |
find(ComponentMatcher m)
Finds a
using the given . |
Component |
find(Container root,
ComponentMatcher m)
Finds a
using the given in the hierarchy
under the given root. |
<T extends Component> |
find(Container root,
GenericTypeMatcher<T> m)
Finds a
using the given in the hierarchy
under the given root. |
<T extends Component> |
find(GenericTypeMatcher<T> m)
Finds a
using the given . |
Collection<Component> |
findAll(ComponentMatcher m)
Returns all the
s that match the search criteria specified in the given
. |
Collection<Component> |
findAll(Container root,
ComponentMatcher m)
Returns all the
s under the given root that match the search criteria specified in
the given . |
<T extends Component> |
findAll(Container root,
GenericTypeMatcher<T> m)
Returns all the
s under the given root that match the search criteria specified in
the given . |
<T extends Component> |
findAll(GenericTypeMatcher<T> m)
Returns all the
s that match the search criteria specified in the given
. |
Component |
findByLabel(Container root,
String label)
|
Component |
findByLabel(Container root,
String label,
boolean showing)
|
<T extends Component> |
findByLabel(Container root,
String label,
Class<T> type)
|
<T extends Component> |
findByLabel(Container root,
String label,
Class<T> type,
boolean showing)
|
Component |
findByLabel(String label)
|
Component |
findByLabel(String label,
boolean showing)
|
<T extends Component> |
findByLabel(String label,
Class<T> type)
|
<T extends Component> |
findByLabel(String label,
Class<T> type,
boolean showing)
|
Component |
findByName(Container root,
String name)
Finds a
by name, in the hierarchy under the given root. |
Component |
findByName(Container root,
String name,
boolean showing)
Finds a
by name, in the hierarchy under the given root. |
<T extends Component> |
findByName(Container root,
String name,
Class<T> type)
Finds a
by name and type, in the hierarchy under the given root. |
<T extends Component> |
findByName(Container root,
String name,
Class<T> type,
boolean showing)
Finds a
by name and type, in the hierarchy under the given root. |
Component |
findByName(String name)
Finds a
by name. |
Component |
findByName(String name,
boolean showing)
Finds a
by name. |
<T extends Component> |
findByName(String name,
Class<T> type)
Finds a
by name and type. |
<T extends Component> |
findByName(String name,
Class<T> type,
boolean showing)
Finds a
by name and type. |
<T extends Component> |
findByType(Class<T> type)
Finds a
by type. |
<T extends Component> |
findByType(Class<T> type,
boolean showing)
Finds a
by type. |
<T extends Component> |
findByType(Container root,
Class<T> type)
Finds a
by type in the hierarchy under the given root. |
<T extends Component> |
findByType(Container root,
Class<T> type,
boolean showing)
Finds a
by type in the hierarchy under the given root. |
static ComponentFinder |
finderWithCurrentAwtHierarchy()
Creates a new
that has access to all the GUI components in the AWT
hierarchy. |
static ComponentFinder |
finderWithNewAwtHierarchy()
Creates a new
with a new AWT hierarchy. |
boolean |
includeHierarchyIfComponentNotFound()
Returns whether the message in a
should include the current component
hierarchy. |
void |
includeHierarchyIfComponentNotFound(boolean newValue)
Updates whether the message in a
should include the current component
hierarchy. |
ComponentPrinter |
printer()
Returns the
in this finder. |
protected boolean |
requireShowingFromSettingsOr(boolean defaultValue)
Returns the value of the flag "requireShowing" in the
this finder's
. |
protected BasicComponentFinder(ComponentHierarchy hierarchy)
BasicComponentFinder. The created finder does not use any
Settings.hierarchy - the component hierarchy to use.protected BasicComponentFinder(ComponentHierarchy hierarchy, Settings settings)
BasicComponentFinder.hierarchy - the component hierarchy to use.settings - the configuration settings to use. It can be null.public static ComponentFinder finderWithNewAwtHierarchy()
BasicComponentFinder with a new AWT hierarchy. Components
created before the created BasicComponentFinder cannot be accessed by the created
BasicComponentFinder.public static ComponentFinder finderWithCurrentAwtHierarchy()
BasicComponentFinder that has access to all the GUI components in the AWT
hierarchy.public ComponentPrinter printer()
ComponentPrinter in this finder.printer in interface ComponentFinderComponentPrinter in this finder.public <T extends Component> T findByType(Class<T> type)
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);
findByType in interface ComponentFinderT - the parameterized type of the component to find.type - the type of the component to find.Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope@RunsInEDT public <T extends Component> T findByType(Class<T> type, boolean showing)
Component by type. For example:findByType in interface ComponentFinderT - the parameterized type 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.ComponentFinder.findByType(Class)@RunsInEDT public <T extends Component> T findByType(Container root, Class<T> type)
Finds a by type in the hierarchy under the given root. If this finder is attached to
a Component, it will use the component lookup scope in the RobotRobot's
to determine whether the component to find should be showing or not. If this finder
is not attached to any SettingsRobot, the component to find does not have to be showing.
Let's assume we have the following containing a
JFrame:
JTextField
JFrame myFrame = new JFrame(); myFrame.add(new JTextField());
If we want to get a reference to the in that particular
JTextField without going through the whole AWT component hierarchy, we could simply
specify:
JFrame
JTextField textbox = finder.findByType(myFrame, JTextField.class);
findByType in interface ComponentFinderT - the parameterized type of the component to find.root - the root used as the starting point of the search.type - the type of the component to find.Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope@RunsInEDT public <T extends Component> T findByType(Container root, Class<T> type, boolean showing)
Component by type in the hierarchy under the given root.findByType in interface ComponentFinderT - the parameterized type of the component to find.root - the root used as the starting point of the search.type - the type of the component to find.showing - indicates whether the component to find should be visible (or showing) or not.ComponentFinder.findByType(Container, Class)@RunsInEDT public <T extends Component> T findByName(String name, Class<T> type)
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.findByName in interface ComponentFinderT - the parameterized type of the component to find.name - the name of the component to find.type - the type of the component to find.Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope,
ComponentFinder.findByName(String)@RunsInEDT public <T extends Component> T findByName(String name, Class<T> type, boolean showing)
Component by name and type.findByName in interface ComponentFinderT - the parameterized type of the component to find.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.ComponentFinder.findByName(String)@RunsInEDT public Component findByName(String name)
Finds a by name. If this finder is attached to a Component, it
will use the component lookup scope in the RobotRobot's to determine whether
the component to find should be showing or not. If this finder is not attached to any SettingsRobot,
the component to find does not have to be showing.
Let's assume we have the with name "myTextBox";
JTextField
JTextField textbox = new JTextField();
textBox.setName("myTextBox");
To get a reference to this by its name, we can specify:
JTextField
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:
findByName in interface ComponentFindername - the name of the component to find.Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope@RunsInEDT public Component findByName(String name, boolean showing)
Component by name.findByName in interface ComponentFindername - the name of the component to find.showing - indicates whether the component to find should be visible (or showing) or not.ComponentFinder.findByName(String)@RunsInEDT public <T extends Component> T findByLabel(String label, Class<T> type)
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.findByLabel in interface ComponentFinderT - the parameterized type of the component to find.label - the text of the JLabel associated to the component to find.type - the type of the component to find.ComponentFinder.findByLabel(String),
JLabel.getLabelFor(),
JLabel.setLabelFor(Component),
Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope@RunsInEDT public <T extends Component> T findByLabel(String label, Class<T> type, boolean showing)
findByLabel in interface ComponentFinderT - the parameterized type of the component to find.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.ComponentFinder.findByLabel(String),
JLabel.getLabelFor(),
JLabel.setLabelFor(Component)@RunsInEDT public Component findByLabel(String label)
Finds a by by the text of its associated Component. If this finder
is attached to a JLabel, it will use the component lookup scope in the RobotRobot's
to determine whether the component to find should be showing or not. If this finder
is not attached to any SettingsRobot, the component to find does not have to be showing.
Let's assume we have the with a JTextField with text
"Name";
JLabel
JLabel label = new JLabel("Name");
JTextField textbox = new JTextField();
label.setLabelFor(textBox);
To get a reference to this by the text of its associated
JTextFieldJLabel, 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:
findByLabel in interface ComponentFinderlabel - the text of the JLabel associated to the component to find.JLabel.getLabelFor(),
JLabel.setLabelFor(Component),
Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope@RunsInEDT public Component findByLabel(String label, boolean showing)
findByLabel in interface ComponentFinderlabel - 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.ComponentFinder.findByLabel(String),
JLabel.getLabelFor(),
JLabel.setLabelFor(Component)@RunsInEDT public <T extends Component> T find(GenericTypeMatcher<T> m)
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.find in interface ComponentFinderT - the type of component the given matcher can handle.m - the matcher to use to find the component of interest.@RunsInEDT public Component find(ComponentMatcher m)
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.find in interface ComponentFinderm - the matcher to use to find the component of interest.@RunsInEDT public <T extends Component> T findByName(Container root, String name, Class<T> type)
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.findByName in interface ComponentFinderT - the parameterized type of the component to find.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.Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope,
ComponentFinder.findByName(String)@RunsInEDT public <T extends Component> T findByName(Container root, String name, Class<T> type, boolean showing)
Component by name and type, in the hierarchy under the given root.findByName in interface ComponentFinderT - the parameterized type of the component to find.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.ComponentFinder.findByName(String)@RunsInEDT public Component findByName(Container root, String name)
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.findByName in interface ComponentFinderroot - the root used as the starting point of the search.name - the name of the component to find.Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope,
ComponentFinder.findByName(String)@RunsInEDT public Component findByName(Container root, String name, boolean showing)
Component by name, in the hierarchy under the given root.findByName in interface ComponentFinderroot - 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.ComponentFinder.findByName(String)@RunsInEDT public <T extends Component> T findByLabel(Container root, String label, Class<T> type)
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.findByLabel in interface ComponentFinderT - the parameterized type of the component to find.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.ComponentFinder.findByLabel(String),
JLabel.getLabelFor(),
JLabel.setLabelFor(Component),
Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope@RunsInEDT public <T extends Component> T findByLabel(Container root, String label, Class<T> type, boolean showing)
Component by the text of its associated JLabel and type, in the
hierarchy under the given root.findByLabel in interface ComponentFinderT - the parameterized type of the component to find.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.ComponentFinder.findByLabel(String),
JLabel.getLabelFor(),
JLabel.setLabelFor(Component)@RunsInEDT public Component findByLabel(Container root, String label)
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.findByLabel in interface ComponentFinderroot - the root used as the starting point of the search.label - the text of the JLabel associated to the component to find.ComponentFinder.findByLabel(String),
JLabel.getLabelFor(),
JLabel.setLabelFor(Component),
Robot.settings(),
Settings.componentLookupScope(),
ComponentLookupScope@RunsInEDT public Component findByLabel(Container root, String label, boolean showing)
findByLabel in interface ComponentFinderroot - 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.ComponentFinder.findByLabel(String),
JLabel.getLabelFor(),
JLabel.setLabelFor(Component)@RunsInEDT public <T extends Component> T find(Container root, GenericTypeMatcher<T> m)
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.find in interface ComponentFinderT - the type of component the given matcher can handle.root - the root used as the starting point of the search.m - the matcher to use to find the component.@RunsInEDT public Component find(Container root, ComponentMatcher m)
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.find in interface ComponentFinderroot - the root used as the starting point of the search.m - the matcher to use to find the component.public boolean includeHierarchyIfComponentNotFound()
ComponentLookupException should include the current component
hierarchy. The default value is true.includeHierarchyIfComponentNotFound in interface ComponentFindertrue if the component hierarchy is included as part of the
ComponentLookupException message, false otherwise.public void includeHierarchyIfComponentNotFound(boolean newValue)
ComponentLookupException should include the current component
hierarchy. The default value is true.includeHierarchyIfComponentNotFound in interface ComponentFindernewValue - the new value to set.public Collection<Component> findAll(ComponentMatcher m)
Components that match the search criteria specified in the given
ComponentMatcher.findAll in interface ComponentFinderm - the matcher to use to find the component.Components that match the search criteria specified in the given
ComponentMatcher; or an empty collection, if there are no matching components.public Collection<Component> findAll(Container root, ComponentMatcher m)
Components under the given root that match the search criteria specified in
the given ComponentMatcher.findAll in interface ComponentFinderroot - the root used as the starting point of the search.m - the matcher to use to find the component.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.public <T extends Component> Collection<T> findAll(GenericTypeMatcher<T> m)
Components that match the search criteria specified in the given
GenericTypeMatcher.findAll in interface ComponentFinderT - the generic type of component that this search supports.m - the matcher to use to find the component.Components that match the search criteria specified in the given
GenericTypeMatcher; or an empty collection, if there are no matching components.public <T extends Component> Collection<T> findAll(Container root, GenericTypeMatcher<T> m)
Components under the given root that match the search criteria specified in
the given GenericTypeMatcher.findAll in interface ComponentFinderT - the generic type of component that this search supports.root - the root used as the starting point of the search.m - the matcher to use to find the component.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.protected final boolean requireShowingFromSettingsOr(boolean defaultValue)
ComponentLookupScope this finder's
Settings. If the settings object is null, this method will return the provided
default value.defaultValue - the value to return if this matcher does not have any configuration settings.Copyright © 2007-2012 FEST (Fixtures for Easy Software Testing). All Rights Reserved.