<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.mihosoft.vrl.fxwindows;

import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class VFXNodeUtils {
    // no instanciation allowed

    private VFXNodeUtils() {
        throw new AssertionError(); // not in this class either!
    }
    
    // we probably don't need this scale stuff anymore (since 2.2)

//    /**
//     * Returns the global scale of the specified node.
//     *
//     * @param n node
//     * @return the global scale of the specified node
//     */
//    public static Scale getGlobalScale(Node n) {
//        return _getGlobalScale(n,
//                new Scale(n.getScaleX(), n.getScaleY(), n.getScaleZ()));
//    }
//
//    /**
//     * Returns the global scale of the ancestors of the specified node.
//     *
//     * @param n node
//     * @return the global scale of the ancestors of the specified node
//     */
//    public static Scale getGlobalParentScale(Node n) {
//        return _getGlobalScale(n,
//                new Scale(1, 1, 1));
//    }
//
//    private static Scale _getGlobalScale(Node n, Scale scale) {
//        Node parent = n.getParent();
//
//        if (parent != null) {
//            scale = new Scale(
//                    parent.getScaleX() * scale.getScaleX(),
//                    parent.getScaleY() * scale.getScaleY(),
//                    parent.getScaleZ() * scale.getScaleZ());
//
//            scale = _getGlobalScale(parent, scale);
//        }
//
//        return scale;
//    }
    
    public static void removeFromParent(Node n) {
        if (n.getParent() instanceof Group) {
            ((Group)n.getParent()).getChildren().remove(n);
        } else if (n.getParent() instanceof Pane) {
            ((Pane)n.getParent()).getChildren().remove(n);
        }
    }
    
     public static void addToParent(Parent p, Node n) {
        if (p instanceof Group) {
            ((Group)p).getChildren().add(n);
        } else if (p instanceof Pane) {
            ((Pane)p).getChildren().add(n);
        }
    }
}<commit_msg>nodeutil extended, getNode by scene coordinates<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.mihosoft.vrl.fxwindows;

import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class VFXNodeUtils {
    // no instanciation allowed

    private VFXNodeUtils() {
        throw new AssertionError(); // not in this class either!
    }

    // we probably don't need this scale stuff anymore (since 2.2)
//    /**
//     * Returns the global scale of the specified node.
//     *
//     * @param n node
//     * @return the global scale of the specified node
//     */
//    public static Scale getGlobalScale(Node n) {
//        return _getGlobalScale(n,
//                new Scale(n.getScaleX(), n.getScaleY(), n.getScaleZ()));
//    }
//
//    /**
//     * Returns the global scale of the ancestors of the specified node.
//     *
//     * @param n node
//     * @return the global scale of the ancestors of the specified node
//     */
//    public static Scale getGlobalParentScale(Node n) {
//        return _getGlobalScale(n,
//                new Scale(1, 1, 1));
//    }
//
//    private static Scale _getGlobalScale(Node n, Scale scale) {
//        Node parent = n.getParent();
//
//        if (parent != null) {
//            scale = new Scale(
//                    parent.getScaleX() * scale.getScaleX(),
//                    parent.getScaleY() * scale.getScaleY(),
//                    parent.getScaleZ() * scale.getScaleZ());
//
//            scale = _getGlobalScale(parent, scale);
//        }
//
//        return scale;
//    }
    public static void removeFromParent(Node n) {
        if (n.getParent() instanceof Group) {
            ((Group) n.getParent()).getChildren().remove(n);
        } else if (n.getParent() instanceof Pane) {
            ((Pane) n.getParent()).getChildren().remove(n);
        }
    }

    public static void addToParent(Parent p, Node n) {
        if (p instanceof Group) {
            ((Group) p).getChildren().add(n);
        } else if (p instanceof Pane) {
            ((Pane) p).getChildren().add(n);
        }
    }

    public static Node getNode(Parent p, double sceneX, double sceneY, Class<?> nodeClass) {
//        Node result = null;

        for (Node n : p.getChildrenUnmodifiable()) {
            boolean contains = n.contains(n.sceneToLocal(sceneX, sceneY));

            if (contains) {
                
                if (nodeClass.isAssignableFrom(n.getClass())) {
                    return n;
                }

                if (n instanceof Parent) {
                    return getNode((Parent) n, sceneX, sceneY, nodeClass);
                }
            }
        }

        return null;
    }
}
{'fraction_non_alphanumeric': 0.13849445633145302, 'fraction_numerical': 0.0019451468585878235, 'mean_word_length': 1.8424543946932006, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7587153', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1481, 'n_words': 415}