public class ComponentHierarchyNavigator extends Object implements TreeNavigator<Component>
TreeNavigator
for an AWT component hierarchy.
This implementation is thread-safe in the sense that individual method calls will not fail if the component hierarchy is changed concurrently. But it can not prevent return values from getting stale so chaining calls might lead to unexpected results, e.g.:
Component component = ... if (getParent(component).isPresent()) { // the component has a parent, so it should have a child index, too; // but the component hierarchy may have changed, so 'indexPresent' may be false boolean indexPresent = getChildIndex(component).isPresent(); }Similarly:
Component parent = ... Optional<Component> child1 = getChild(parent, 0); Optional<Component> child2 = getChild(parent, 0); // if the component hierarchy changed between the two calls, this may be false boolean sameChildren = child1.equals(child2);
Constructor and Description |
---|
ComponentHierarchyNavigator() |
Modifier and Type | Method and Description |
---|---|
Optional<Component> |
getChild(Component parent,
int childIndex) |
OptionalInt |
getChildIndex(Component node) |
int |
getChildrenCount(Component parent) |
Optional<Component> |
getParent(Component child) |
public Optional<Component> getParent(Component child)
getParent
in interface TreeNavigator<Component>
child
- an node in the treeempty
is
returnedpublic OptionalInt getChildIndex(Component node)
getChildIndex
in interface TreeNavigator<Component>
node
- a node in the treeempty
is returnedpublic int getChildrenCount(Component parent)
getChildrenCount
in interface TreeNavigator<Component>
parent
- a node in the treepublic Optional<Component> getChild(Component parent, int childIndex)
getChild
in interface TreeNavigator<Component>
parent
- a node in the treechildIndex
- a non-negative number specifying the index of the requested childempty
is returnedThis documentation is licensed under CC-BY 4.0, attributed to Nicolai Parlog from CodeFX.