All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tornadofx.util.NodeHelper Maven / Gradle / Ivy

The newest version!
package tornadofx.util;

import javafx.css.PseudoClass;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.layout.Pane;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class NodeHelper {

    public static  T findParentOfType( Node node, Class type ){
        if( node == null ) return null;
        Parent parent = node.getParent();
        if( parent == null ) return null;
        if( type.isAssignableFrom(parent.getClass()) ) return (T)parent;
        return findParentOfType( parent, type );
    }

    public static  List findChildrenOfType(Pane parent, Class type) {
        List elements = new ArrayList<>();
        for (Node node : parent.getChildren()) {
            if (type.isAssignableFrom(node.getClass())) {
                elements.add((T) node);
            } else if (node instanceof Pane) {
                elements.addAll(findChildrenOfType((Pane) node, type));
            }
        }
        return Collections.unmodifiableList(elements);
    }

    public static void addPseudoClass( Node node, String className ){
        PseudoClass pseudoClass = PseudoClass.getPseudoClass( className );
        node.pseudoClassStateChanged( pseudoClass, true );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy