Class BasicComponentFinder
- All Implemented Interfaces:
ComponentFinder
Component lookup.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FinderDelegateprivate final ComponentHierarchyprivate booleanprivate final ComponentPrinterprivate final Settings -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBasicComponentFinder(ComponentHierarchy hierarchy) Creates a new.BasicComponentFinderprotectedBasicComponentFinder(ComponentHierarchy hierarchy, Settings settings) Creates a new.BasicComponentFinder -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidappendComponents(StringBuilder message, Collection<Component> found) private ComponentLookupExceptionfind(Container root, ComponentMatcher m) Finds ausing the givenComponentin the hierarchy under the given root.ComponentMatcher<T extends Component>
Tfind(Container root, GenericTypeMatcher<T> m) Finds ausing the givenComponentin the hierarchy under the given root.GenericTypeMatcherFinds ausing the givenComponent.ComponentMatcher<T extends Component>
Tfind(GenericTypeMatcher<T> m) Finds ausing the givenComponent.GenericTypeMatcherprivate ComponentfindAll(Container root, ComponentMatcher m) Returns all thes 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 thes under the given root that match the search criteria specified in the givenComponent.GenericTypeMatcherReturns all thes that match the search criteria specified in the givenComponent.ComponentMatcher<T extends Component>
Collection<T>findAll(GenericTypeMatcher<T> m) Returns all thes that match the search criteria specified in the givenComponent.GenericTypeMatcherfindByLabel(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 aby name, in the hierarchy under the given root.ComponentfindByName(Container root, String name, boolean showing) Finds aby name, in the hierarchy under the given root.Component<T extends Component>
TfindByName(Container root, String name, Class<T> type) Finds aby 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 aby name and type, in the hierarchy under the given root.ComponentfindByName(String name) Finds aby name.ComponentfindByName(String name, boolean showing) Finds aby name.Component<T extends Component>
TfindByName(String name, Class<T> type) Finds aby name and type.Component<T extends Component>
TfindByName(String name, Class<T> type, boolean showing) Finds aby name and type.Component<T extends Component>
TfindByType(Container root, Class<T> type) Finds aby type in the hierarchy under the given root.Component<T extends Component>
TfindByType(Container root, Class<T> type, boolean showing) Finds aby type in the hierarchy under the given root.Component<T extends Component>
TfindByType(Class<T> type) Finds aby type.Component<T extends Component>
TfindByType(Class<T> type, boolean showing) Finds aby type.Componentstatic ComponentFinderCreates a newthat has access to all the GUI components in the AWT hierarchy.BasicComponentFinderstatic ComponentFinderCreates a newwith a new AWT hierarchy.BasicComponentFinderprivate StringformattedHierarchy(Container root) private ComponentHierarchybooleanReturns whether the message in ashould include the current component hierarchy.ComponentLookupExceptionvoidincludeHierarchyIfComponentNotFound(boolean newValue) Updates whether the message in ashould include the current component hierarchy.ComponentLookupExceptionprivate <T> Tprivate static ComponentLookupExceptionprinter()Returns thein this finder.ComponentPrinterprivate booleanprotected final booleanrequireShowingFromSettingsOr(boolean defaultValue) Returns the value of the flag "requireShowing" in thethis finder'sComponentLookupScope.Settingsprivate 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 newwith a new AWT hierarchy.BasicComponentFinders created before the createdComponentcannot be accessed by the createdBasicComponentFinder.BasicComponentFinder- Returns:
- the created finder.
-
finderWithCurrentAwtHierarchy
Creates a newthat has access to all the GUI components in the AWT hierarchy.BasicComponentFinder- Returns:
- the created finder.
-
printer
Returns thein this finder.ComponentPrinter- Specified by:
printerin interfaceComponentFinder- Returns:
- the
ComponentPrinterin this finder.
-
findByType
Finds aby type. If this finder is attached to aComponent, it will use the component lookup scope in theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.Example:
JTextField textbox = finder.findByType(JTextField.class);
- Specified by:
findByTypein 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 aby type. For example:Component- Specified by:
findByTypein 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 theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.Let's assume we have the following
containing aJFrame:JTextFieldJFrame myFrame = new JFrame(); myFrame.add(new JTextField());
If we want to get a reference to the
in that particularJTextFieldwithout going through the whole AWT component hierarchy, we could simply specify:JFrameJTextField textbox = finder.findByType(myFrame, JTextField.class);
- Specified by:
findByTypein 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 aby type in the hierarchy under the given root.Component- Specified by:
findByTypein 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 aby name and type. If this finder is attached to aComponent, it will use the component lookup scope in theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.- Specified by:
findByNamein 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 aby name and type.Component- Specified by:
findByNamein 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 theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.Let's assume we have the
with name "myTextBox";JTextFieldJTextField textbox = new JTextField(); textBox.setName("myTextBox");To get a reference to this
by its name, we can specify:JTextFieldJTextField 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:
findByNamein interfaceComponentFinder- Parameters:
name- the name of the component to find.- Returns:
- the found component.
- See Also:
-
findByName
Finds aby name.Component- Specified by:
findByNamein 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 aby the text of its associatedComponentand type. If this finder is attached to aJLabel, it will use the component lookup scope in theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.- Specified by:
findByLabelin interfaceComponentFinder- Type Parameters:
T- the parameterized type of the component to find.- Parameters:
label- the text of theJLabelassociated to the component to find.type- the type of the component to find.- Returns:
- the found component.
- See Also:
-
findByLabel
- Specified by:
findByLabelin interfaceComponentFinder- Type Parameters:
T- the parameterized type of the component to find.- Parameters:
label- the text of theJLabelassociated 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 theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.Let's assume we have the
with aJTextFieldwith text "Name";JLabelJLabel label = new JLabel("Name"); JTextField textbox = new JTextField(); label.setLabelFor(textBox);To get a reference to this
by the text of its associatedJTextFieldJLabel, 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:
findByLabelin interfaceComponentFinder- Parameters:
label- the text of theJLabelassociated to the component to find.- Returns:
- the found component.
- See Also:
-
findByLabel
- Specified by:
findByLabelin interfaceComponentFinder- Parameters:
label- the text of theJLabelassociated 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 ausing the givenComponent. The given matcher will be evaluated in the event dispatch thread. Implementations ofGenericTypeMatcherGenericTypeMatcherdo not need to be concerned about the event dispatch thread.- Specified by:
findin 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 ausing the givenComponent. The given matcher will be evaluated in the event dispatch thread. Implementations ofComponentMatcherComponentMatcherdo not need to be concerned about the event dispatch thread.- Specified by:
findin interfaceComponentFinder- Parameters:
m- the matcher to use to find the component of interest.- Returns:
- the found component.
-
findByName
Finds aby 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 theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.- Specified by:
findByNamein 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 aby name and type, in the hierarchy under the given root.Component- Specified by:
findByNamein 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 aby name, in the hierarchy under the given root. If this finder is attached to aComponent, it will use the component lookup scope in theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.- Specified by:
findByNamein 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 aby name, in the hierarchy under the given root.Component- Specified by:
findByNamein 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 aby the text of its associatedComponentand type, in the hierarchy under the given root. If this finder is attached to aJLabel, it will use the component lookup scope in theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.- Specified by:
findByLabelin 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 theJLabelassociated 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 aby the text of its associatedComponentand type, in the hierarchy under the given root.JLabel- Specified by:
findByLabelin 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 theJLabelassociated 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 aby 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 theRobotRobot'sto determine whether the component to find should be showing or not. If this finder is not attached to anySettingsRobot, the component to find does not have to be showing.- Specified by:
findByLabelin interfaceComponentFinder- Parameters:
root- the root used as the starting point of the search.label- the text of theJLabelassociated to the component to find.- Returns:
- the found component.
- See Also:
-
requireShowing
private boolean requireShowing() -
findByLabel
- Specified by:
findByLabelin interfaceComponentFinder- Parameters:
root- the root used as the starting point of the search.label- the text of theJLabelassociated 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 ausing the givenComponentin the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations ofGenericTypeMatcherGenericTypeMatcherdo not need to be concerned about the event dispatch thread.- Specified by:
findin 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 ausing the givenComponentin the hierarchy under the given root. The given matcher will be evaluated in the event dispatch thread. Implementations ofComponentMatcherComponentMatcherdo not need to be concerned about the event dispatch thread.- Specified by:
findin 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 ashould include the current component hierarchy. The default value isComponentLookupExceptiontrue.- Specified by:
includeHierarchyIfComponentNotFoundin interfaceComponentFinder- Returns:
trueif the component hierarchy is included as part of theComponentLookupExceptionmessage,falseotherwise.
-
includeHierarchyIfComponentNotFound
public void includeHierarchyIfComponentNotFound(boolean newValue) Updates whether the message in ashould include the current component hierarchy. The default value isComponentLookupExceptiontrue.- Specified by:
includeHierarchyIfComponentNotFoundin interfaceComponentFinder- Parameters:
newValue- the new value to set.
-
findAll
Returns all thes that match the search criteria specified in the givenComponent.ComponentMatcher- Specified by:
findAllin interfaceComponentFinder- Parameters:
m- the matcher to use to find the component.- Returns:
- all the
Components that match the search criteria specified in the givenComponentMatcher; or an empty collection, if there are no matching components.
-
findAll
Returns all thes under the given root that match the search criteria specified in the givenComponent.ComponentMatcher- Specified by:
findAllin 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
Components 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 thes that match the search criteria specified in the givenComponent.GenericTypeMatcher- Specified by:
findAllin 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
Components that match the search criteria specified in the givenGenericTypeMatcher; or an empty collection, if there are no matching components.
-
findAll
Returns all thes under the given root that match the search criteria specified in the givenComponent.GenericTypeMatcher- Specified by:
findAllin 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
Components 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 thethis finder'sComponentLookupScope. If the settings object isSettingsnull, 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
-