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

Add base classes for rectangular anchorage visuals

* TODO: Cleanup/factorize this package (see #4176)

Issue-Ref: 4175
Issue-Url: af3#4175



Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent d00fa600
No related branches found
No related tags found
1 merge request!1604175: Adaptations to enable development of SOA architecture in separate plugins
......@@ -4,10 +4,14 @@ LayoutedCircularAnchorageDiagramVisualBase.java 7634416bcb88a014d985143bf00a8d29
LayoutedCurveLinkVisual.java 5b06cd7e80eaf7cf6af37a4769eaafe2a1e591f3 GREEN
LayoutedEllipticContentVisualBase.java 6f3daf386d5120793b90ce4569dd9bea33dd2a0f GREEN
LayoutedLineLinkVisual.java 5fc26086e2f63afee403379ba8f09f5113d4c025 GREEN
LayoutedRectangularAnchorageContentVisualBase.java 9d5ab8fbad2900a26ec5ea620f9f1a2a1656da77 YELLOW
LayoutedRectangularAnchorageDiagramVisualBase.java b9aa51cce71d8f6c4e400f6019b3cab0a1ed6df6 YELLOW
LayoutedRectangularContentVisualBase.java 61698ffd771ee2ad798025df8195d1bc09c2c765 GREEN
NamedLayoutedCircularAnchorageContentVisual.java 5ba0b5d133998eac47425696ef0a02b575418c2d GREEN
NamedLayoutedCircularAnchorageDiagramVisual.java eb1e736d7715b86dbc3ca0551bb754157f71cc5f GREEN
NamedLayoutedCurveLinkVisual.java 7945b2f550d5e4804f44891294ee60cc8ffcbf1e GREEN
NamedLayoutedEllipticContentVisual.java f96a956c2f71b675eee56cfc613684397545da68 GREEN
NamedLayoutedLineLinkVisual.java 4fc48616000516dc90ba22b7069ffdabadc9c377 GREEN
NamedLayoutedRectangularAnchorageContentVisual.java c9d94c2cd8a33e20aba12cdd88270cd55f42d0bd YELLOW
NamedLayoutedRectangularAnchorageDiagramVisual.java ee3d8f081681146112b1dbe11c134b474ae6e775 YELLOW
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 java.lang.Math.toDegrees;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.rgb;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.ANCHOR_DIMENSION;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.ANCHOR_INSET;
import static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.convertEOrientationToSide;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectorAngleAsDouble;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectorOffsetOrientation;
import static org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_ALLOWED_TAG;
import static org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_DENIED_TAG;
import org.fortiss.tooling.base.model.layout.EOrientation;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.OffsetOrientation;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.layout.IAngleLayout;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.layout.ILayout;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.layout.IOffsetLayout;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.layout.ISideLayout;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.rectangular.RectangularContentAnchorageVisualBase;
import javafx.geometry.Dimension2D;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.geometry.Side;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
/**
* {@link RectangularContentAnchorageVisualBase} providing a rectangular visual for ports attached
* to boxes in standard boxes-and-wires diagrams based on {@link ILayoutedModelElement}s.
*
* @author barner
*/
public abstract class LayoutedRectangularAnchorageContentVisualBase<T extends ILayoutedModelElement>
extends RectangularContentAnchorageVisualBase
implements ISideLayout, IOffsetLayout, IAngleLayout {
/** Constructor. */
public LayoutedRectangularAnchorageContentVisualBase(IContentAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb);
// TODO(#3877): Move type checks to a common base class.
Object model = mvcb.getModel();
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
}
/** Returns the model element in the correct type. */
@SuppressWarnings("unchecked")
protected T getModelElement() {
return (T)getModel();
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <S extends ILayout> S getLayout(Class<S> type) {
return (S)this;
}
/** {@inheritDoc} */
@Override
public Rectangle2D getModelBounds() {
Point2D locOnParent = getLocationOnParent();
Dimension2D dim = getDimensions();
return new Rectangle2D(locOnParent.getX(), locOnParent.getY(), dim.getWidth(),
dim.getHeight());
}
/** {@inheritDoc} */
@Override
public Dimension2D getDimensions() {
return ANCHOR_DIMENSION;
}
/** {@inheritDoc} */
@Override
protected Insets getInsets() {
return new Insets(ANCHOR_INSET);
}
/** {@inheritDoc} */
@Override
public double getOffset() {
OffsetOrientation offsetOrientation = getConnectorOffsetOrientation(getModelElement());
double inset = getDimensions().getWidth() / 2;
return offsetOrientation.getOffset() - inset;
}
/** {@inheritDoc} */
@Override
public Side getSide() {
// TODO (#3868): Remove null check.
OffsetOrientation offsetOrientation = getConnectorOffsetOrientation(getModelElement());
EOrientation orientation = EOrientation.NORTH;
if(offsetOrientation != null) {
orientation = offsetOrientation.getOrientation();
}
return convertEOrientationToSide(orientation);
}
/** {@inheritDoc} */
@Override
protected Paint getBorderColor() {
return BLACK;
}
/** {@inheritDoc} */
@Override
protected double getOpacity() {
return 1.0;
}
/** {@inheritDoc} */
@Override
protected double getBorderWidth() {
return 1.0;
}
/** {@inheritDoc} */
@Override
protected Color getInteractionColor() {
IContentAnchorageMVCBundle mvcBundle = getMVCBundle();
if(mvcBundle.hasTag(LINK_TARGET_DENIED_TAG)) {
return rgb(255, 0, 0, .25);
}
if(mvcBundle.hasTag(LINK_TARGET_ALLOWED_TAG)) {
return rgb(0, 255, 0, .25);
}
return super.getInteractionColor();
}
/** {@inheritDoc} */
@Override
public double getAngleInDegree() {
return 360 - toDegrees(getConnectorAngleAsDouble(getModelElement()));
}
}
/*-------------------------------------------------------------------------+
| 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 javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.rgb;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.ANCHOR_DIMENSION;
import static org.fortiss.tooling.base.ui.editor.fx.visual.CoordinateCorrections.ANCHOR_INSET;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodePosition;
import static org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_ALLOWED_TAG;
import static org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_DENIED_TAG;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.rectangular.RectangularDiagramAnchorageVisualBase;
import javafx.geometry.Dimension2D;
import javafx.geometry.Insets;
import javafx.geometry.Rectangle2D;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
/**
* {@link RectangularDiagramAnchorageVisualBase} providing a rectangular visual for diagram ports in
* standard boxes-and-wires diagrams based on {@link ILayoutedModelElement}s.
*
* @author barner
*/
public abstract class LayoutedRectangularAnchorageDiagramVisualBase<T extends ILayoutedModelElement>
extends RectangularDiagramAnchorageVisualBase {
/** Constructor. */
public LayoutedRectangularAnchorageDiagramVisualBase(IDiagramAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb);
// TODO(#3877): Move type checks to a common base class.
Object model = mvcb.getModel();
if(model == null) {
throw new IllegalArgumentException("The given model is null!");
}
if(!modelType.isAssignableFrom(model.getClass())) {
throw new IllegalArgumentException("Expected model of type " +
modelType.getSimpleName() + ", but was " + model.getClass().getSimpleName());
}
}
/** Returns the wrapped model as the expected type. */
@SuppressWarnings("unchecked")
protected T getModelElement() {
return (T)getModel();
}
/** {@inheritDoc} */
@Override
public Rectangle2D getModelBounds() {
Point p = getNodePosition(getModelElement());
Dimension2D dim = getDimensions();
return new Rectangle2D(p.getX(), p.getY(), dim.getWidth(), dim.getHeight());
}
/** {@inheritDoc} */
@Override
public Dimension2D getDimensions() {
return ANCHOR_DIMENSION;
}
/** {@inheritDoc} */
@Override
protected Insets getInsets() {
return new Insets(ANCHOR_INSET);
}
/** {@inheritDoc} */
@Override
protected Paint getBorderColor() {
return BLACK;
}
/** {@inheritDoc} */
@Override
protected double getOpacity() {
return 1.0;
}
/** {@inheritDoc} */
@Override
protected double getBorderWidth() {
return 1.0;
}
/** {@inheritDoc} */
@Override
protected Color getInteractionColor() {
IDiagramAnchorageMVCBundle mvcBundle = getMVCBundle();
if(mvcBundle.hasTag(LINK_TARGET_DENIED_TAG)) {
return rgb(255, 0, 0, .25);
}
if(mvcBundle.hasTag(LINK_TARGET_ALLOWED_TAG)) {
return rgb(0, 255, 0, .25);
}
return super.getInteractionColor();
}
}
/*-------------------------------------------------------------------------+
| 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.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 barner
*/
public class NamedLayoutedRectangularAnchorageContentVisual<T extends ILayoutedModelElement & INamedElement & IConnector>
extends LayoutedRectangularAnchorageContentVisualBase<T> {
/** The name text label. */
private final Text nameText = new Text("");
/** Constructor. */
public NamedLayoutedRectangularAnchorageContentVisual(IContentAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb, modelType);
nameText.setMouseTransparent(true);
nameText.setTextAlignment(TextAlignment.LEFT);
nameText.setTextOrigin(VPos.CENTER);
}
/** {@inheritDoc} */
@Override
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();
}
}
/*-------------------------------------------------------------------------+
| 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.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 barner
*/
public class NamedLayoutedRectangularAnchorageDiagramVisual<T extends ILayoutedModelElement & INamedElement & IConnector>
extends LayoutedRectangularAnchorageDiagramVisualBase<T> {
/** The name text label. */
private final Text nameText = new Text("");
/** Constructor. */
public NamedLayoutedRectangularAnchorageDiagramVisual(IDiagramAnchorageMVCBundle mvcb,
Class<T> modelType) {
super(mvcb, modelType);
nameText.setMouseTransparent(true);
nameText.setTextAlignment(TextAlignment.LEFT);
nameText.setTextOrigin(VPos.CENTER);
}
/** {@inheritDoc} */
@Override
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);
}
}
/** {@inheritDoc} */
@Override
public void removeAllVisuals(DiagramLayers layers) {
super.removeAllVisuals(layers);
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();
}
}
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