NodeParent

public abstract class NodeParent
Known Direct Subclasses
Known Indirect Subclasses

Base class for all classes that can contain a set of nodes as children.

The classes Node and Scene are both NodeParents. To make a Node the child of another Node or a Scene, use setParent(NodeParent).

Public Constructors

Public Methods

final void
addChild(Node child)
Adds a node as a child of this NodeParent.
void
callOnHierarchy(Consumer<Node> consumer)
Traverse the hierarchy and call a method on each node.
Node
findByName(String name)
Traverse the hierarchy to find the first node with a given name.
Node
findInHierarchy(Predicate<Node> condition)
Traverse the hierarchy to find the first node that meets a condition.
final List<Node>
getChildren()
Returns an immutable list of this parent's children.
final void
removeChild(Node child)
Removes a node from the children of this NodeParent.

Protected Methods

boolean
canAddChild(Node child, StringBuilder failureReason)
void
onAddChild(Node child)
void

Inherited Methods

Public Constructors

public NodeParent ()

Public Methods

public final void addChild (Node child)

Adds a node as a child of this NodeParent. If the node already has a parent, it is removed from its old parent. If the node is already a direct child of this NodeParent, no change is made.

Parameters
child the node to add as a child
Throws
IllegalArgumentException if the child is the same object as the parent, or if the parent is a descendant of the child

public void callOnHierarchy (Consumer<Node> consumer)

Traverse the hierarchy and call a method on each node. Traversal is depth first. If this NodeParent is a Node, traversal starts with this NodeParent, otherwise traversal starts with its children.

Parameters
consumer The method to call on each node.

public Node findByName (String name)

Traverse the hierarchy to find the first node with a given name. Traversal is depth first. If this NodeParent is a Node, traversal starts with this NodeParent, otherwise traversal starts with its children.

Parameters
name The name of the node to find
Returns
  • the node if it's found, otherwise null

public Node findInHierarchy (Predicate<Node> condition)

Traverse the hierarchy to find the first node that meets a condition. Traversal is depth first. If this NodeParent is a Node, traversal starts with this NodeParent, otherwise traversal starts with its children.

Parameters
condition predicate the defines the conditions of the node to search for.
Returns
  • the first node that matches the conditions of the predicate, otherwise null is returned

public final List<Node> getChildren ()

Returns an immutable list of this parent's children.

public final void removeChild (Node child)

Removes a node from the children of this NodeParent. If the node is not a direct child of this NodeParent, no change is made.

Parameters
child the node to remove from the children

Protected Methods

protected boolean canAddChild (Node child, StringBuilder failureReason)

Parameters
child
failureReason

protected void onAddChild (Node child)

Parameters
child

protected void onRemoveChild (Node child)

Parameters
child

Send feedback about...