org.jhotdraw8.draw.handle.LabelConnectorHandle Maven / Gradle / Ivy
Show all versions of org.jhotdraw8.draw Show documentation
/*
* @(#)LabelConnectorHandle.java
* Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
*/
package org.jhotdraw8.draw.handle;
import javafx.geometry.Point2D;
import javafx.scene.Group;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.transform.Transform;
import org.jhotdraw8.draw.DrawingView;
import org.jhotdraw8.draw.connector.Connector;
import org.jhotdraw8.draw.css.value.CssColor;
import org.jhotdraw8.draw.css.value.CssPoint2D;
import org.jhotdraw8.draw.css.value.Paintable;
import org.jhotdraw8.draw.figure.ConnectingFigure;
import org.jhotdraw8.draw.figure.Figure;
import org.jhotdraw8.fxcollection.typesafekey.MapAccessor;
import org.jhotdraw8.fxcollection.typesafekey.NonNullMapAccessor;
import org.jhotdraw8.geom.Angles;
import org.jhotdraw8.geom.FXTransforms;
import org.jhotdraw8.geom.PointAndDerivative;
import org.jspecify.annotations.Nullable;
import java.util.function.Function;
import static java.lang.Math.PI;
/**
* Handle for the start or end point of a connection figure.
*
* Pressing the alt or the control key while dragging the handle prevents
* connecting the point.
*
* @author Werner Randelshofer
*/
public class LabelConnectorHandle extends AbstractConnectorHandle {
protected Background regionBackgroundConnected = new Background(new BackgroundFill(Color.BLUE, null, null));
protected final Background REGION_BACKGROUND_DISCONNECTED = new Background(new BackgroundFill(Color.WHITE, null, null));
private static final Function REGION_BORDER = color -> new Border(
new BorderStroke(Color.WHITE, BorderStrokeStyle.SOLID, null, new BorderWidths(2)),
new BorderStroke(color, BorderStrokeStyle.SOLID, null, null)
);
protected static final Circle REGION_SHAPE = new Circle(4);
protected final Group groupNode;
protected final Region targetNode;
protected final Line lineNode;
protected final NonNullMapAccessor originKey;
protected @Nullable Point2D connectorDerivative;
public LabelConnectorHandle(ConnectingFigure figure,
NonNullMapAccessor originKey,
NonNullMapAccessor pointKey,
MapAccessor connectorKey,
MapAccessor