package be.iminds.ilabt.jfed.experimenter_gui.canvas;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.DoubleBinding;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.scene.Node;

/**
 * User: twalcari
 * Date: 6/4/2015
 * Time: 12:01
 */
public interface NewLinkTarget {

    static DoubleBinding createCenterXBinding(Node node){
        return Bindings.createDoubleBinding(()-> node.getLayoutBounds().getMinX() + node.getLayoutBounds().getWidth()/2.0,
                node.layoutBoundsProperty())
                .add(node.layoutXProperty());
    }

    static DoubleBinding createCenterYBinding(Node node){
        return Bindings.createDoubleBinding(()-> node.getLayoutBounds().getMinY() + node.getLayoutBounds().getHeight()/2.0,
                node.layoutBoundsProperty())
                .add(node.layoutYProperty());
    }


    static double getCenterX(Node node) {
        return node.getLayoutX() + node.getLayoutBounds().getMinX() + node.getLayoutBounds().getWidth() / 2.0;

    }

    static double getCenterY(Node node) {
        return node.getLayoutY() + node.getLayoutBounds().getMinY() + node.getLayoutBounds().getHeight() / 2.0;

    }

    static void setCenterX(double x, Node node) {
        node.setLayoutX(x - node.getLayoutBounds().getMinX() - node.getLayoutBounds().getWidth() / 2.0);
    }

    static void setCenterY(double y, Node node) {
        node.setLayoutY(y - node.getLayoutBounds().getMinY() - node.getLayoutBounds().getHeight() / 2.0);
    }

    Point2D getCenterPosition();
    Bounds getCanvasBounds();

}
