public final class BasicComponentFinder extends Object implements ComponentFinder
ComponentFinder
.ComponentFinder
Modifier | Constructor and Description |
---|---|
protected |
BasicComponentFinder(ComponentHierarchy hierarchy)
Creates a new
BasicComponentFinder . |
protected |
BasicComponentFinder(ComponentHierarchy hierarchy,
Settings settings)
Creates a new
BasicComponentFinder . |
Modifier and Type | Method and Description |
---|---|
Component |
find(ComponentMatcher m)
Finds an AWT or Swing
Component using the given ComponentMatcher . |
Component |
find(Container root,
ComponentMatcher m)
Finds an AWT or Swing
Component using the given ComponentMatcher in the hierarchy under the given
root. |
<T extends Component> |
find(Container root,
GenericTypeMatcher<T> m)
Finds an AWT or Swing
Component using the given GenericTypeMatcher in the hierarchy under the given
root. |
<T extends Component> |
find(GenericTypeMatcher<T> m)
Finds an AWT or Swing
Component using the given GenericTypeMatcher . |
Collection<Component> |
findAll(ComponentMatcher m)
Returns all the AWT or Swing
Component s that match the search criteria specified in the given
ComponentMatcher . |
Collection<Component> |
findAll(Container root,
ComponentMatcher m)
Returns all the AWT or Swing
Component s under the given root that match the search criteria specified in
the given ComponentMatcher . |
<T extends Component> |
findAll(Container root,
GenericTypeMatcher<T> m)
Returns all the AWT or Swing
Component s under the given root that match the search criteria specified in
the given GenericTypeMatcher . |
<T extends Component> |
findAll(GenericTypeMatcher<T> m)
Returns all the AWT or Swing
Component s that match the search criteria specified in the given
GenericTypeMatcher . |
Component |
findByLabel(Container root,
String label)
Finds an AWT or Swing
Component by the text of its associated JLabel , in the hierarchy under the
given root. |
Component |
findByLabel(Container root,
String label,
boolean showing)
Finds an AWT or Swing
Component by the text of its associated JLabel , in the hierarchy under the
given root. |
<T extends Component> |
findByLabel(Container root,
String label,
Class<T> type)
Finds an AWT or Swing
Component by the text of its associated JLabel and type, in the hierarchy
under the given root. |
<T extends Component> |
findByLabel(Container root,
String label,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by the text of its associated JLabel and type, in the hierarchy
under the given root. |
Component |
findByLabel(String label)
Finds an AWT or Swing
Component by by the text of its associated JLabel . |
Component |
findByLabel(String label,
boolean showing)
Finds an AWT or Swing
Component by by the text of its associated JLabel . |
<T extends Component> |
findByLabel(String label,
Class<T> type)
Finds an AWT or Swing
Component by the text of its associated JLabel and type. |
<T extends Component> |
findByLabel(String label,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by the text of its associated JLabel and type. |
Component |
findByName(Container root,
String name)
Finds an AWT or Swing
Component by name, in the hierarchy under the given root. |
Component |
findByName(Container root,
String name,
boolean showing)
Finds an AWT or Swing
Component by name, in the hierarchy under the given root. |
<T extends Component> |
findByName(Container root,
String name,
Class<T> type)
Finds an AWT or Swing
Component 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 an AWT or Swing
Component by name and type, in the hierarchy under the given root. |
Component |
findByName(String name)
Finds an AWT or Swing
Component by name. |
Component |
findByName(String name,
boolean showing)
Finds an AWT or Swing
Component by name. |
<T extends Component> |
findByName(String name,
Class<T> type)
Finds an AWT or Swing
Component by name and type. |
<T extends Component> |
findByName(String name,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by name and type. |
<T extends Component> |
findByType(Class<T> type)
Finds an AWT or Swing
Component by type. |
<T extends Component> |
findByType(Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by type. |
<T extends Component> |
findByType(Container root,
Class<T> type)
Finds an AWT or Swing
Component by type in the hierarchy under the given root. |
<T extends Component> |
findByType(Container root,
Class<T> type,
boolean showing)
Finds an AWT or Swing
Component by type in the hierarchy under the given root. |
static ComponentFinder |
finderWithCurrentAwtHierarchy()
Creates a new
BasicComponentFinder that has access to all the AWT and Swing Component s in the AWT
hierarchy. |
static ComponentFinder |
finderWithNewAwtHierarchy()
Creates a new
BasicComponentFinder with a new AWT hierarchy. |
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() |
protected boolean |
requireShowingFromSettingsOr(boolean defaultValue)
Returns the value of the flag "requireShowing" in the
ComponentLookupScope this finder's Settings . |
protected BasicComponentFinder(@Nonnull ComponentHierarchy hierarchy)
BasicComponentFinder
. The created finder does not use any Settings
.hierarchy
- the component hierarchy to use.protected BasicComponentFinder(@Nonnull ComponentHierarchy hierarchy, @Nullable Settings settings)
BasicComponentFinder
.hierarchy
- the component hierarchy to use.settings
- the configuration settings to use. It can be null
.@Nonnull public static ComponentFinder finderWithNewAwtHierarchy()
BasicComponentFinder
with a new AWT hierarchy. AWT and Swing Component
s created
before the created BasicComponentFinder
cannot be accessed by the created BasicComponentFinder
.@Nonnull public static ComponentFinder finderWithCurrentAwtHierarchy()
BasicComponentFinder
that has access to all the AWT and Swing Component
s in the AWT
hierarchy.@Nonnull public ComponentPrinter printer()
printer
in interface ComponentFinder
ComponentPrinter
in this finder.@Nonnull public <T extends Component> T findByType(@Nonnull Class<T> type)
ComponentFinder
Finds an AWT or Swing 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 type of the component to find.type
- the class of the component to find.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@RunsInEDT @Nonnull public <T extends Component> T findByType(@Nonnull Class<T> type, boolean showing)
ComponentFinder
Component
by type. For example:findByType
in interface ComponentFinder
T
- the type of the component to find.type
- the class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentFinder.findByType(Class)
@RunsInEDT @Nonnull public <T extends Component> T findByType(@Nonnull Container root, @Nonnull Class<T> type)
ComponentFinder
Finds an AWT or Swing 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);
findByType
in interface ComponentFinder
T
- the type of the component to find.root
- the root used as the starting point of the search.type
- the class of the component to find.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@RunsInEDT @Nonnull public <T extends Component> T findByType(@Nonnull Container root, @Nonnull Class<T> type, boolean showing)
ComponentFinder
Component
by type in the hierarchy under the given root.findByType
in interface ComponentFinder
T
- the type of the component to find.root
- the root used as the starting point of the search.type
- the class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentFinder.findByType(Container, Class)
@RunsInEDT @Nonnull public <T extends Component> T findByName(@Nullable String name, @Nonnull Class<T> type)
ComponentFinder
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 type of the component to find.name
- the name of the component to find.type
- the class of the component to find.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
,
ComponentFinder.findByName(String)
@RunsInEDT @Nonnull public <T extends Component> T findByName(@Nullable String name, @Nonnull Class<T> type, boolean showing)
ComponentFinder
Component
by name and type.findByName
in interface ComponentFinder
T
- the type of the component to find.name
- the name of the component to find.type
- the class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentFinder.findByName(String)
@RunsInEDT @Nonnull public Component findByName(@Nullable String name)
ComponentFinder
Finds an AWT or Swing 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:
findByName
in interface ComponentFinder
name
- the name of the component to find.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@RunsInEDT @Nonnull public Component findByName(@Nullable String name, boolean showing)
ComponentFinder
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 @Nonnull public <T extends Component> T findByLabel(@Nullable String label, @Nonnull Class<T> type)
ComponentFinder
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 type of the component to find.label
- the text of the JLabel
associated to the component to find.type
- the class of the component to find.ComponentFinder.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
,
Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@RunsInEDT @Nonnull public <T extends Component> T findByLabel(@Nullable String label, @Nonnull Class<T> type, boolean showing)
ComponentFinder
Component
by the text of its associated JLabel
and type.findByLabel
in interface ComponentFinder
T
- the type of the component to find.label
- the text of the JLabel
associated to the component to find.type
- the class 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 @Nonnull public Component findByLabel(@Nullable String label)
ComponentFinder
Finds an AWT or Swing 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:
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 @Nonnull public Component findByLabel(@Nullable String label, boolean showing)
ComponentFinder
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 @Nonnull public <T extends Component> T find(@Nonnull GenericTypeMatcher<T> m)
ComponentFinder
Component
using the given GenericTypeMatcher
. The given matcher will be
evaluated in the event dispatch thread (EDT.) Implementations of GenericTypeMatcher
do not need to be
concerned about the event dispatch thread (EDT.)find
in interface ComponentFinder
T
- the type of the component to find.m
- the matcher to use to find the component of interest.@RunsInEDT @Nonnull public Component find(@Nonnull ComponentMatcher m)
ComponentFinder
Component
using the given ComponentMatcher
. The given matcher will be
evaluated in the event dispatch thread (EDT.) Implementations of ComponentMatcher
do not need to be
concerned about the event dispatch thread (EDT.)find
in interface ComponentFinder
m
- the matcher to use to find the component of interest.@RunsInEDT @Nonnull public <T extends Component> T findByName(@Nonnull Container root, @Nullable String name, @Nonnull Class<T> type)
ComponentFinder
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 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 class of the component to find.Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
,
ComponentFinder.findByName(String)
@RunsInEDT @Nonnull public <T extends Component> T findByName(@Nonnull Container root, @Nullable String name, @Nonnull Class<T> type, boolean showing)
ComponentFinder
Component
by name and type, in the hierarchy under the given root.findByName
in interface ComponentFinder
T
- the 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 class of the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.ComponentFinder.findByName(String)
@RunsInEDT @Nonnull public Component findByName(@Nonnull Container root, @Nullable String name)
ComponentFinder
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 @Nonnull public Component findByName(@Nonnull Container root, @Nullable String name, boolean showing)
ComponentFinder
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 @Nonnull public <T extends Component> T findByLabel(@Nonnull Container root, @Nullable String label, @Nonnull Class<T> type)
ComponentFinder
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 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 class of the component to find.ComponentFinder.findByLabel(String)
,
JLabel.getLabelFor()
,
JLabel.setLabelFor(Component)
,
Robot.settings()
,
Settings.componentLookupScope()
,
ComponentLookupScope
@RunsInEDT @Nonnull public <T extends Component> T findByLabel(@Nonnull Container root, @Nullable String label, @Nonnull Class<T> type, boolean showing)
ComponentFinder
Component
by the text of its associated JLabel
and type, in the hierarchy
under the given root.findByLabel
in interface ComponentFinder
T
- the 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 class 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 @Nonnull public Component findByLabel(@Nonnull Container root, @Nullable String label)
ComponentFinder
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 @Nonnull public Component findByLabel(@Nonnull Container root, @Nullable String label, boolean showing)
ComponentFinder
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 @Nonnull public <T extends Component> T find(@Nonnull Container root, @Nonnull GenericTypeMatcher<T> m)
ComponentFinder
Component
using the given GenericTypeMatcher
in the hierarchy under the given
root. The given matcher will be evaluated in the event dispatch thread (EDT.) Implementations of
GenericTypeMatcher
do not need to be concerned about the event dispatch thread (EDT.)find
in interface ComponentFinder
T
- the type of the component to find.root
- the root used as the starting point of the search.m
- the matcher to use to find the component.@RunsInEDT @Nonnull public Component find(@Nullable Container root, @Nonnull ComponentMatcher m)
ComponentFinder
Component
using the given ComponentMatcher
in the hierarchy under the given
root. The given matcher will be evaluated in the event dispatch thread (EDT.) Implementations of
ComponentMatcher
do not need to be concerned about the event dispatch thread (EDT.)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()
ComponentFinder
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
org.assertj.swing.exception.ComponentLookupException
message, false
otherwise.public void includeHierarchyIfComponentNotFound(boolean newValue)
ComponentFinder
ComponentLookupException
should include the
current component hierarchy.
The default value is true
.includeHierarchyIfComponentNotFound
in interface ComponentFinder
newValue
- the new value to set.@Nonnull public Collection<Component> findAll(@Nonnull ComponentMatcher m)
ComponentFinder
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.@Nonnull public Collection<Component> findAll(@Nonnull Container root, @Nonnull ComponentMatcher m)
ComponentFinder
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.@Nonnull public <T extends Component> Collection<T> findAll(@Nonnull GenericTypeMatcher<T> m)
ComponentFinder
Component
s that match the search criteria specified in the given
GenericTypeMatcher
.findAll
in interface ComponentFinder
T
- the type of the component to find.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.@Nonnull public <T extends Component> Collection<T> findAll(@Nonnull Container root, @Nonnull GenericTypeMatcher<T> m)
ComponentFinder
Component
s under the given root that match the search criteria specified in
the given GenericTypeMatcher
.findAll
in interface ComponentFinder
T
- the type of the component to find.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.Copyright © 2014-2015 AssertJ. All Rights Reserved.