// Path: src/main/java/tornadofx/util/NodeHelper.java
// public class NodeHelper {
// 
//     public static <T> T findParentOfType( Node node, Class<T> 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 <T> List<T> findChildrenOfType(Pane parent, Class<T> type) {
//         List<T> 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 );
//     }
// }


import javafx.beans.DefaultProperty;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ListChangeListener;
import javafx.css.PseudoClass;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import tornadofx.util.NodeHelper;
import java.util.List;
import static javafx.beans.binding.Bindings.createObjectBinding;
import static javafx.geometry.Orientation.HORIZONTAL;
import static javafx.geometry.Orientation.VERTICAL;
import static javafx.scene.layout.Priority.SOMETIMES;
    }

    public Field field(Node... inputs) {
        Field field = new Field(null, inputs);
        getChildren().add(field);
        return field;
    }

    public Fieldset() {

        getStyleClass().add("fieldset");

        syncOrientationState();

        // Add legend label when text is populated
        textProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue != null && !newValue.isEmpty() ) addLegend();
        });

        // Add legend when icon is populated
        iconProperty().addListener(((observable1, oldValue1, newValue) -> {
            if (newValue != null) addLegend();
        }));

        // Make sure input children get the configured HBox.hgrow property
        syncHgrow();

        // Register/deregister with parent Form
	    parentProperty().addListener( (observable, oldParent, newParent) -> {
	        if( !(oldParent instanceof Form) ) {
// Path: src/main/java/tornadofx/util/NodeHelper.java
// public class NodeHelper {
// 
//     public static <T> T findParentOfType( Node node, Class<T> 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 <T> List<T> findChildrenOfType(Pane parent, Class<T> type) {
//         List<T> 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 );
//     }
// }


// Path: src/main/java/tornadofx/control/Fieldset.java
import javafx.beans.DefaultProperty;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ListChangeListener;
import javafx.css.PseudoClass;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import tornadofx.util.NodeHelper;
import java.util.List;
import static javafx.beans.binding.Bindings.createObjectBinding;
import static javafx.geometry.Orientation.HORIZONTAL;
import static javafx.geometry.Orientation.VERTICAL;
import static javafx.scene.layout.Priority.SOMETIMES;

    }

    public Field field(Node... inputs) {
        Field field = new Field(null, inputs);
        getChildren().add(field);
        return field;
    }

    public Fieldset() {

        getStyleClass().add("fieldset");

        syncOrientationState();

        // Add legend label when text is populated
        textProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue != null && !newValue.isEmpty() ) addLegend();
        });

        // Add legend when icon is populated
        iconProperty().addListener(((observable1, oldValue1, newValue) -> {
            if (newValue != null) addLegend();
        }));

        // Make sure input children get the configured HBox.hgrow property
        syncHgrow();

        // Register/deregister with parent Form
	    parentProperty().addListener( (observable, oldParent, newParent) -> {
	        if( !(oldParent instanceof Form) ) {
                Form oldParentForm = NodeHelper.findParentOfType(oldParent, Form.class);