Commit 4976281b authored by Tiziano Munaro's avatar Tiziano Munaro

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

Base classes for standard boxes-and-wires diagram have been introduces
in order to avoid code duplication among similar diagram types.

Issue-Ref: 3874
Issue-Url: https://af3-developer.fortiss.org/issues/3874Signed-off-by: Tiziano Munaro's avatarTiziano Munaro <munaro@fortiss.org>
parent 54ab765a
......@@ -25,6 +25,7 @@ Export-Package: org.fortiss.tooling.base.ui,
org.fortiss.tooling.base.ui.editor,
org.fortiss.tooling.base.ui.editor.annotations,
org.fortiss.tooling.base.ui.editor.fx,
org.fortiss.tooling.base.ui.editor.fx.visuals,
org.fortiss.tooling.base.ui.editpart,
org.fortiss.tooling.base.ui.editpart.allocation,
org.fortiss.tooling.base.ui.editpart.command,
......
CoordinateCorrections.java 45b81595dd33d4750a06324ad1006c5a4ca06eb1 YELLOW
LayoutedModelElementBasedCircularContentAnchorageVisualBase.java 47073dcd2163e4a212f6165ba026f33eab0410fe YELLOW
LayoutedModelElementBasedCircularDiagramAnchorageVisualBase.java a4b91392b0df43877bd7179539e05ef8763b6759 YELLOW
LayoutedModelElementBasedLineLinkVisualBase.java bba9193bbe2a3cc854e89586eb93b1de6ea53447 YELLOW
LayoutedModelElementBasedRectangularContentVisualBase.java ac847324c23291fde09abd27c467542a6b112ee7 YELLOW
/*-------------------------------------------------------------------------+
| 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.tooling.base.ui.editor.fx.visuals;
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;
}
/*-------------------------------------------------------------------------+
| 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.tooling.base.ui.editor.fx.visuals;
import static javafx.scene.paint.Color.BLACK;
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.tooling.base.ui.editor.fx.visuals.CoordinateCorrections.PORT_DIMENSION;
import static org.fortiss.tooling.base.ui.editor.fx.visuals.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.elliptic.CircularContentAnchorageVisualBase;
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 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;
/**
* {@link CircularContentAnchorageVisualBase} providing a default visual for ports attached to boxes
* in standard boxes-and-wires diagrams based on {@link ILayoutedModelElement}s.
*
* @author munaro
*/
public abstract class LayoutedModelElementBasedCircularContentAnchorageVisualBase
extends CircularContentAnchorageVisualBase implements ISideLayout, IOffsetLayout {
/** Constructor. */
public LayoutedModelElementBasedCircularContentAnchorageVisualBase(
IContentAnchorageMVCBundle mvcb) {
super(mvcb);
Object model = mvcb.getModel();
if(!(model instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Expected model of type ILayoutedModelElement, but was " +
model.getClass().getSimpleName());
}
}
/** {@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(getLayoutedModelElement());
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(getLayoutedModelElement());
EOrientation eo = EOrientation.NORTH;
if(oo != null) {
eo = oo.getOrientation();
}
return convertEOrientationToSide(eo);
}
/** {@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();
}
/** Return the {@link ILayoutedModelElement}. */
private ILayoutedModelElement getLayoutedModelElement() {
// Safe wild cast due to type check in constructor
return (ILayoutedModelElement)getModel();
}
}
/*-------------------------------------------------------------------------+
| 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.tooling.base.ui.editor.fx.visuals;
import static javafx.scene.paint.Color.BLACK;
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.tooling.base.ui.editor.fx.visuals.CoordinateCorrections.PORT_DIMENSION;
import static org.fortiss.tooling.base.ui.editor.fx.visuals.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.elliptic.CircularDiagramAnchorageVisualBase;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point;
import javafx.geometry.Dimension2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
/**
* {@link CircularDiagramAnchorageVisualBase} providing a default visual for diagram ports in
* standard boxes-and-wires diagrams based on {@link ILayoutedModelElement}s.
*
* @author munaro
*/
public abstract class LayoutedModelElementBasedCircularDiagramAnchorageVisualBase
extends CircularDiagramAnchorageVisualBase {
/** Constructor. */
public LayoutedModelElementBasedCircularDiagramAnchorageVisualBase(
IDiagramAnchorageMVCBundle mvcb) {
super(mvcb);
Object model = mvcb.getModel();
if(!(model instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Expected model of type ILayoutedModelElement, but was " +
model.getClass().getSimpleName());
}
}
/** {@inheritDoc} */
@Override
public Rectangle2D getModelBounds() {
Point p = getNodePosition(getLayoutedModelElement());
Dimension2D dim = getDimensions();
return new Rectangle2D(p.getX(), p.getY(), dim.getWidth(), dim.getHeight());
}
/** {@inheritDoc} */
@Override
public Dimension2D getDimensions() {
return PORT_DIMENSION;
}
/** {@inheritDoc} */
@Override
protected double getInset() {
return PORT_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();
}
/** Return the {@link ILayoutedModelElement}. */
private ILayoutedModelElement getLayoutedModelElement() {
// Safe wild cast due to type check in constructor
return (ILayoutedModelElement)getModel();
}
}
/*-------------------------------------------------------------------------+
| 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.tooling.base.ui.editor.fx.visuals;
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.rectangular.LineLinkVisualBase;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Point;
import org.fortiss.tooling.base.model.layout.Points;
import javafx.geometry.Rectangle2D;
/**
* {@link LineLinkVisualBase} providing a default visual for wires in standard
* boxes-and-wires diagrams based on {@link ILayoutedModelElement}s.
*
* @author munaro
*/
public abstract class LayoutedModelElementBasedLineLinkVisualBase extends LineLinkVisualBase {
/** Constructor. */
public LayoutedModelElementBasedLineLinkVisualBase(ILinkMVCBundle mvcb) {
super(mvcb);
Object model = mvcb.getModel();
if(!(model instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Expected model of type ILayoutedModelElement, but was " +
model.getClass().getSimpleName());
}
}
/** {@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(getLayoutedModelElement());
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;
}
/** Return the {@link ILayoutedModelElement}. */
private ILayoutedModelElement getLayoutedModelElement() {
// Safe wild cast due to type check in constructor
return (ILayoutedModelElement)getModel();
}
}
/*-------------------------------------------------------------------------+
| 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.tooling.base.ui.editor.fx.visuals;
import static java.lang.Math.min;
import static org.fortiss.tooling.base.ui.editor.fx.visuals.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.rectangular.RectangularBorderLocation;
import org.eclipse.systemfocus.kernel.common.ui.javafx.lwfxef.visual.rectangular.RectangularContentVisualBase;
import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Rectangle;
import javafx.geometry.Dimension2D;
import javafx.geometry.Rectangle2D;
import javafx.geometry.Side;
/**
* {@link RectangularContentVisualBase} providing a default visual for boxes in standard
* boxes-and-wires diagrams based on {@link ILayoutedModelElement}s.
*
* @author munaro
*/
public abstract class LayoutedModelElementBasedRectangularContentVisualBase
extends RectangularContentVisualBase {
/** Constructor. */
public LayoutedModelElementBasedRectangularContentVisualBase(IContentMVCBundle mvcb) {
super(mvcb);
Object model = mvcb.getModel();
if(!(model instanceof ILayoutedModelElement)) {
throw new IllegalArgumentException(
"Expected model of type ILayoutedModelElement, but was " +
model.getClass().getSimpleName());
}
}
/** {@inheritDoc} */
@Override
public Rectangle2D getModelBounds() {
Rectangle r = getNodeBounds(getLayoutedModelElement());
double ix = COMPONENT_INSETS.getWidth();
double dw = ix * 2;
double iy = COMPONENT_INSETS.getHeight();
double dh = iy * 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 double getBorderWidth() {
return 1;
}
/** {@inheritDoc} */
@Override
protected double getOpacity() {
return 1.0;
}
/** {@inheritDoc} */
@Override
protected boolean requireSelectionForMoveGesture() {
return false;
}
/** {@inheritDoc} */
@Override
protected boolean requireSelectionForResizeGesture() {
return false;
}
/** Return the {@link ILayoutedModelElement}. */
private ILayoutedModelElement getLayoutedModelElement() {
// Safe wild cast due to type check in constructor
return (ILayoutedModelElement)getModel();
}
}
Markdown is supported
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