|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.fest.swing.core.BasicComponentFinder
public final class BasicComponentFinder
Understands GUI
lookup.
Component
Constructor Summary | |
---|---|
protected |
BasicComponentFinder(ComponentHierarchy hierarchy)
Creates a new . |
protected |
BasicComponentFinder(ComponentHierarchy hierarchy,
Settings settings)
Creates a new . |
Method Summary | ||
---|---|---|
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. |
|
|
find(Container root,
GenericTypeMatcher<T> m)
Finds a using the given in the hierarchy
under the given root. |
|
|
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 . |
|
|
findAll(Container root,
GenericTypeMatcher<T> m)
Returns all the s under the given root that match the search criteria specified in
the given . |
|
|
findAll(GenericTypeMatcher<T> m)
Returns all the s that match the search criteria specified in the given
. |
|
Component |
findByLabel(Container root,
String label)
Finds a by the text of its associated , in the hierarchy
under the given root. |
|
Component |
findByLabel(Container root,
String label,
boolean showing)
Finds a by the text of its associated , in the hierarchy
under the given root. |
|
|
findByLabel(Container root,
String label,
Class<T> type)
Finds a by the text of its associated and type, in the
hierarchy under the given root. |
|
|
findByLabel(Container root,
String label,
Class<T> type,
boolean showing)
Finds a by the text of its associated and type, in the
hierarchy under the given root. |
|
Component |
findByLabel(String label)
Finds a by by the text of its associated . |
|
Component |
findByLabel(String label,
boolean showing)
Finds a by by the text of its associated . |
|
|
findByLabel(String label,
Class<T> type)
Finds a by the text of its associated and type. |
|
|
findByLabel(String label,
Class<T> type,
boolean showing)
Finds a by the text of its associated and type. |
|
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. |
|
|
findByName(Container root,
String name,
Class<T> type)
Finds a by name and type, in the hierarchy under the given root. |
|
|
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. |
|
|
findByName(String name,
Class<T> type)
Finds a by name and type. |
|
|
findByName(String name,
Class<T> type,
boolean showing)
Finds a by name and type. |
|
|
findByType(Class<T> type)
Finds a by type. |
|
|
findByType(Class<T> type,
boolean showing)
Finds a by type. |
|
|
findByType(Container root,
Class<T> type)
Finds a by type in the hierarchy under the given root. |
|
|
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
. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
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
.Method Detail |
---|
public static ComponentFinder finderWithNewAwtHierarchy()
BasicComponentFinder
with a new AWT hierarchy. Component
s
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 ComponentFinder
ComponentPrinter
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 ComponentFinder
T
- 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 ComponentFinder
T
- 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 Robot
Robot
's
to determine whether the component to find should be showing or not. If this finder
is not attached to any Settings
Robot
, 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 ComponentFinder
T
- 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 ComponentFinder
T
- 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 ComponentFinder
T
- 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 ComponentFinder
T
- 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 Robot
Robot
's
to determine whether
the component to find should be showing or not. If this finder is not attached to any Settings
Robot
,
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:
ComponentFinder.findByName(String, Class)
ComponentFinder.findByName(String, Class, boolean)
ComponentFinder.findByName(Container, String, Class)
ComponentFinder.findByName(Container, String, Class, boolean)
findByName
in interface ComponentFinder
name
- 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 ComponentFinder
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(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 ComponentFinder
T
- 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)
Component
by the text of its associated JLabel
and type.
findByLabel
in interface ComponentFinder
T
- 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 Robot
Robot
's
to determine whether the component to find should be showing or not. If this finder
is not attached to any Settings
Robot
, 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
JTextField
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:
ComponentFinder.findByLabel(String, Class)
ComponentFinder.findByLabel(String, Class, boolean)
ComponentFinder.findByLabel(Container, String, Class)
ComponentFinder.findByLabel(Container, String, Class, boolean)
findByLabel
in interface ComponentFinder
label
- 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)
Component
by by the text of its associated JLabel
.
findByLabel
in interface ComponentFinder
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(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 ComponentFinder
T
- 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 ComponentFinder
m
- 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 ComponentFinder
T
- 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 ComponentFinder
T
- 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 ComponentFinder
root
- 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 ComponentFinder
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.
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 ComponentFinder
T
- 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 ComponentFinder
T
- 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 ComponentFinder
root
- 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)
Component
by the text of its associated JLabel
, in the hierarchy
under the given root.
findByLabel
in interface ComponentFinder
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.
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 ComponentFinder
T
- 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 ComponentFinder
root
- 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 ComponentFinder
true
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 ComponentFinder
newValue
- the new value to set.public Collection<Component> findAll(ComponentMatcher m)
Component
s that match the search criteria specified in the given
ComponentMatcher
.
findAll
in interface ComponentFinder
m
- the matcher to use to find the component.
Component
s 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)
Component
s under the given root that match the search criteria specified in
the given ComponentMatcher
.
findAll
in interface ComponentFinder
root
- the root used as the starting point of the search.m
- the matcher to use to find the component.
Component
s 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)
Component
s that match the search criteria specified in the given
GenericTypeMatcher
.
findAll
in interface ComponentFinder
T
- the generic type of component that this search supports.m
- the matcher to use to find the component.
Component
s 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)
Component
s under the given root that match the search criteria specified in
the given GenericTypeMatcher
.
findAll
in interface ComponentFinder
T
- 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.
Component
s 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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |