Commit 4a23fb57 authored by Tiziano Munaro's avatar Tiziano Munaro
Browse files

[UI] Refactor component diagram visuals

The visuals of channels, ports and components have been refactored to
take advantage of the base classes for standard boxes-and-wires
diagrams.

Issue-Ref: 3876
Issue-Url: https://af3-developer.fortiss.org/issues/3876

Signed-off-by: Tiziano Munaro's avatarTiziano Munaro <munaro@fortiss.org>
parent 6a3e1918
ChannelVisual.java 381cfd3bb1983b4c23bf5f6dd75f61a44f1bc2b5 GREEN
CoordinateCorrections.java c676ffd7f26e4f29f6e3bbcbde7c26d4e4c21c4d GREEN
DiagramComponentPortVisual.java 842e298a4d01a9428083d5e86a614547cd065b23 GREEN
SubComponentPortVisual.java db1ad8ec2246380b25b3e2d1edefe7f047f48b6f GREEN
SubComponentVisual.java 285df737cfd719e8fe9c8de8186ced30ee636da1 GREEN
ChannelVisual.java e8fb7bca9719d9385ddff519ac2c5cfe119410dd YELLOW
DiagramComponentPortVisual.java 5c49bf5e1b411bd2392d5f8452fa527f32cefc0b YELLOW
SubComponentPortVisual.java 708416152921dda483c7535cf6359232370572e4 YELLOW
SubComponentVisual.java 7f4e83e7a596d2fcc84151732f0b46727dc5df48 YELLOW
......@@ -15,28 +15,17 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor.fx.visual;
import static java.util.Collections.emptyList;
import static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.computeLinkToCircleLocation;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectionPoints;
import java.util.List;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.ILinkMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.ILinkVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.rectangular.LineLinkVisualBase;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.base.model.layout.Points;
import javafx.geometry.Rectangle2D;
import org.fortiss.tooling.base.ui.editor.fx.visuals.LayoutedModelElementBasedLineLinkVisualBase;
/**
* {@link ILinkVisual} for {@link Channel}s.
*
* @author hoelzl
*/
public final class ChannelVisual extends LineLinkVisualBase {
public final class ChannelVisual extends LayoutedModelElementBasedLineLinkVisualBase {
/** Constructor. */
public ChannelVisual(ILinkMVCBundle mvcb) {
super(mvcb);
......@@ -53,64 +42,6 @@ public final class ChannelVisual extends LineLinkVisualBase {
return (Channel)super.getModel();
}
/** {@inheritDoc} */
@Override
public DiagramCoordinate getBendPointLocation(int bpIndex) {
Point point = getBendPointList().get(bpIndex);
return new DiagramCoordinate(point.getX(), point.getY());
}
/** {@inheritDoc} */
@Override
protected DiagramCoordinate getStartAnchorLocation(Rectangle2D anchorBounds,
DiagramCoordinate target) {
return computeLinkToCircleLocation(anchorBounds, target);
}
/** {@inheritDoc} */
@Override
protected DiagramCoordinate getEndAnchorLocation(Rectangle2D anchorBounds,
DiagramCoordinate target) {
return computeLinkToCircleLocation(anchorBounds, target);
}
/** {@inheritDoc} */
@Override
protected Object getBendPointModel(int i) {
return getBendPointList().get(i);
}
/** {@inheritDoc} */
@Override
protected int getNumberOfBendPoints() {
return getBendPointList().size();
}
/** Returns the list of bend-points. */
private List<Point> getBendPointList() {
Points connectionPoints = getConnectionPoints(getChannel());
if(connectionPoints == null) {
return emptyList();
}
List<Point> l = connectionPoints.getPoints();
if(l == null) {
return emptyList();
}
return l;
}
/** {@inheritDoc} */
@Override
protected boolean showArrowOnLastSegment() {
return true;
}
/** {@inheritDoc} */
@Override
protected double getInvisibleSelectionLineWidth() {
return 3;
}
/** {@inheritDoc} */
@Override
protected String getLabelText(int currentSegment, int lastSegment) {
......
/*-------------------------------------------------------------------------+
| Copyright 2019 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.af3.component.ui.editor.fx.visual;
import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_CONNECTOR_SIZE;
import org.fortiss.tooling.base.layout.DefaultLayoutConstants;
import javafx.geometry.Dimension2D;
/**
* This class contains corrections of {@link DefaultLayoutConstants}.
*
* @author hoelzl
*/
class CoordinateCorrections {
/** The insets of components. */
/* package */ static final Dimension2D COMPONENT_INSETS =
new Dimension2D(DEFAULT_CONNECTOR_SIZE / 2, DEFAULT_CONNECTOR_SIZE / 2);
/** The default size of ports. */
/* package */ static final Dimension2D PORT_DIMENSION =
new Dimension2D(DEFAULT_CONNECTOR_SIZE, DEFAULT_CONNECTOR_SIZE);
/** The insets of the port visuals. */
/* package */ static final double PORT_INSET = DEFAULT_CONNECTOR_SIZE / 4.5;
}
......@@ -17,23 +17,13 @@ package org.fortiss.af3.component.ui.editor.fx.visual;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.WHITE;
import static javafx.scene.paint.Color.rgb;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_ALLOWED_TAG;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_DENIED_TAG;
import static org.fortiss.af3.component.ui.editor.fx.visual.CoordinateCorrections.PORT_DIMENSION;
import static org.fortiss.af3.component.ui.editor.fx.visual.CoordinateCorrections.PORT_INSET;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodePosition;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IDiagramAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IContentVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.elliptic.CircularDiagramAnchorageVisualBase;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.base.ui.editor.fx.visuals.LayoutedModelElementBasedCircularDiagramAnchorageVisualBase;
import javafx.geometry.Dimension2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
/**
......@@ -41,8 +31,10 @@ import javafx.scene.paint.Paint;
* diagram.
*
* @author hoelzl
* @author munaro
*/
public final class DiagramComponentPortVisual extends CircularDiagramAnchorageVisualBase {
public final class DiagramComponentPortVisual
extends LayoutedModelElementBasedCircularDiagramAnchorageVisualBase {
/** Constructor. */
public DiagramComponentPortVisual(IDiagramAnchorageMVCBundle mvcb) {
super(mvcb);
......@@ -59,32 +51,6 @@ public final class DiagramComponentPortVisual extends CircularDiagramAnchorageVi
return (Port)super.getModel();
}
/** {@inheritDoc} */
@Override
public Dimension2D getDimensions() {
return PORT_DIMENSION;
}
/** {@inheritDoc} */
@Override
public Rectangle2D getModelBounds() {
Point p = getNodePosition(getPort());
Dimension2D dim = getDimensions();
return new Rectangle2D(p.getX(), p.getY(), dim.getWidth(), dim.getHeight());
}
/** {@inheritDoc} */
@Override
protected double getInset() {
return PORT_INSET;
}
/** {@inheritDoc} */
@Override
protected Paint getBorderColor() {
return BLACK;
}
/** {@inheritDoc} */
@Override
protected Paint getFillColor() {
......@@ -93,23 +59,4 @@ public final class DiagramComponentPortVisual extends CircularDiagramAnchorageVi
}
return WHITE;
}
/** {@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, 0.25);
}
return super.getInteractionColor();
}
}
......@@ -17,30 +17,15 @@ package org.fortiss.af3.component.ui.editor.fx.visual;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.WHITE;
import static javafx.scene.paint.Color.rgb;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_ALLOWED_TAG;
import static org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramViewerDefaultTags.LINK_TARGET_DENIED_TAG;
import static org.fortiss.af3.component.ui.editor.fx.visual.CoordinateCorrections.PORT_DIMENSION;
import static org.fortiss.af3.component.ui.editor.fx.visual.CoordinateCorrections.PORT_INSET;
import static org.fortiss.tooling.base.ui.utils.LWFXEditorUtils.convertEOrientationToSide;
import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.getConnectorOffsetOrientation;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.layout.ILayout;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.layout.IOffsetLayout;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.layout.ISideLayout;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentAnchorageMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IContentVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.elliptic.CircularContentAnchorageVisualBase;
import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.Port;
import org.fortiss.tooling.base.model.layout.EOrientation;
import org.fortiss.tooling.base.model.layout.OffsetOrientation;
import org.fortiss.tooling.base.ui.editor.fx.visuals.LayoutedModelElementBasedCircularContentAnchorageVisualBase;
import javafx.geometry.Dimension2D;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.geometry.Side;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
/**
......@@ -48,9 +33,12 @@ import javafx.scene.paint.Paint;
* diagram.
*
* @author hoelzl
* @author munaro
*/
public final class SubComponentPortVisual extends CircularContentAnchorageVisualBase
public final class SubComponentPortVisual
extends LayoutedModelElementBasedCircularContentAnchorageVisualBase
implements ISideLayout, IOffsetLayout {
/** Constructor. */
public SubComponentPortVisual(IContentAnchorageMVCBundle mvcb) {
super(mvcb);
......@@ -67,58 +55,10 @@ public final class SubComponentPortVisual extends CircularContentAnchorageVisual
return (Port)super.getModel();
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T extends ILayout> T getLayout(Class<T> type) {
return (T)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 PORT_DIMENSION;
}
/** {@inheritDoc} */
@Override
protected double getInset() {
return PORT_INSET;
}
/** {@inheritDoc} */
@Override
public double getOffset() {
OffsetOrientation oo = getConnectorOffsetOrientation(getPort());
double inset = getDimensions().getWidth() / 2;
return oo.getOffset() - inset;
}
/** {@inheritDoc} */
@Override
public Side getSide() {
// TODO: remove null check after https://af3-developer.fortiss.org/issues/3868 was fixed
OffsetOrientation oo = getConnectorOffsetOrientation(getPort());
EOrientation eo = EOrientation.NORTH;
if(oo != null) {
eo = oo.getOrientation();
}
return convertEOrientationToSide(eo);
}
/** {@inheritDoc} */
@Override
protected Paint getBorderColor() {
return BLACK;
protected String getHoverText() {
return getPort().getName();
}
/** {@inheritDoc} */
......@@ -130,35 +70,4 @@ public final class SubComponentPortVisual extends CircularContentAnchorageVisual
}
return BLACK;
}
/** {@inheritDoc} */
@Override
protected double getOpacity() {
return 1.0;
}
/** {@inheritDoc} */
@Override
protected double getBorderWidth() {
return 1.0;
}
/** {@inheritDoc} */
@Override
protected String getHoverText() {
return getPort().getName();
}
/** {@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, 0.25);
}
return super.getInteractionColor();
}
}
......@@ -15,30 +15,17 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.editor.fx.visual;
import static java.lang.Math.min;
import static javafx.scene.paint.Color.BLACK;
import static org.fortiss.af3.component.ui.AF3ComponentUIActivator.convertColor;
import static org.fortiss.af3.component.ui.AF3ComponentUIActivator.getFXImage;
import static org.fortiss.af3.component.ui.DefaultStyle.STRONGLY_CAUSAL_COMPONENT_BACKGROUND;
import static org.fortiss.af3.component.ui.DefaultStyle.SUBSTRUCTURE_COMPONENT_BACKGROUND;
import static org.fortiss.af3.component.ui.DefaultStyle.WEAKLY_CAUSAL_COMPONENT_BACKGROUND;
import static org.fortiss.af3.component.ui.editor.fx.visual.CoordinateCorrections.COMPONENT_INSETS;
import static org.fortiss.tooling.base.utils.LayoutDataUtils.getNodeBounds;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.DiagramCoordinate;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.layout.IOffsetLayout;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.model.layout.ISideLayout;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.mvc.IContentMVCBundle;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IContentAnchorageVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.IContentVisual;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.rectangular.RectangularBorderLocation;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.rectangular.RectangularContentVisualBase;
import org.fortiss.af3.component.model.Component;
import org.fortiss.tooling.base.model.layout.Rectangle;
import org.fortiss.tooling.base.ui.editor.fx.visuals.LayoutedModelElementBasedRectangularContentVisualBase;
import javafx.geometry.Dimension2D;
import javafx.geometry.Rectangle2D;
import javafx.geometry.Side;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
......@@ -47,8 +34,10 @@ import javafx.scene.paint.Paint;
* {@link IContentVisual} for sub-components of the component displayed in the diagram.
*
* @author hoelzl
* @author munaro
*/
public final class SubComponentVisual extends RectangularContentVisualBase {
public final class SubComponentVisual
extends LayoutedModelElementBasedRectangularContentVisualBase {
/** The fill color used by composite components. */
private static final Color COMPOSITE_COLOR;
/** The fill color used by strongly causal components. */
......@@ -80,43 +69,6 @@ public final class SubComponentVisual extends RectangularContentVisualBase {
return (Component)getModel();
}
/** {@inheritDoc} */
@Override
protected Image getIcon() {
return ICON;
}
/** {@inheritDoc} */
@Override
protected String getName() {
return getComponent().getName();
}
/** {@inheritDoc} */
@Override
public Rectangle2D getModelBounds() {
Rectangle r = getNodeBounds(getComponent());
double ix = COMPONENT_INSETS.getWidth();
double dw = ix * 2;
double iy = COMPONENT_INSETS.getHeight();
double dh = ix * 2;
return new Rectangle2D(r.getX() + ix, r.getY() + iy, r.getWidth() - dw, r.getHeight() - dh);
}
/** {@inheritDoc} */
@Override
public DiagramCoordinate getAnchorageLocation(IContentAnchorageVisual visual) {
Rectangle2D pb = getCurrentBounds();
Side side = visual.getLayout(ISideLayout.class).getSide();
double offset = visual.getLayout(IOffsetLayout.class).getOffset();
Dimension2D dim = visual.getDimensions();
DiagramCoordinate location =
new RectangularBorderLocation(side, offset, pb, dim).getLocation();
double x = min(location.getX(), pb.getWidth() - dim.getWidth() / 2);
double y = min(location.getY(), pb.getHeight() - dim.getHeight() / 2);
return new DiagramCoordinate(x, y);
}
/** {@inheritDoc} */
@Override
protected Paint getFillColor() {
......@@ -132,37 +84,13 @@ public final class SubComponentVisual extends RectangularContentVisualBase {
/** {@inheritDoc} */
@Override
protected Paint getBorderColor() {
return BLACK;
}
/** {@inheritDoc} */
@Override
protected Dimension2D getCornerArcDimensions() {
return new Dimension2D(15, 15);
}
/** {@inheritDoc} */
@Override
protected double getBorderWidth() {
return 1;
}
/** {@inheritDoc} */
@Override
protected double getOpacity() {
return 1.0;
}
/** {@inheritDoc} */
@Override
protected boolean requireSelectionForMoveGesture() {
return false;
protected Image getIcon() {
return ICON;
}
/** {@inheritDoc} */
@Override
protected boolean requireSelectionForResizeGesture() {
return false;
protected String getName() {
return getComponent().getName();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment