Skip to content
Snippets Groups Projects
Commit 9262c9cd authored by Simon Barner's avatar Simon Barner
Browse files

Merge branch '4184' into 'master'

Polish diagram appearance

See merge request !166
parents 0a6c9702 5f10e996
Branches
Tags
1 merge request!166Polish diagram appearance
Showing
with 272 additions and 152 deletions
AnchorageText.java d857c045a26a4b73f87adfd2773425460774ab2f GREEN
CoordinateCorrections.java 018bf229e5686afcb8540b61dd9d05b6e4a23e93 GREEN
LayoutedCircularAnchorageContentVisualBase.java bf71e5e84ede0c26bd0632e4218aae55ab915ade GREEN
LayoutedCircularAnchorageDiagramVisualBase.java 7634416bcb88a014d985143bf00a8d29ff1e3ff5 GREEN
......@@ -7,11 +8,11 @@ LayoutedLineLinkVisual.java 5fc26086e2f63afee403379ba8f09f5113d4c025 GREEN
LayoutedRectangularAnchorageContentVisualBase.java 9d5ab8fbad2900a26ec5ea620f9f1a2a1656da77 GREEN
LayoutedRectangularAnchorageDiagramVisualBase.java b9aa51cce71d8f6c4e400f6019b3cab0a1ed6df6 GREEN
LayoutedRectangularContentVisualBase.java 61698ffd771ee2ad798025df8195d1bc09c2c765 GREEN
NamedLayoutedCircularAnchorageContentVisual.java 5ba0b5d133998eac47425696ef0a02b575418c2d GREEN
NamedLayoutedCircularAnchorageContentVisual.java 853ddce0e1519cbc6284776dffcdeaf64ae358b1 GREEN
NamedLayoutedCircularAnchorageDiagramVisual.java eb1e736d7715b86dbc3ca0551bb754157f71cc5f GREEN
NamedLayoutedCurveLinkVisual.java 7945b2f550d5e4804f44891294ee60cc8ffcbf1e GREEN
NamedLayoutedEllipticContentVisual.java f96a956c2f71b675eee56cfc613684397545da68 GREEN
NamedLayoutedLineLinkVisual.java 4fc48616000516dc90ba22b7069ffdabadc9c377 GREEN
NamedLayoutedRectangularAnchorageContentVisual.java 35dcce7f97e051be21768f70c278b6e560e79a41 GREEN
NamedLayoutedRectangularAnchorageContentVisual.java 4c699f6e7f32339397b302d390744e5ebf2443d7 GREEN
NamedLayoutedRectangularAnchorageDiagramVisual.java 9a143987f3990d970fa7239fcf5c768e113b6320 GREEN
NamedLayoutedRectangularContentVisual.java 8cdc55b306c1db60074fa8c5c240f95d892e1e32 GREEN
/*-------------------------------------------------------------------------+
| Copyright 2021 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 static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.stickyConnectorHasVisibleConnections;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramLayers;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.layout.ISideLayout;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IAnchorageVisual;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.widgets.AlignedText;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
/**
* Manages visual node(s) for the display of anchorage text labels.
*
* @author schoepp
*/
/* package */ class AnchorageText {
/** The text displaying the anchorage name. */
AlignedText nameText;
/** Constructor. */
public AnchorageText() {
this.nameText = new AlignedText();
nameText.setMouseTransparent(true);
}
/**
* Update the text nodes with the data from the given anchorage visual,
* the model element and the given text. Place the nodes on the given layers.
*/
public <V extends IAnchorageVisual & ISideLayout> //
void updateNodes(V visual, IConnector connector, String text, DiagramLayers layers) {
nameText.setText(text);
updateNameTextPosition(visual, connector);
if(nameText.getParent() == null) {
layers.getVisualFeedbackLayer().add(nameText, visual.getMVCBundle());
}
}
/** Sets the position of the text. Depending on the side, the text is placed off to the side. */
private <V extends IAnchorageVisual & ISideLayout> //
void updateNameTextPosition(V visual, IConnector connector) {
Rectangle2D bounds = visual.getCurrentBounds();
switch(visual.getSide()) {
case LEFT:
if(stickyConnectorHasVisibleConnections(connector)) {
// move the text a little to the side if there is a connection
nameText.setX(bounds.getMinX() + bounds.getWidth() / 4);
nameText.setY(bounds.getMinY() + bounds.getHeight() / 4);
nameText.setAlignment(Pos.BOTTOM_RIGHT);
} else {
nameText.setX(bounds.getMinX());
nameText.setY(bounds.getMinY() + bounds.getHeight() / 2);
nameText.setAlignment(Pos.CENTER_RIGHT);
}
break;
case RIGHT:
if(stickyConnectorHasVisibleConnections(connector)) {
// move the text a little to the side if there is a connection
nameText.setX(bounds.getMaxX() - bounds.getWidth() / 4);
nameText.setY(bounds.getMinY() + bounds.getHeight() / 4);
nameText.setAlignment(Pos.BOTTOM_LEFT);
} else {
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMinY() + bounds.getHeight() / 2);
nameText.setAlignment(Pos.CENTER_LEFT);
}
break;
case TOP:
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMinY());
nameText.setAlignment(Pos.BOTTOM_CENTER);
break;
case BOTTOM:
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMaxY());
nameText.setAlignment(Pos.TOP_CENTER);
break;
}
}
/** Remove the text from layers; do nothing if the text is not placed on any node. */
public void removeAllVisuals(DiagramLayers layers) {
if(nameText.getParent() != null) {
layers.getVisualFeedbackLayer().remove(nameText);
}
}
}
......@@ -24,11 +24,6 @@ import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundl
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.geometry.Rectangle2D;
import javafx.geometry.VPos;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
/**
* {@link IVisual} for layouted and named {@link IConnector}s of some content element within a
* diagram (sticky connectors).
......@@ -38,15 +33,12 @@ import javafx.scene.text.TextAlignment;
public class NamedLayoutedCircularAnchorageContentVisual<T extends ILayoutedModelElement & INamedElement & IConnector>
extends LayoutedCircularAnchorageContentVisualBase<T> {
/** The name text label. */
private final Text nameText = new Text("");
private final AnchorageText nameText = new AnchorageText();
/** Constructor. */
public NamedLayoutedCircularAnchorageContentVisual(IContentAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb, modelType);
nameText.setMouseTransparent(true);
nameText.setTextAlignment(TextAlignment.LEFT);
nameText.setTextOrigin(VPos.CENTER);
}
/** {@inheritDoc} */
......@@ -54,16 +46,17 @@ public class NamedLayoutedCircularAnchorageContentVisual<T extends ILayoutedMode
public void updateNodes(DiagramLayers layers) {
super.updateNodes(layers);
if(enableName()) {
Rectangle2D bounds = getCurrentBounds();
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMinY() + bounds.getHeight() / 2);
nameText.setText(getName());
if(nameText.getParent() == null) {
layers.getVisualFeedbackLayer().add(nameText, getMVCBundle());
nameText.updateNodes(this, getModelElement(), getName(), layers);
} else {
nameText.removeAllVisuals(layers);
}
} else if(nameText.getParent() != null) {
layers.getVisualFeedbackLayer().remove(nameText);
}
/** {@inheritDoc} */
@Override
public void removeAllVisuals(DiagramLayers layers) {
super.removeAllVisuals(layers);
nameText.removeAllVisuals(layers);
}
/** Returns whether the name label should be enabled. */
......
......@@ -24,29 +24,21 @@ import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundl
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.kernel.model.INamedElement;
import javafx.geometry.Rectangle2D;
import javafx.geometry.VPos;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
/**
* {@link IVisual} for layouted and named {@link IConnector}s (as rectangles) of some content element within a
* diagram (sticky connectors).
* {@link IVisual} for layouted and named {@link IConnector}s (as rectangles) of some content
* element within a diagram (sticky connectors).
*
* @author barner
*/
public class NamedLayoutedRectangularAnchorageContentVisual<T extends ILayoutedModelElement & INamedElement & IConnector>
extends LayoutedRectangularAnchorageContentVisualBase<T> {
/** The name text label. */
private final Text nameText = new Text("");
private final AnchorageText nameText = new AnchorageText();
/** Constructor. */
public NamedLayoutedRectangularAnchorageContentVisual(IContentAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb, modelType);
nameText.setMouseTransparent(true);
nameText.setTextAlignment(TextAlignment.LEFT);
nameText.setTextOrigin(VPos.CENTER);
}
/** {@inheritDoc} */
......@@ -54,16 +46,17 @@ public class NamedLayoutedRectangularAnchorageContentVisual<T extends ILayoutedM
public void updateNodes(DiagramLayers layers) {
super.updateNodes(layers);
if(enableName()) {
Rectangle2D bounds = getCurrentBounds();
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMinY() + bounds.getHeight() / 2);
nameText.setText(getName());
if(nameText.getParent() == null) {
layers.getVisualFeedbackLayer().add(nameText, getMVCBundle());
nameText.updateNodes(this, getModelElement(), getName(), layers);
} else {
nameText.removeAllVisuals(layers);
}
} else if(nameText.getParent() != null) {
layers.getVisualFeedbackLayer().remove(nameText);
}
/** {@inheritDoc} */
@Override
public void removeAllVisuals(DiagramLayers layers) {
super.removeAllVisuals(layers);
nameText.removeAllVisuals(layers);
}
/** Returns whether the name label should be enabled. */
......
AutoLayoutMenu.java 67dc2d04a6f39ec72ea640b745997baa8ff63a49 GREEN
DiagramTapeMeasure.java 72454e6fe5225dab11d3d691baad93aab7a171c0 GREEN
DiagramTapeMeasure.java d607529c055a9f0f8857c4f7923e244a7e2199cd GREEN
IAutoLayouter.java de1b11d9e202c7e23352ad85684dbf8a3fd17c7d GREEN
IAutoLayouterTapeMeasure.java df186e0ba505e0ecda211b1df76cf12f3245b47e GREEN
KielerAutoLayouter.java cb01df7d05830b95b595d7f1aec53a801812e5b6 GREEN
IAutoLayouterTapeMeasure.java 9781aedaab3a85370542aacee9c49475ad7586c5 GREEN
KielerAutoLayouter.java be19c05c98ff036a6d9552523b7f490a3029bbfc GREEN
......@@ -23,12 +23,6 @@ import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeSize;
import static org.fortiss.tooling.kernel.ui.util.KernelUIUtils.getName;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.fortiss.tooling.base.model.base.EntryConnectorBase;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
......@@ -37,8 +31,9 @@ import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.model.layout.Dimension;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.ui.editor.DiagramEditorBase;
import org.fortiss.tooling.base.ui.editpart.ConnectionEditPartBase;
import org.fortiss.tooling.base.ui.editpart.ElementEditPartBase;
import javafx.geometry.Bounds;
import javafx.scene.text.Text;
/**
* {@link IAutoLayouterTapeMeasure} specialization to for automatic layout of models to be displayed
......@@ -48,54 +43,14 @@ import org.fortiss.tooling.base.ui.editpart.ElementEditPartBase;
*/
public class DiagramTapeMeasure implements IAutoLayouterTapeMeasure {
/** {@link EditPartViewer} used to display the underlying diagram. */
private EditPartViewer diagramEpv;
/** Underlying GC. */
private GC gc;
/** Constructor. */
public DiagramTapeMeasure(EditPartViewer epv, GC gc) {
this.diagramEpv = epv;
this.gc = gc;
}
/** Returns the {@code Font} used by the given {@code element} (may be {@code null}). */
private Font getFont(IModelElement element) {
if(diagramEpv == null) {
return null;
}
Object ep = diagramEpv.getEditPartRegistry().get(element);
if(ep instanceof ElementEditPartBase) {
Label label = ((ElementEditPartBase<?>)ep).createLabelFigure();
if(label != null) {
return label.getFont();
}
} else if(ep instanceof ConnectionEditPartBase) {
IFigure figure = ((ConnectionEditPartBase<?>)ep).getFigure();
if(figure != null) {
return figure.getFont();
}
}
return null;
}
/** Returns the text extend of the given {@code element}'s label (may be {@code null}). */
private Point getTextExtent(IModelElement element) {
if(gc == null) {
return null;
}
/**
* Returns the an estimation of the text extent of the given {@code element}'s label (may be
* {@code null}).
*/
private Bounds getTextExtent(IModelElement element) {
String name = getName(element);
if(name == null) {
return null;
}
gc.setFont(getFont(element));
Point rval = gc.textExtent(name);
return rval;
Text text = new Text(name);
return text.getBoundsInLocal();
}
/** {@inheritDoc} */
......@@ -104,9 +59,9 @@ public class DiagramTapeMeasure implements IAutoLayouterTapeMeasure {
Dimension dimension = getNodeSize((ILayoutedModelElement)element);
int width = max(DEFAULT_SHAPE_MINIMUM_WIDTH, dimension.getWidth());
Point textExtend = getTextExtent(element);
if(textExtend != null) {
width = max(width, textExtend.x + 6 * DEFAULT_GRID_SIZE);
Bounds textExtent = getTextExtent(element);
if(textExtent != null) {
width = max(width, (int)textExtent.getWidth() + 6 * DEFAULT_GRID_SIZE);
}
return width;
......@@ -127,19 +82,26 @@ public class DiagramTapeMeasure implements IAutoLayouterTapeMeasure {
/** {@inheritDoc} */
@Override
public int getConnectorWidth(IConnector connector) {
return 2 * DEFAULT_CONNECTOR_SIZE;
return DEFAULT_CONNECTOR_SIZE;
}
/** {@inheritDoc} */
@Override
public int getConnectorHeight(IConnector connector) {
return 2 * DEFAULT_CONNECTOR_SIZE;
return DEFAULT_CONNECTOR_SIZE;
}
/** {@inheritDoc} */
@Override
public int getConnectionWidth(IConnection connection) {
Point textExtend = getTextExtent(connection);
return textExtend != null ? textExtend.x : 0;
Bounds textExtend = getTextExtent(connection);
return textExtend != null ? (int)textExtend.getWidth() : 0;
}
/** {@inheritDoc} */
@Override
public int getConnectorLabelWidth(IConnector connector) {
Bounds textExtend = getTextExtent(connector);
return textExtend != null ? (int)textExtend.getWidth() : 0;
}
}
......@@ -38,6 +38,9 @@ public interface IAutoLayouterTapeMeasure {
/** Estimates the height requirements of the given connector. */
public int getConnectorHeight(IConnector connector);
/** Estimates the width requirements for the label of the given connector. */
public int getConnectorLabelWidth(IConnector connector);
/** Estimates the width requirements of the given connection. */
public int getConnectionWidth(IConnection connection);
}
......@@ -37,6 +37,7 @@ import org.eclipse.elk.core.AbstractLayoutProvider;
import org.eclipse.elk.core.data.LayoutMetaDataService;
import org.eclipse.elk.core.options.Direction;
import org.eclipse.elk.core.options.EdgeRouting;
import org.eclipse.elk.core.options.PortLabelPlacement;
import org.eclipse.elk.core.options.PortSide;
import org.eclipse.elk.core.util.BasicProgressMonitor;
import org.eclipse.elk.graph.ElkEdge;
......@@ -48,9 +49,6 @@ import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.BasicEMap;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.swt.graphics.GC;
import org.fortiss.tooling.base.model.base.EntryConnectorBase;
import org.fortiss.tooling.base.model.base.ExitConnectorBase;
import org.fortiss.tooling.base.model.element.IConnection;
......@@ -61,11 +59,9 @@ import org.fortiss.tooling.base.model.layout.ILayoutData;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Points;
import org.fortiss.tooling.base.model.layout.impl.PointsImpl;
import org.fortiss.tooling.base.ui.editor.DiagramEditorBase;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
import org.fortiss.tooling.kernel.ui.extension.IModelEditor;
import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService;
/**
* <p>
......@@ -117,9 +113,13 @@ public class KielerAutoLayouter implements IAutoLayouter {
rootNode.setProperty(LayeredOptions.INTERACTIVE_LAYOUT, true);
rootNode.setProperty(LayeredOptions.FEEDBACK_EDGES, true);
rootNode.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
rootNode.setProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, 100.0);
rootNode.setProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS,
5.0 * DEFAULT_GRID_SIZE);
rootNode.setProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS,
2.0 * DEFAULT_GRID_SIZE);
rootNode.setProperty(LayeredOptions.INTERACTIVE_REFERENCE_POINT,
InteractiveReferencePoint.TOP_LEFT);
rootNode.setProperty(LayeredOptions.PORT_LABELS_PLACEMENT, PortLabelPlacement.outside());
AbstractLayoutProvider layoutProvider = new LayeredLayoutProvider();
BasicProgressMonitor progressMonitor = new BasicProgressMonitor();
......@@ -220,9 +220,8 @@ public class KielerAutoLayouter implements IAutoLayouter {
IConnector connector = entry.getKey();
ElkPort elkPort = entry.getValue();
ElkNode tempNode = elkPort.getParent();
setNodePosition((ILayoutedModelElement)connector,
truncateSnap2Grid(tempNode.getX(), true),
truncateSnap2Grid(tempNode.getY(), true));
setNodePosition((ILayoutedModelElement)connector, truncateSnap2Grid(tempNode.getX()),
truncateSnap2Grid(tempNode.getY()));
}
}
......@@ -276,19 +275,6 @@ public class KielerAutoLayouter implements IAutoLayouter {
}
}
/**
* Opens the given {@link IHierarchicElement} in an editor. Returns the editor in case it is a
* {@link DiagramEditorBase}-based, {@code null} otherwise.
*/
private EditPartViewer getDiagramEditPartViewer(IHierarchicElement element) {
IModelEditorBindingService es = IModelEditorBindingService.getInstance();
es.openInEditor(element);
IModelEditor<EObject> editor = es.getActiveEditor();
boolean isDiagramEditor = editor instanceof DiagramEditorBase;
return isDiagramEditor ? ((DiagramEditorBase<?>)editor).getViewer() : null;
}
/**
* Creates a KIELER {@link ElkNode} graph with the same structure as the given
* {@link IHierarchicElement}.
......@@ -310,9 +296,7 @@ public class KielerAutoLayouter implements IAutoLayouter {
connectionsToElkEdges = new BasicEMap<IConnection, ElkEdge>();
undirectedConnectorsToElkPorts = new BasicEMap<IConnector, ElkPort>();
EditPartViewer viewer = getDiagramEditPartViewer(element);
GC gc = viewer != null ? new GC(viewer.getControl()) : null;
IAutoLayouterTapeMeasure tapeMeasure = new DiagramTapeMeasure(viewer, gc);
IAutoLayouterTapeMeasure tapeMeasure = new DiagramTapeMeasure();
// Create nodes
for(IHierarchicElement child : element.getContainedElements()) {
......@@ -343,14 +327,15 @@ public class KielerAutoLayouter implements IAutoLayouter {
}
}
for(IConnector connector : outputConnectors) {
ElkPort k =
createKPortFromIConnector(connector, elkNode, outboundConnectorsToElkPorts);
ElkPort k = createKPortFromIConnector(tapeMeasure, connector, elkNode,
outboundConnectorsToElkPorts);
if(undirectedConnectors.contains(connector)) {
undirectedConnectorsToElkPorts.put(connector, k);
}
}
for(IConnector connector : inputConnectors) {
createKPortFromIConnector(connector, elkNode, inboundConnectorsToElkPorts);
createKPortFromIConnector(tapeMeasure, connector, elkNode,
inboundConnectorsToElkPorts);
}
}
......@@ -368,12 +353,15 @@ public class KielerAutoLayouter implements IAutoLayouter {
globalOutboundConnectorsToElkPorts.put(connector, elkPort);
} else {
globalInboundConnectorsToElkPorts.put(connector, elkPort);
outboundConnectorsToElkPorts.put(connector, elkPort);
}
}
EMap<IConnector, ElkPort> sourceConnectors = new BasicEMap<>();
sourceConnectors.putAll(outboundConnectorsToElkPorts);
sourceConnectors.putAll(globalInboundConnectorsToElkPorts);
// Create edges
for(Entry<IConnector, ElkPort> entry : outboundConnectorsToElkPorts) {
for(Entry<IConnector, ElkPort> entry : sourceConnectors) {
for(IConnection connection : entry.getKey().getOutgoing()) {
ElkPort kSourcePort = entry.getValue();
......@@ -395,9 +383,6 @@ public class KielerAutoLayouter implements IAutoLayouter {
}
}
if(gc != null) {
gc.dispose();
}
return rootNode;
}
......@@ -407,6 +392,8 @@ public class KielerAutoLayouter implements IAutoLayouter {
* {@link IConnector})
* and a {@link IConnector}-to- {@link ElkPort} map.
*
* @param tapeMeasure
* {@link IAutoLayouterTapeMeasure} to estimate the label width
* @param connector
* {@link IConnector} to be converted to {@link ElkPort}
* @param elkNode
......@@ -416,12 +403,19 @@ public class KielerAutoLayouter implements IAutoLayouter {
*
* @return {@link ElkNode} representing the given {@link IConnector}.
*/
private ElkPort createKPortFromIConnector(IConnector connector, ElkNode elkNode,
EMap<IConnector, ElkPort> connectorsToelkPorts) {
private ElkPort createKPortFromIConnector(IAutoLayouterTapeMeasure tapeMeasure,
IConnector connector, ElkNode elkNode, EMap<IConnector, ElkPort> connectorsToelkPorts) {
ElkPort elkPort = createPort(elkNode);
elkPort.setParent(elkNode);
elkPort.setHeight(DEFAULT_CONNECTOR_SIZE);
if(connector instanceof INamedElement) {
ElkLabel elkPortLabel = createLabel(elkPort);
String name = ((INamedElement)connector).getName();
elkPortLabel.setWidth(tapeMeasure.getConnectorLabelWidth(connector));
elkPortLabel.setText(name);
}
connectorsToelkPorts.put(connector, elkPort);
return elkPort;
}
......
DiamondContentVisualBase.java a81e76e85706ad38b6c22bbcd1cc5a5696737e3d GREEN
LineLinkGraph.java 85a06a553f88f7b9fb4bd9c06411725d9fb160fc GREEN
LineLinkVisualBase.java 876d6872b1844568f055809b975d2471330f719f GREEN
LineSegment.java 9ab1b97ad372db763654ef783747fa0733bec55c GREEN
LineSegment.java 920caf921de967f06ce2d9b0a5a0190ac93f7830 GREEN
RectangularBorderLocation.java 824472c353534d1094ae4f735a30a231b885f050 GREEN
RectangularContentAnchorageVisualBase.java 39981dc29cac42d77c6ffe855ecc8ccad1689230 GREEN
RectangularContentVisualBase.java aeeda282f330180b1f339e3230810eccea2e7e7b GREEN
......
......@@ -14,9 +14,11 @@ import static javafx.scene.paint.Color.TRANSPARENT;
import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramLayers;
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.AlignedText;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.widgets.LinkArrowWidget;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
......@@ -46,7 +48,7 @@ final class LineSegment {
/** The arrow head widget. */
private final LinkArrowWidget arrowWidget;
/** Stores the label. */
private Text label;
private AlignedText label;
/** Stores the simulation label */
private Text simulationLabel;
/** Offset of simulation label in y direction. */
......@@ -83,9 +85,9 @@ final class LineSegment {
arrowWidget = null;
}
if(labelText != null) {
label = new Text(labelText);
label.setTextAlignment(TextAlignment.CENTER);
label.setTextOrigin(VPos.TOP);
label = new AlignedText();
label.setText(labelText);
label.setAlignment(Pos.BOTTOM_CENTER);
} else {
label = null;
}
......@@ -130,8 +132,7 @@ final class LineSegment {
if(label != null) {
label.setText(labelText);
double lx = (visibleLine.getStartX() + visibleLine.getEndX() -
label.getBoundsInLocal().getWidth()) / 2;
double lx = (visibleLine.getStartX() + visibleLine.getEndX()) / 2;
double ly = (visibleLine.getStartY() + visibleLine.getEndY()) / 2;
label.setX(lx);
label.setY(ly);
......@@ -146,9 +147,7 @@ final class LineSegment {
interactionLayer.add(clickableLine, bundle);
}
/**
* Sets the text of the simulation label below the label of the line.
*/
/** Sets the text of the simulation label below the label of the line. */
private void setSimulationLabel(String simulationLabelText, double lx, double ly,
double yOffset) {
simulationLabel.setText(simulationLabelText);
......@@ -224,7 +223,7 @@ final class LineSegment {
}
if(label != null) {
label.setText(labelText);
double lx = (sx + ex - label.getBoundsInLocal().getWidth()) / 2;
double lx = (sx + ex) / 2;
double ly = (sy + ey) / 2;
label.setX(lx);
label.setY(ly);
......
AlignedText.java 1c0bae7d18c93e7645dbb09d70632d5351dc8f38 GREEN
ExpandCollapseWidget.java f431b6a86f3ce1794c55b90f39a15cda4f92ea06 GREEN
LinkArrowWidget.java 5354f14ca9d53cc3df88afb1867a266dfde65199 GREEN
/*-------------------------------------------------------------------------+
| Copyright 2021 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.common.ui.javafx.lwfxef.visual.widgets;
import javafx.geometry.Bounds;
import javafx.geometry.Pos;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
/**
* Text shape that automatically sets its translation to achieve text alignment.
*
* @author schoepp
*/
public class AlignedText extends Text {
/** The alignment to be achieved by setting the translation. */
private Pos alignment = Pos.TOP_LEFT;
/** Constructor. */
public AlignedText() {
super();
this.setTextAlignment(TextAlignment.LEFT);
updatePosition();
this.boundsInLocalProperty().addListener(o -> updatePosition());
}
/** Returns alignment. */
public Pos getAlignment() {
return alignment;
}
/** Sets alignment. */
public void setAlignment(Pos alignment) {
this.alignment = alignment;
updatePosition();
}
/** Sets the translation. */
private void updatePosition() {
Bounds bounds = getBoundsInLocal();
switch(alignment.getHpos()) {
case LEFT:
setTranslateX(0);
break;
case CENTER:
setTranslateX(-bounds.getWidth() / 2);
break;
case RIGHT:
setTranslateX(-bounds.getWidth());
break;
}
setTextOrigin(alignment.getVpos());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment