Commit c27babfb authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Merge branch '3876' into 'master'

[UI] Introduce base classes for the visuals of boxes-and-wires diagrams

See merge request af3/af3!262
parents 41454d26 27d24b51
ChannelController.java fe3fd8b71f320e93fa8581298581af6a9d5f8aee YELLOW
DiagramComponentPortController.java c99d075a9bc6b9c4214dee19aa5fd634ca5be379 YELLOW
DiagramController.java 74e96ce04d715a8084eb5d20b74567bc0168910d YELLOW
ChannelController.java fe3fd8b71f320e93fa8581298581af6a9d5f8aee GREEN
DiagramComponentPortController.java c99d075a9bc6b9c4214dee19aa5fd634ca5be379 GREEN
DiagramController.java 74e96ce04d715a8084eb5d20b74567bc0168910d GREEN
SubComponentController.java 3fe6f80d4fec036983523b78a8a1892c7716cbda GREEN
SubComponentPortController.java ce6b20088baeb1ddd5c98111316f707f71cd133e YELLOW
SubComponentPortController.java ce6b20088baeb1ddd5c98111316f707f71cd133e GREEN
ChannelVisual.java 381cfd3bb1983b4c23bf5f6dd75f61a44f1bc2b5 GREEN
CoordinateCorrections.java c676ffd7f26e4f29f6e3bbcbde7c26d4e4c21c4d GREEN
DiagramComponentPortVisual.java 842e298a4d01a9428083d5e86a614547cd065b23 GREEN
SubComponentPortVisual.java db1ad8ec2246380b25b3e2d1edefe7f047f48b6f GREEN
SubComponentVisual.java 285df737cfd719e8fe9c8de8186ced30ee636da1 GREEN
ChannelVisual.java b381c8ff8d3c807b0efc0408f873a96d5db865a6 GREEN
DiagramComponentPortVisual.java 604db6f8979fdb307247fdce9aa1ca28837b55a4 GREEN
SubComponentPortVisual.java 5ccd54942b0306bc1354611856e9103fb174b0a8 GREEN
SubComponentVisual.java 974bb721aa15d16c16efd8c00bb67817d66f1065 GREEN
......@@ -15,28 +15,18 @@
+--------------------------------------------------------------------------*/
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.LayoutedLineLinkVisualBase;
/**
* {@link ILinkVisual} for {@link Channel}s.
*
* @author hoelzl
* @author munaro
*/
public final class ChannelVisual extends LineLinkVisualBase {
public final class ChannelVisual extends LayoutedLineLinkVisualBase {
/** Constructor. */
public ChannelVisual(ILinkMVCBundle mvcb) {
super(mvcb);
......@@ -53,64 +43,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.LayoutedCircularDiagramAnchorageVisualBase;
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 LayoutedCircularDiagramAnchorageVisualBase {
/** 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,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.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.LayoutedCircularContentAnchorageVisualBase;
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 +31,11 @@ import javafx.scene.paint.Paint;
* diagram.
*
* @author hoelzl
* @author munaro
*/
public final class SubComponentPortVisual extends CircularContentAnchorageVisualBase
implements ISideLayout, IOffsetLayout {
public final class SubComponentPortVisual
extends LayoutedCircularContentAnchorageVisualBase {
/** Constructor. */
public SubComponentPortVisual(IContentAnchorageMVCBundle mvcb) {
super(mvcb);
......@@ -67,58 +52,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 +67,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.LayoutedRectangularContentVisualBase;
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,23 +34,21 @@ 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 LayoutedRectangularContentVisualBase {
/** The fill color used by composite components. */
private static final Color COMPOSITE_COLOR;
private static final Color COMPOSITE_COLOR = convertColor(SUBSTRUCTURE_COMPONENT_BACKGROUND);
/** The fill color used by strongly causal components. */
private static final Color STRONGLY_CAUSAL_COLOR;
private static final Color STRONGLY_CAUSAL_COLOR =
convertColor(STRONGLY_CAUSAL_COMPONENT_BACKGROUND);
/** The fill color used by weakly causal components. */
private static final Color WEAKLY_CAUSAL_COLOR;
private static final Color WEAKLY_CAUSAL_COLOR =
convertColor(WEAKLY_CAUSAL_COMPONENT_BACKGROUND);
/** The icon image. */
private static final Image ICON = getFXImage("/icons/component.gif");
static {
COMPOSITE_COLOR = convertColor(SUBSTRUCTURE_COMPONENT_BACKGROUND);
STRONGLY_CAUSAL_COLOR = convertColor(STRONGLY_CAUSAL_COMPONENT_BACKGROUND);
WEAKLY_CAUSAL_COLOR = convertColor(WEAKLY_CAUSAL_COMPONENT_BACKGROUND);
}
/** Constructor. */
public SubComponentVisual(IContentMVCBundle mvcb) {
super(mvcb);
......@@ -80,43 +65,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 +80,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