Search in sources :

Example 1 with UnmodifiableListSet

use of com.sun.javafx.collections.UnmodifiableListSet in project JFoenix by jfoenixadmin.

the class JFXNodeUtils method getAllChildren.

public static <T> Set<T> getAllChildren(Node root, Class<T> childClass) {
    final List<T> selectedChildren = new ArrayList<>();
    Queue<Node> queue = new ArrayDeque<>();
    queue.add(root);
    while (!queue.isEmpty()) {
        Node head = queue.poll();
        if (childClass.isInstance(head)) {
            selectedChildren.add((T) head);
        } else if (Region.class.isInstance(head)) {
            ((Region) head).getChildrenUnmodifiable().forEach(queue::offer);
        }
    }
    return new UnmodifiableListSet<>(selectedChildren);
}
Also used : Node(javafx.scene.Node) ArrayList(java.util.ArrayList) Region(javafx.scene.layout.Region) UnmodifiableListSet(com.sun.javafx.collections.UnmodifiableListSet) ArrayDeque(java.util.ArrayDeque)

Aggregations

UnmodifiableListSet (com.sun.javafx.collections.UnmodifiableListSet)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Node (javafx.scene.Node)1 Region (javafx.scene.layout.Region)1