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

import be.iminds.ilabt.jfed.experimenter_gui.canvas.CanvasNode;
import be.iminds.ilabt.jfed.experimenter_gui.canvas.NewLinkTarget;
import be.iminds.ilabt.jfed.gts.model.impl.FXGtsExternalNetwork;
import be.iminds.ilabt.jfed.gts.model.impl.FXGtsHost;
import be.iminds.ilabt.jfed.gts.model.impl.FXGtsNode;
import be.iminds.ilabt.jfed.gts.model.impl.FXGtsOfx;
import javafx.geometry.Point2D;
import javafx.scene.image.Image;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: twalcari
 * Date: 2/9/2016
 * Time: 16:58
 */
public class GtsCanvasNode extends CanvasNode implements NewLinkTarget {
    private static final Logger LOG = LoggerFactory.getLogger(GtsCanvasNode.class);

    protected final FXGtsNode node;

    public GtsCanvasNode(FXGtsNode node) {
        this.node = node;

        this.textProperty().bind(node.idProperty());
        this.layoutXProperty().bindBidirectional(node.editorXProperty());
        this.layoutYProperty().bindBidirectional(node.editorYProperty());


        if (node instanceof FXGtsOfx) {
            setImage(new Image(GtsCanvasNode.class.getResource("/images/gts_types/64/gts-ofx.png").toExternalForm()));
        } else if (node instanceof FXGtsExternalNetwork) {
            setImage(new Image(GtsCanvasNode.class.getResource("/images/gts_types/64/gts-network.png").toExternalForm()));
        } else if (node instanceof FXGtsHost) {
            setImage(new Image(GtsCanvasNode.class.getResource("/images/gts_types/64/gts-node.png").toExternalForm()));
        } else {
            LOG.error("Unexpected node type: {}", node.getClass().getName());
        }
    }


    public FXGtsNode getNode() {
        return node;
    }

    @Override
    public Point2D getCenterPosition() {
        return new Point2D(NewLinkTarget.getCenterX(this), NewLinkTarget.getCenterY(this));
    }
}
