Skip to content
Snippets Groups Projects
Commit 0a7d9371 authored by Tiziano Munaro's avatar Tiziano Munaro
Browse files

Display labels in ellipses-and-curves editors

parent 42df2ae5
No related branches found
No related tags found
1 merge request!88[3873] Ellipses and Bezier curves
......@@ -7,6 +7,7 @@ LayoutedLineLinkVisual.java 5fc26086e2f63afee403379ba8f09f5113d4c025 YELLOW
LayoutedRectangularContentVisualBase.java 61698ffd771ee2ad798025df8195d1bc09c2c765 YELLOW
NamedLayoutedCircularAnchorageContentVisual.java bf06ac6e93d78e98b0359e0f879dccaefc920aa0 YELLOW
NamedLayoutedCircularAnchorageDiagramVisual.java 53b9d739587d658f65dc03517257d6e29f4ba1fa YELLOW
NamedLayoutedCurveLinkVisual.java 7945b2f550d5e4804f44891294ee60cc8ffcbf1e YELLOW
NamedLayoutedEllipticContentVisual.java f96a956c2f71b675eee56cfc613684397545da68 YELLOW
NamedLayoutedLineLinkVisual.java 60f5d21f0723dc5d08b2ad43bc6361fca83a16aa YELLOW
NamedLayoutedLineLinkVisual.java 4fc48616000516dc90ba22b7069ffdabadc9c377 YELLOW
NamedLayoutedRectangularContentVisual.java 8cdc55b306c1db60074fa8c5c240f95d892e1e32 YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2020 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.visual;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* {@link IVisual} for layouted and named curved links within a diagram. Typically, those are
* {@link IConnection}s.
*
* @author munaro
*/
public class NamedLayoutedCurveLinkVisual<T extends INamedElement & ILayoutedModelElement>
extends LayoutedCurveLinkVisual<T> {
/** Constructor. */
public NamedLayoutedCurveLinkVisual(ILinkMVCBundle mvcb, Class<T> modelType) {
super(mvcb, modelType);
}
/** {@inheritDoc} */
@Override
protected String getLabelText(int currentSegment, int lastSegment) {
return getModelElement().getName();
}
}
......@@ -15,19 +15,18 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.editor.fx.visual;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.kernel.model.INamedElement;
/**
* {@link IVisual} for layouted and named links within a diagram. Typically, those are
* {@link IVisual} for layouted and named straight links within a diagram. Typically, those are
* {@link IConnection}s.
*
* @author diewald
*/
// TODO (TM): See comment in LayoutedLineLinkVisual
public class NamedLayoutedLineLinkVisual<T extends INamedElement & ILayoutedModelElement>
extends LayoutedLineLinkVisual<T> {
......
CircularContentAnchorageVisualBase.java de227ce8a2a14eb4df7bdcf43b82d98f6ff17045 YELLOW
CircularContentVisualBase.java cc3caea328e36e90069b915e413c8e7e9522a939 YELLOW
CircularDiagramAnchorageVisualBase.java 7a3b92fb1b135c218b9a5e16506acfc74a6b5468 YELLOW
CurveLinkVisualBase.java 0b8706214320d715966c86a5242ad21c8bf5a315 YELLOW
CurveSegment.java 445bc2607cb70ae1c788c27ba9fc637dd7df4956 YELLOW
CurveLinkVisualBase.java 5ce3086769004a9eb6800d7eb58379d831ff74b1 YELLOW
CurveSegment.java 0e7f70e9526a74aaec2bec4f4fc16295521cf5f2 YELLOW
EllipticBorderLocation.java 1e9b3d42c7fcd5495004fb30b0c499096a839967 YELLOW
EllipticContentVisualBase.java dc2fddc9cfe5605bc8a5d09dd862845e360b23f5 YELLOW
......@@ -65,7 +65,7 @@ public abstract class CurveLinkVisualBase extends LinkVisualBase {
for(int i = 2; i < pts; i += 3) {
Point2D ep = getBendPointLocation(i);
makeCurve(sp, cp1, cp2, ep, getInvisibleSelectionLineWidth(), markerSize, markerSize,
false, true, 0);
false, true, 0, getLabelText(i, pts + 1));
sp = ep;
cp1 = getBendPointLocation(i + 1);
cp2 = getBendPointLocation(i + 2);
......@@ -76,14 +76,16 @@ public abstract class CurveLinkVisualBase extends LinkVisualBase {
.applyToPoint(getEndAnchorPoint());
// Last bend point is not selectable => set its feedback rectangle size to 0
makeCurve(sp, cp1, cp2, ep, getInvisibleSelectionLineWidth(), 0, markerSize,
showArrowOnLastSegment(), useLineArrow(), getArrowLength());
showArrowOnLastSegment(), useLineArrow(), getArrowLength(),
getLabelText(pts, pts + 1));
endFeedbackHandle.setX(ep.getX() - ms2);
endFeedbackHandle.setY(ep.getY() - ms2);
endFeedbackHandle.setWidth(markerSize);
endFeedbackHandle.setHeight(markerSize);
for(CurveSegment cs : segments) {
cs.addLinkNodes(layers, linkBundle);
cs.addLinkNodes(layers, linkBundle,
getLabelText(segments.indexOf(cs), segments.size()));
}
curvesAddedToSceneGraph = true;
}
......@@ -133,7 +135,8 @@ public abstract class CurveLinkVisualBase extends LinkVisualBase {
// handle bend points
for(int i = 2; i < pts; i += 3) {
Point2D ep = getFeedbackChangeForBendPoint(i).applyToPoint(getBendPointLocation(i));
segments.get(segIndex).update(sp, cp1, cp2, ep, markerSize, markerSize, 0);
segments.get(segIndex).update(sp, cp1, cp2, ep, markerSize, markerSize, 0,
getLabelText(i, pts));
sp = ep;
cp1 = getFeedbackChangeForBendPoint(i + 1).applyToPoint(getBendPointLocation(i + 1));
cp2 = getFeedbackChangeForBendPoint(i + 2).applyToPoint(getBendPointLocation(i + 2));
......@@ -142,7 +145,8 @@ public abstract class CurveLinkVisualBase extends LinkVisualBase {
// end point
Point2D ep = getFeedbackChangeForBendPoint(END_OF_LINK_BEND_POINT_INDEX)
.applyToPoint(getEndAnchorPoint());
segments.get(segIndex).update(sp, cp1, cp2, ep, 0, markerSize, getArrowLength());
segments.get(segIndex).update(sp, cp1, cp2, ep, 0, markerSize, getArrowLength(),
getLabelText(pts, pts));
endFeedbackHandle.setX(ep.getX() - ms2);
endFeedbackHandle.setY(ep.getY() - ms2);
endFeedbackHandle.setWidth(markerSize);
......@@ -338,10 +342,10 @@ public abstract class CurveLinkVisualBase extends LinkVisualBase {
/** Creates the curve segment. */
private void makeCurve(Point2D sp, Point2D cp1, Point2D cp2, Point2D ep, double selWidth,
double bpMarkerSize, double cpMarkerSize, boolean showArrow, boolean useLineArrow,
double arrowLength) {
double arrowLength, String labelText) {
CurveSegment segVis = new CurveSegment(sp.getX(), sp.getY(), cp1.getX(), cp1.getY(),
cp2.getX(), cp2.getY(), ep.getX(), ep.getY(), selWidth, bpMarkerSize, cpMarkerSize,
showArrow, useLineArrow, arrowLength);
showArrow, useLineArrow, arrowLength, labelText);
segments.add(segVis);
}
......@@ -448,4 +452,17 @@ public abstract class CurveLinkVisualBase extends LinkVisualBase {
cs.setMouseTransparent(true);
}
}
/**
* Returns the label text.
*
* @param currentSegment
* the current segment
* @param lastSegment
* the last index of a segment
* @return the label text for the current segment or null for no label
*/
protected String getLabelText(int currentSegment, int lastSegment) {
return null;
}
}
......@@ -13,6 +13,7 @@ import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.GRAY;
import static javafx.scene.paint.Color.RED;
import static javafx.scene.paint.Color.TRANSPARENT;
import static javafx.scene.paint.Color.WHITE;
import static javafx.scene.shape.StrokeLineCap.BUTT;
import static javafx.scene.shape.StrokeLineJoin.ROUND;
......@@ -21,11 +22,17 @@ import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramLayers.ILayer;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.widgets.LinkArrowWidget;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.scene.control.Label;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Paint;
import javafx.scene.shape.CubicCurve;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.TextAlignment;
/**
* This class encapsulates {@link CubicCurve}s usually needed for every segment: a visible one, a
......@@ -48,12 +55,14 @@ final class CurveSegment {
private final Line helperEnd;
/** The arrow widget for curved links. */
private final LinkArrowWidget arrowWidget;
/** Stores the label. */
private Label label;
/** Constructor. */
public CurveSegment(double sx, double sy, double c1x, double c1y, double c2x, double c2y,
double ex, double ey, double selectionStrokeWidth, double bendPointFeedbackSize,
double controlPointFeedbackSize, boolean showArrow, boolean useLineArrow,
double arrowLength) {
double arrowLength, String labelText) {
visibleCurve = new CubicCurve(sx, sy, c1x, c1y, c2x, c2y, ex, ey);
visibleCurve.setStroke(BLACK);
visibleCurve.setFill(null);
......@@ -93,6 +102,12 @@ final class CurveSegment {
} else {
arrowWidget = null;
}
if(labelText != null) {
label = new Label(labelText);
label.setTextAlignment(TextAlignment.CENTER);
} else {
label = null;
}
}
/** Returns the visible curve. */
......@@ -145,7 +160,8 @@ final class CurveSegment {
/** Updates the segment coordinates. */
public void update(Point2D sp, Point2D cp1, Point2D cp2, Point2D ep,
double bendPointFeedbackSize, double controlPointFeedbackSize, double arrowLength) {
double bendPointFeedbackSize, double controlPointFeedbackSize, double arrowLength,
String labelText) {
double sx = sp.getX();
double sy = sp.getY();
visibleCurve.setStartX(sx);
......@@ -196,16 +212,29 @@ final class CurveSegment {
if(arrowWidget != null) {
arrowWidget.update(ex, ey, c2x, c2y, arrowLength);
}
if(label != null) {
label.setText(labelText);
double lx = (sx + ex - label.getBoundsInLocal().getWidth()) / 2;
double ly = (sy + ey) / 2;
label.setLayoutX(lx);
label.setLayoutY(ly);
}
}
/** Adds the link nodes of this segment to the link layer node. */
public void addLinkNodes(DiagramLayers layers, ILinkMVCBundle bundle) {
public void addLinkNodes(DiagramLayers layers, ILinkMVCBundle bundle, String labelText) {
ILayer linkLayer = layers.getLinkLayer();
linkLayer.add(visibleCurve, bundle);
linkLayer.add(clickableCurve, bundle);
if(arrowWidget != null) {
linkLayer.add(arrowWidget, bundle);
}
if(label != null) {
label.setText(labelText);
label.setBackground(
new Background(new BackgroundFill(WHITE, new CornerRadii(0), new Insets(0))));
layers.getTextLayer().add(label, bundle);
}
}
/** Removes the link nodes of this segment from the link layer node. */
......@@ -216,6 +245,9 @@ final class CurveSegment {
if(arrowWidget != null) {
linkLayer.remove(arrowWidget);
}
if(label != null) {
layers.getTextLayer().remove(label);
}
}
/** Adds the feedback nodes of this segment to the feedback layer node. */
......@@ -246,5 +278,8 @@ final class CurveSegment {
if(arrowWidget != null) {
arrowWidget.setMouseTransparent(transparent);
}
if(label != null) {
label.setMouseTransparent(transparent);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment