diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/.ratings index 87268daa9dfeb907bf0b79a81d06eb4cbe9da6fe..fb68c914d2f2a86e204431e75a68394825817a46 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/.ratings @@ -5,8 +5,8 @@ LayoutedCurveLinkVisual.java 5b06cd7e80eaf7cf6af37a4769eaafe2a1e591f3 GREEN LayoutedEllipticContentVisualBase.java 6f3daf386d5120793b90ce4569dd9bea33dd2a0f GREEN LayoutedLineLinkVisual.java 5fc26086e2f63afee403379ba8f09f5113d4c025 GREEN LayoutedRectangularContentVisualBase.java 61698ffd771ee2ad798025df8195d1bc09c2c765 GREEN -NamedLayoutedCircularAnchorageContentVisual.java bf06ac6e93d78e98b0359e0f879dccaefc920aa0 GREEN -NamedLayoutedCircularAnchorageDiagramVisual.java 53b9d739587d658f65dc03517257d6e29f4ba1fa GREEN +NamedLayoutedCircularAnchorageContentVisual.java 5ba0b5d133998eac47425696ef0a02b575418c2d GREEN +NamedLayoutedCircularAnchorageDiagramVisual.java 94eccb7bb03c5518ae875e9972f062ddd0e1f62d GREEN NamedLayoutedCurveLinkVisual.java 7945b2f550d5e4804f44891294ee60cc8ffcbf1e GREEN NamedLayoutedEllipticContentVisual.java f96a956c2f71b675eee56cfc613684397545da68 GREEN NamedLayoutedLineLinkVisual.java 4fc48616000516dc90ba22b7069ffdabadc9c377 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/NamedLayoutedCircularAnchorageContentVisual.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/NamedLayoutedCircularAnchorageContentVisual.java index bf06ac6e93d78e98b0359e0f879dccaefc920aa0..5ba0b5d133998eac47425696ef0a02b575418c2d 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/NamedLayoutedCircularAnchorageContentVisual.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/NamedLayoutedCircularAnchorageContentVisual.java @@ -15,29 +15,64 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.ui.editor.fx.visual; -import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle; -import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisual; +import static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.stickyConnectorHasVisibleConnections; + import org.fortiss.tooling.base.model.element.IConnector; 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; +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). * * @author diewald */ -public class NamedLayoutedCircularAnchorageContentVisual<T extends ILayoutedModelElement & INamedElement> +public class NamedLayoutedCircularAnchorageContentVisual<T extends ILayoutedModelElement & INamedElement & IConnector> extends LayoutedCircularAnchorageContentVisualBase<T> { + /** The name text label. */ + private final Text nameText = new Text(""); /** Constructor. */ - public NamedLayoutedCircularAnchorageContentVisual(IContentAnchorageMVCBundle mvcb, Class<T> modelType) { + public NamedLayoutedCircularAnchorageContentVisual(IContentAnchorageMVCBundle mvcb, + Class<T> modelType) { super(mvcb, modelType); + nameText.setMouseTransparent(true); + nameText.setTextAlignment(TextAlignment.LEFT); + nameText.setTextOrigin(VPos.CENTER); } /** {@inheritDoc} */ @Override - protected String getHoverText() { + 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()); + } + } else if(nameText.getParent() != null) { + layers.getVisualFeedbackLayer().remove(nameText); + } + } + + /** Returns whether the name label should be enabled. */ + public boolean enableName() { + return !stickyConnectorHasVisibleConnections(getModelElement()); + } + + /** Returns the name. */ + public String getName() { return getModelElement().getName(); } } diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/NamedLayoutedCircularAnchorageDiagramVisual.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/NamedLayoutedCircularAnchorageDiagramVisual.java index 53b9d739587d658f65dc03517257d6e29f4ba1fa..94eccb7bb03c5518ae875e9972f062ddd0e1f62d 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/NamedLayoutedCircularAnchorageDiagramVisual.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/visual/NamedLayoutedCircularAnchorageDiagramVisual.java @@ -15,28 +15,63 @@ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.ui.editor.fx.visual; -import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle; -import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisual; +import static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.freeConnectorHasVisibleConnections; + import org.fortiss.tooling.base.model.element.IConnector; 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.IDiagramAnchorageMVCBundle; +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 within a diagram (free connectors). * * @author diewald */ -public class NamedLayoutedCircularAnchorageDiagramVisual<T extends ILayoutedModelElement & INamedElement> +public class NamedLayoutedCircularAnchorageDiagramVisual<T extends ILayoutedModelElement & INamedElement & IConnector> extends LayoutedCircularAnchorageDiagramVisualBase<T> { + /** The name text label. */ + private final Text nameText = new Text(""); /** Constructor. */ - public NamedLayoutedCircularAnchorageDiagramVisual(IDiagramAnchorageMVCBundle mvcb, Class<T> modelType) { + public NamedLayoutedCircularAnchorageDiagramVisual(IDiagramAnchorageMVCBundle mvcb, + Class<T> modelType) { super(mvcb, modelType); + nameText.setMouseTransparent(true); + nameText.setTextAlignment(TextAlignment.LEFT); + nameText.setTextOrigin(VPos.CENTER); } /** {@inheritDoc} */ @Override - protected String getHoverText() { + 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()); + } + } else if(nameText.getParent() != null) { + layers.getVisualFeedbackLayer().remove(nameText); + } + } + + /** Returns whether the name label should be enabled. */ + public boolean enableName() { + return !freeConnectorHasVisibleConnections(getModelElement()); + } + + /** Returns the name. */ + public String getName() { return getModelElement().getName(); } } diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/.ratings index b6b09de379e179640e4e2959874cb52f189329a2..a92b49bdcccf734fd7bb9ad1cbcc3febe2b8897c 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/.ratings @@ -5,7 +5,7 @@ EllipseLayoutUIUtils.java 4dd9dbd96a45e8c455c019caa19e4a50f18336af GREEN FXDNDUtils.java 6ce94e239e68f9e2b3cc0524b072606f4a120076 GREEN FontUtils.java a167a05bdaa8da9853705cc5134f30f6d81bc9f2 GREEN GCStateManager.java 983973a92376b5c757c1253b32e33d0666ccdf7b GREEN -LWFXEditorUtils.java c624d3f0f6487b6d426b168dad048b2c39e71114 GREEN +LWFXEditorUtils.java 24ec0e23dc4b4e768ede8209335985867bdf0e35 GREEN LayoutDataUIUtils.java c85886ac313a6efb122532218eb134047ffd6631 GREEN PropertiesViewUtils.java d345b4501c4092228edf1c98e0189317d53aaf22 GREEN RectangleLayoutUIUtils.java ef4b872bb5b4a51174e9a29d9ef05e7cb3bff3a1 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/LWFXEditorUtils.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/LWFXEditorUtils.java index c624d3f0f6487b6d426b168dad048b2c39e71114..24ec0e23dc4b4e768ede8209335985867bdf0e35 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/LWFXEditorUtils.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/LWFXEditorUtils.java @@ -19,8 +19,12 @@ import static java.lang.Math.atan2; import static java.lang.Math.cos; import static java.lang.Math.sin; -import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramCoordinate; +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.EOrientation; +import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramCoordinate; import javafx.geometry.Point2D; import javafx.geometry.Rectangle2D; @@ -99,6 +103,45 @@ public final class LWFXEditorUtils { return new DiagramCoordinate(nx, ny); } + /** + * Returns whether any connections of the given sticky connector are visible on the current + * level of hierarchy. + */ + public static boolean stickyConnectorHasVisibleConnections(IConnector connector) { + IHierarchicElement elem = connector.getOwner(); + IHierarchicElementContainer diagram = elem.getContainer(); + for(IConnection conn : connector.getIncoming()) { + if(conn.getOwner() == diagram) { + return true; + } + } + for(IConnection conn : connector.getOutgoing()) { + if(conn.getOwner() == diagram) { + return true; + } + } + return false; + } + + /** + * Returns whether any connections of the given free connector are visible on the current level + * of hierarchy. + */ + public static boolean freeConnectorHasVisibleConnections(IConnector connector) { + IHierarchicElement diagram = connector.getOwner(); + for(IConnection conn : connector.getIncoming()) { + if(conn.getOwner() == diagram) { + return true; + } + } + for(IConnection conn : connector.getOutgoing()) { + if(conn.getOwner() == diagram) { + return true; + } + } + return false; + } + /** Constructor. */ private LWFXEditorUtils() { // prevent instantiation