Skip to content
Snippets Groups Projects
Commit 8de572fb authored by Ulrich Schöpp's avatar Ulrich Schöpp
Browse files

Improve code


Signed-off-by: default avatarUlrich Schöpp <schoepp@fortiss.org>
Issue-Ref: 4184
parent 6f5c1902
No related branches found
No related tags found
1 merge request!166Polish diagram appearance
Pipeline #32213 failed
......@@ -7,7 +7,7 @@ LayoutedLineLinkVisual.java 5fc26086e2f63afee403379ba8f09f5113d4c025 GREEN
LayoutedRectangularAnchorageContentVisualBase.java 9d5ab8fbad2900a26ec5ea620f9f1a2a1656da77 GREEN
LayoutedRectangularAnchorageDiagramVisualBase.java b9aa51cce71d8f6c4e400f6019b3cab0a1ed6df6 GREEN
LayoutedRectangularContentVisualBase.java 61698ffd771ee2ad798025df8195d1bc09c2c765 GREEN
NamedLayoutedCircularAnchorageContentVisual.java 070b45fdae674995a3063f93bcc572facd934df7 YELLOW
NamedLayoutedCircularAnchorageContentVisual.java 5cfa7d14fec6835ff0167bbe5faf9f8ad8f6577b YELLOW
NamedLayoutedCircularAnchorageDiagramVisual.java eb1e736d7715b86dbc3ca0551bb754157f71cc5f GREEN
NamedLayoutedCurveLinkVisual.java 7945b2f550d5e4804f44891294ee60cc8ffcbf1e GREEN
NamedLayoutedEllipticContentVisual.java f96a956c2f71b675eee56cfc613684397545da68 GREEN
......
......@@ -17,10 +17,7 @@ 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.IConnection;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.base.model.element.IHierarchicElementContainer;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramLayers;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
......@@ -28,8 +25,6 @@ import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisual;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.widgets.AlignedText;
import org.fortiss.tooling.kernel.model.INamedElement;
import com.google.common.base.Predicate;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
......@@ -57,66 +52,59 @@ public class NamedLayoutedCircularAnchorageContentVisual<T extends ILayoutedMode
super.updateNodes(layers);
if(enableName()) {
nameText.setText(getName());
updateNameTextPosition();
if(nameText.getParent() == null) {
layers.getVisualFeedbackLayer().add(nameText, getMVCBundle());
}
} else if(nameText.getParent() != null) {
layers.getVisualFeedbackLayer().remove(nameText);
}
}
// Depending on the side, place the text off to the side.
Rectangle2D bounds = getCurrentBounds();
Rectangle2D attachedToBounds =
getMVCBundle().getAttachedTo().getVisual().getCurrentBounds();
if(bounds.getMaxX() >= attachedToBounds.getMinX() &&
bounds.getMinX() < attachedToBounds.getMinX()) {
// left
if(!hasConnection()) {
/**
* Sets the position of the label text.
* Depending on the side, the text is placed off to the side.
*/
private void updateNameTextPosition() {
Rectangle2D bounds = getCurrentBounds();
switch(getSide()) {
case LEFT:
if(stickyConnectorHasVisibleConnections(getModelElement())) {
// 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);
} else {
nameText.setX(bounds.getMinX() + bounds.getWidth() / 4);
}
break;
case RIGHT:
if(stickyConnectorHasVisibleConnections(getModelElement())) {
// 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_RIGHT);
nameText.setAlignment(Pos.BOTTOM_LEFT);
} else {
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMinY() + bounds.getHeight() / 2);
nameText.setAlignment(Pos.CENTER_LEFT);
}
} else if(bounds.getMaxY() >= attachedToBounds.getMinY() &&
bounds.getMinY() < attachedToBounds.getMinY()) {
// top
break;
case TOP:
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMinY());
nameText.setAlignment(Pos.BOTTOM_CENTER);
} else if(bounds.getMinY() <= attachedToBounds.getMaxY() &&
bounds.getMaxY() > attachedToBounds.getMaxY()) {
// bottom
break;
case BOTTOM:
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMaxY());
nameText.setAlignment(Pos.TOP_CENTER);
} else {
// right
if(!hasConnection()) {
nameText.setX(bounds.getMaxX());
nameText.setY(bounds.getMinY() + bounds.getHeight() / 2);
nameText.setAlignment(Pos.CENTER_LEFT);
} else {
nameText.setX(bounds.getMaxX() - bounds.getWidth() / 4);
nameText.setY(bounds.getMinY() + bounds.getHeight() / 4);
nameText.setAlignment(Pos.BOTTOM_LEFT);
}
}
if(nameText.getParent() == null) {
layers.getVisualFeedbackLayer().add(nameText, getMVCBundle());
}
} else if(nameText.getParent() != null) {
layers.getVisualFeedbackLayer().remove(nameText);
break;
}
}
/** Does the port have a connection at this level? */
private boolean hasConnection() {
T port = getModelElement();
IHierarchicElement element = port.getOwner();
IHierarchicElementContainer container = element.getContainer();
Predicate<IConnection> atSameLevel = connection -> container.equals(connection.getOwner());
return port.getIncoming().stream().anyMatch(atSameLevel) ||
port.getOutgoing().stream().anyMatch(atSameLevel);
}
/** {@inheritDoc} */
@Override
public void removeAllVisuals(DiagramLayers layers) {
......
AlignedText.java f8bc913c77862b650d3f73de6309e71afb4b46b4 YELLOW
AlignedText.java 746933b14b345b773361e94208d31c27d816f436 YELLOW
ExpandCollapseWidget.java f431b6a86f3ce1794c55b90f39a15cda4f92ea06 GREEN
LinkArrowWidget.java 5354f14ca9d53cc3df88afb1867a266dfde65199 GREEN
......@@ -17,7 +17,6 @@ package org.fortiss.tooling.common.ui.javafx.lwfxef.visual.widgets;
import javafx.geometry.Bounds;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
......@@ -30,7 +29,7 @@ public class AlignedText extends Text {
/**
* The alignment to be achieved by setting the translation.
*/
private Pos alignment = Pos.BOTTOM_LEFT;
private Pos alignment = Pos.TOP_LEFT;
/**
*
......@@ -38,9 +37,8 @@ public class AlignedText extends Text {
public AlignedText() {
super();
this.setTextAlignment(TextAlignment.LEFT);
this.setTextOrigin(VPos.TOP);
updatePosition();
this.boundsInLocalProperty().addListener(o -> updatePosition());
this.baselineOffsetProperty().addListener(o -> updatePosition());
}
/** Returns alignment. */
......@@ -57,21 +55,17 @@ public class AlignedText extends Text {
/** Sets the translation. */
private void updatePosition() {
Bounds bounds = getBoundsInLocal();
double translateX = 0;
switch(alignment.getHpos()) {
case LEFT:
translateX = 0;
setTranslateX(0);
break;
case CENTER:
translateX = -bounds.getWidth() / 2;
setTranslateX(-bounds.getWidth() / 2);
break;
case RIGHT:
translateX = -bounds.getWidth();
setTranslateX(-bounds.getWidth());
break;
}
setTranslateX(translateX);
setTextOrigin(alignment.getVpos());
}
}
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