Class BasicComponentFinder
- All Implemented Interfaces:
ComponentFinder
Component
lookup.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FinderDelegate
private final ComponentHierarchy
private boolean
private final ComponentPrinter
private final Settings
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BasicComponentFinder
(ComponentHierarchy hierarchy) Creates a new
.BasicComponentFinder
protected
BasicComponentFinder
(ComponentHierarchy hierarchy, Settings settings) Creates a new
.BasicComponentFinder
-
Method Summary
Modifier and TypeMethodDescriptionprivate static void
appendComponents
(StringBuilder message, Collection<Component> found) private ComponentLookupException
find
(Container root, ComponentMatcher m) Finds a
using the givenComponent
in the hierarchy under the given root.ComponentMatcher
<T extends Component>
Tfind
(Container root, GenericTypeMatcher<T> m) Finds a
using the givenComponent
in the hierarchy under the given root.GenericTypeMatcher
Finds a
using the givenComponent
.ComponentMatcher
<T extends Component>
Tfind
(GenericTypeMatcher<T> m) Finds a
using the givenComponent
.GenericTypeMatcher
private Component
findAll
(Container root, ComponentMatcher m) Returns all the
s under the given root that match the search criteria specified in the givenComponent
.ComponentMatcher
<T extends Component>
Collection<T>findAll
(Container root, GenericTypeMatcher<T> m) Returns all the
s under the given root that match the search criteria specified in the givenComponent
.GenericTypeMatcher
Returns all the
s that match the search criteria specified in the givenComponent
.ComponentMatcher
<T extends Component>
Collection<T>findAll
(GenericTypeMatcher<T> m) Returns all the
s that match the search criteria specified in the givenComponent
.GenericTypeMatcher
findByLabel
(Container root, String label) findByLabel
(Container root, String label, boolean showing) <T extends Component>
TfindByLabel
(Container root, String label, Class<T> type) <T extends Component>
TfindByLabel
(Container root, String label, Class<T> type, boolean showing) findByLabel
(String label) findByLabel
(String label, boolean showing) <T extends Component>
TfindByLabel
(String label, Class<T> type) <T extends Component>
TfindByLabel
(String label, Class<T> type, boolean showing) 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.Component
<T extends Component>
TfindByName
(Container root, String name, Class<T> type) Finds a
by name and type, in the hierarchy under the given root.Component
<T extends Component>
TfindByName
(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.Component
<T extends Component>
TfindByName
(String name, Class<T> type) Finds a
by name and type.Component
<T extends Component>
TfindByName
(String name, Class<T> type, boolean showing) Finds a
by name and type.Component
<T extends Component>
TfindByType
(Container root, Class<T> type) Finds a
by type in the hierarchy under the given root.Component
<T extends Component>
TfindByType
(Container root, Class<T> type, boolean showing) Finds a
by type in the hierarchy under the given root.Component
<T extends Component>
TfindByType
(Class<T> type) Finds a
by type.Component
<T extends Component>
TfindByType
(Class<T> type, boolean showing) Finds a
by type.Component
static ComponentFinder
Creates a new
that has access to all the GUI components in the AWT hierarchy.BasicComponentFinder
static ComponentFinder
Creates a new
with a new AWT hierarchy.BasicComponentFinder
private String
formattedHierarchy
(Container root) private ComponentHierarchy
boolean
Returns whether the message in a
should include the current component hierarchy.ComponentLookupException
void
includeHierarchyIfComponentNotFound
(boolean newValue) Updates whether the message in a
should include the current component hierarchy.ComponentLookupException
private <T> T
private static ComponentLookupException
printer()
Returns the
in this finder.ComponentPrinter
private boolean
protected final boolean
requireShowingFromSettingsOr
(boolean defaultValue) Returns the value of the flag "requireShowing" in the
this finder'sComponentLookupScope
.Settings
private static Container
-
Field Details
-
hierarchy
-
printer
-
settings
-
finderDelegate
-
includeHierarchyInComponentLookupException
private boolean includeHierarchyInComponentLookupException
-
-
Constructor Details
-
BasicComponentFinder
Creates a new
. The created finder does not use anyBasicComponentFinder
.Settings
- Parameters:
hierarchy
- the component hierarchy to use.
-
BasicComponentFinder
Creates a new
.BasicComponentFinder
- Parameters:
hierarchy
- the component hierarchy to use.settings
- the configuration settings to use. It can benull
.
-
-
Method Details
-
finderWithNewAwtHierarchy
Creates a new
with a new AWT hierarchy.BasicComponentFinder
s created before the createdComponent
cannot be accessed by the createdBasicComponentFinder
.BasicComponentFinder
- Returns:
- the created finder.
-
finderWithCurrentAwtHierarchy
Creates a new
that has access to all the GUI components in the AWT hierarchy.BasicComponentFinder
- Returns:
- the created finder.
-
printer
Returns the
in this finder.ComponentPrinter
- Specified by:
printer
in interfaceComponentFinder
- Returns:
- the
ComponentPrinter
in this finder.
-
findByType
Finds a
by type. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.Example:
JTextField textbox = finder.findByType(JTextField.class);
- Specified by:
findByType
in interfaceComponentFinder
- Type Parameters:
T
- the parameterized type of the component to find.- Parameters:
type
- the type of the component to find.- Returns:
- the found component.
- See Also:
-
findByType
Finds a
by type. For example:Component
- Specified by:
findByType
in interfaceComponentFinder
- 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.
- See Also:
-
findByType
Finds a
by type in the hierarchy under the given root. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.Let's assume we have the following
containing aJFrame
:JTextField
JFrame myFrame = new JFrame(); myFrame.add(new JTextField());
If we want to get a reference to the
in that particularJTextField
without going through the whole AWT component hierarchy, we could simply specify:JFrame
JTextField textbox = finder.findByType(myFrame, JTextField.class);
- Specified by:
findByType
in interfaceComponentFinder
- 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.
- See Also:
-
findByType
@RunsInEDT public <T extends Component> T findByType(Container root, Class<T> type, boolean showing) Finds a
by type in the hierarchy under the given root.Component
- Specified by:
findByType
in interfaceComponentFinder
- 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.showing
- indicates whether the component to find should be visible (or showing) or not.- Returns:
- the found component.
- See Also:
-
findByName
Finds a
by name and type. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.- Specified by:
findByName
in interfaceComponentFinder
- 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.
- See Also:
-
findByName
Finds a
by name and type.Component
- Specified by:
findByName
in interfaceComponentFinder
- 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.
- See Also:
-
findByName
Finds a
by name. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
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:
- Specified by:
findByName
in interfaceComponentFinder
- Parameters:
name
- the name of the component to find.- Returns:
- the found component.
- See Also:
-
findByName
Finds a
by name.Component
- Specified by:
findByName
in interfaceComponentFinder
- 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.
- See Also:
-
findByLabel
Finds a
by the text of its associatedComponent
and type. If this finder is attached to aJLabel
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.- Specified by:
findByLabel
in interfaceComponentFinder
- Type Parameters:
T
- the parameterized type of the component to find.- Parameters:
label
- the text of theJLabel
associated to the component to find.type
- the type of the component to find.- Returns:
- the found component.
- See Also:
-
findByLabel
- Specified by:
findByLabel
in interfaceComponentFinder
- Type Parameters:
T
- the parameterized type of the component to find.- Parameters:
label
- the text of theJLabel
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.
- See Also:
-
findByLabel
Finds a
by by the text of its associatedComponent
. If this finder is attached to aJLabel
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.Let's assume we have the
with aJTextField
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 associatedJTextField
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:
- Specified by:
findByLabel
in interfaceComponentFinder
- Parameters:
label
- the text of theJLabel
associated to the component to find.- Returns:
- the found component.
- See Also:
-
findByLabel
- Specified by:
findByLabel
in interfaceComponentFinder
- Parameters:
label
- the text of theJLabel
associated to the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.- Returns:
- the found component.
- See Also:
-
find
Finds a
using the givenComponent
. The given matcher will be evaluated in the event dispatch thread. Implementations ofGenericTypeMatcher
GenericTypeMatcher
do not need to be concerned about the event dispatch thread.- Specified by:
find
in interfaceComponentFinder
- 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.
-
find
Finds a
using the givenComponent
. The given matcher will be evaluated in the event dispatch thread. Implementations ofComponentMatcher
ComponentMatcher
do not need to be concerned about the event dispatch thread.- Specified by:
find
in interfaceComponentFinder
- Parameters:
m
- the matcher to use to find the component of interest.- Returns:
- the found component.
-
findByName
Finds a
by name and type, in the hierarchy under the given root. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.- Specified by:
findByName
in interfaceComponentFinder
- 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.
- See Also:
-
findByName
@RunsInEDT public <T extends Component> T findByName(Container root, String name, Class<T> type, boolean showing) Finds a
by name and type, in the hierarchy under the given root.Component
- Specified by:
findByName
in interfaceComponentFinder
- 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.
- See Also:
-
findByName
Finds a
by name, in the hierarchy under the given root. If this finder is attached to aComponent
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.- Specified by:
findByName
in interfaceComponentFinder
- Parameters:
root
- the root used as the starting point of the search.name
- the name of the component to find.- Returns:
- the found component.
- See Also:
-
findByName
Finds a
by name, in the hierarchy under the given root.Component
- Specified by:
findByName
in interfaceComponentFinder
- 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.
- See Also:
-
findByLabel
Finds a
by the text of its associatedComponent
and type, in the hierarchy under the given root. If this finder is attached to aJLabel
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.- Specified by:
findByLabel
in interfaceComponentFinder
- 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 theJLabel
associated to the component to find.type
- the type of the component to find.- Returns:
- the found component.
- See Also:
-
findByLabel
@RunsInEDT public <T extends Component> T findByLabel(Container root, String label, Class<T> type, boolean showing) Finds a
by the text of its associatedComponent
and type, in the hierarchy under the given root.JLabel
- Specified by:
findByLabel
in interfaceComponentFinder
- 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 theJLabel
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.
- See Also:
-
findByLabel
Finds a
by the text of its associatedComponent
, in the hierarchy under the given root. If this finder is attached to aJLabel
, it will use the component lookup scope in theRobot
Robot
's
to determine whether the component to find should be showing or not. If this finder is not attached to anySettings
Robot
, the component to find does not have to be showing.- Specified by:
findByLabel
in interfaceComponentFinder
- Parameters:
root
- the root used as the starting point of the search.label
- the text of theJLabel
associated to the component to find.- Returns:
- the found component.
- See Also:
-
requireShowing
private boolean requireShowing() -
findByLabel
- Specified by:
findByLabel
in interfaceComponentFinder
- Parameters:
root
- the root used as the starting point of the search.label
- the text of theJLabel
associated to the component to find.showing
- indicates whether the component to find should be visible (or showing) or not.- Returns:
- the found component.
- See Also:
-
labelFor
-
find
Finds a
using the givenComponent
in the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations ofGenericTypeMatcher
GenericTypeMatcher
do not need to be concerned about the event dispatch thread.- Specified by:
find
in interfaceComponentFinder
- 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.
-
find
Finds a
using the givenComponent
in the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations ofComponentMatcher
ComponentMatcher
do not need to be concerned about the event dispatch thread.- Specified by:
find
in interfaceComponentFinder
- 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.
-
find
-
componentNotFound
@RunsInEDT private ComponentLookupException componentNotFound(ComponentHierarchy h, ComponentMatcher m) -
root
-
formattedHierarchy
-
multipleComponentsFound
@RunsInEDT private static ComponentLookupException multipleComponentsFound(Collection<Component> found, ComponentMatcher m) -
appendComponents
-
includeHierarchyIfComponentNotFound
public boolean includeHierarchyIfComponentNotFound()Returns whether the message in a
should include the current component hierarchy. The default value isComponentLookupException
true
.- Specified by:
includeHierarchyIfComponentNotFound
in interfaceComponentFinder
- Returns:
true
if the component hierarchy is included as part of theComponentLookupException
message,false
otherwise.
-
includeHierarchyIfComponentNotFound
public void includeHierarchyIfComponentNotFound(boolean newValue) Updates whether the message in a
should include the current component hierarchy. The default value isComponentLookupException
true
.- Specified by:
includeHierarchyIfComponentNotFound
in interfaceComponentFinder
- Parameters:
newValue
- the new value to set.
-
findAll
Returns all the
s that match the search criteria specified in the givenComponent
.ComponentMatcher
- Specified by:
findAll
in interfaceComponentFinder
- Parameters:
m
- the matcher to use to find the component.- Returns:
- all the
Component
s that match the search criteria specified in the givenComponentMatcher
; or an empty collection, if there are no matching components.
-
findAll
Returns all the
s under the given root that match the search criteria specified in the givenComponent
.ComponentMatcher
- Specified by:
findAll
in interfaceComponentFinder
- Parameters:
root
- the root used as the starting point of the search.m
- the matcher to use to find the component.- Returns:
- all the
Component
s under the given root that match the search criteria specified in the givenComponentMatcher
; or an empty collection, if there are no matching components.
-
findAll
Returns all the
s that match the search criteria specified in the givenComponent
.GenericTypeMatcher
- Specified by:
findAll
in interfaceComponentFinder
- 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
Component
s that match the search criteria specified in the givenGenericTypeMatcher
; or an empty collection, if there are no matching components.
-
findAll
Returns all the
s under the given root that match the search criteria specified in the givenComponent
.GenericTypeMatcher
- Specified by:
findAll
in interfaceComponentFinder
- 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
Component
s under the given root that match the search criteria specified in the givenGenericTypeMatcher
; or an empty collection, if there are no matching components.
-
requireShowingFromSettingsOr
protected final boolean requireShowingFromSettingsOr(boolean defaultValue) Returns the value of the flag "requireShowing" in the
this finder'sComponentLookupScope
. If the settings object isSettings
null
, this method will return the provided default value.- Parameters:
defaultValue
- the value to return if this matcher does not have any configuration settings.- Returns:
- the value of the flag "requireShowing" in this finder's settings, or the provided default value if this finder does not have configuration settings.
-
hierarchy
-