1 package fi.jyu.mit.fxgui;
3 import java.util.ArrayList;
5 import java.util.function.Predicate;
7 import javafx.scene.Node;
8 import javafx.scene.layout.Pane;
25 @SuppressWarnings(
"unchecked")
26 public static <T> List<T>
getNodes(Node parent, Class<T>
type, Predicate<Node> condition,
boolean recursive) {
27 List<T> elements =
new ArrayList<>();
29 if ( !(parent instanceof Pane) )
return elements;
31 for (Node node : ((Pane)parent).getChildren()) {
32 if (type.isAssignableFrom(node.getClass()) && condition != null && condition.test(node) )
33 elements.add((T) node);
34 if (node instanceof Pane && recursive)
35 elements.addAll(
getNodes((Pane) node, type, condition, recursive));
50 @SuppressWarnings(
"unchecked")
51 public static <T> T
getNode(Node parent, Class<T>
type, Predicate<Node> condition,
boolean recursive) {
52 if ( !(parent instanceof Pane) )
return null;
54 for (Node node : ((Pane)parent).getChildren()) {
55 if (type.isAssignableFrom(node.getClass()) && condition != null && condition.test(node) )
57 if (node instanceof Pane && recursive) {
58 T result =
getNode((Pane) node, type, condition, recursive);
59 if ( result != null )
return result;