public class SceneGraphNavigator extends Object implements TreeNavigator<javafx.scene.Node>
TreeNavigator
for a JavaFX scene graph.
This implementation is thread-safe in the sense that individual method calls will not fail if the scene graph is changed concurrently. But it can not prevent return values from getting stale so chaining calls might lead to unexpected results, e.g.:
Node node = ... if (getParent(node).isPresent()) { // the node has a parent, so it should have a child index, too; // but the scene graph may have changed, so 'indexPresent' may be false boolean indexPresent = getChildIndex(node).isPresent(); }Similarly:
Node parent = ... Optional<Node> child1 = getChild(parent, 0); Optional<Node> child2 = getChild(parent, 0); // if the scene graph changed between the two calls, this may be false boolean sameChildren = child1.equals(child2);
Constructor and Description |
---|
SceneGraphNavigator() |
Modifier and Type | Method and Description |
---|---|
Optional<javafx.scene.Node> |
getChild(javafx.scene.Node parent,
int childIndex) |
OptionalInt |
getChildIndex(javafx.scene.Node node) |
int |
getChildrenCount(javafx.scene.Node parent) |
Optional<javafx.scene.Node> |
getParent(javafx.scene.Node child) |
public Optional<javafx.scene.Node> getParent(javafx.scene.Node child)
getParent
in interface TreeNavigator<javafx.scene.Node>
child
- an node in the treeempty
is
returnedpublic OptionalInt getChildIndex(javafx.scene.Node node)
getChildIndex
in interface TreeNavigator<javafx.scene.Node>
node
- a node in the treeempty
is returnedpublic int getChildrenCount(javafx.scene.Node parent)
getChildrenCount
in interface TreeNavigator<javafx.scene.Node>
parent
- a node in the treepublic Optional<javafx.scene.Node> getChild(javafx.scene.Node parent, int childIndex)
getChild
in interface TreeNavigator<javafx.scene.Node>
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.