use of org.osate.ge.gef.ConnectionNode in project osate2 by osate.
the class GefAgeDiagram method updateConnectionAnchors.
private void updateConnectionAnchors(final DiagramElement de, final BaseConnectionNode node) {
if (node instanceof FlowIndicatorNode) {
final FlowIndicatorNode fi = (FlowIndicatorNode) node;
final IAnchor anchor = GefAgeDiagramUtil.getAnchor(this, de.getStartElement(), null);
if (anchor != null) {
fi.setStartAnchor(anchor);
}
} else if (node instanceof ConnectionNode) {
final ConnectionNode cn = (ConnectionNode) node;
final IAnchor startAnchor = GefAgeDiagramUtil.getAnchor(this, de.getStartElement(), de.getEndElement());
final IAnchor endAnchor = GefAgeDiagramUtil.getAnchor(this, de.getEndElement(), de.getStartElement());
if (startAnchor != null && endAnchor != null) {
cn.setStartAnchor(startAnchor);
cn.setEndAnchor(endAnchor);
}
} else {
throw new AgeGefRuntimeException("Unexpected node: " + node);
}
}
use of org.osate.ge.gef.ConnectionNode in project osate2 by osate.
the class SelectedElementsMover method shiftAffectedConnections.
private void shiftAffectedConnections(final DiagramElementSnapshot snapshot, final double dx, final double dy) {
if (dx != 0.0 || dy != 0.0) {
for (final DiagramElement affectedConnectionDiagramElement : snapshot.affectedConnections) {
final Node affectedConnectionSceneNode = editor.getGefDiagram().getSceneNode(affectedConnectionDiagramElement);
// Shift regular (non flow-indicator) connections.
if (affectedConnectionSceneNode instanceof ConnectionNode) {
final BaseConnectionNode cn = (BaseConnectionNode) affectedConnectionSceneNode;
cn.getInnerConnection().setControlPoints(cn.getInnerConnection().getControlPoints().stream().map(cp -> new org.eclipse.gef.geometry.planar.Point(cp.x + dx, cp.y + dy)).collect(Collectors.toList()));
}
}
}
}
use of org.osate.ge.gef.ConnectionNode in project osate2 by osate.
the class GefAgeDiagram method updateSceneNode.
/**
* Updates the scene nodes related to the specified GEF diagram element based on the diagram element.
* Only updates properties which do not effect the structure of the scene graph. Not-recursive
* @param gefDiagramElement is the GEF diagram element for which scene nodes will be updated.
*/
private void updateSceneNode(final GefDiagramElement gefDiagramElement) {
final DiagramElement diagramElement = gefDiagramElement.diagramElement;
final Node sceneNode = gefDiagramElement.sceneNode;
// Update connections
if (sceneNode instanceof BaseConnectionNode) {
final BaseConnectionNode connectionNode = (BaseConnectionNode) sceneNode;
final Point controlPointOrigin = getControlPointOriginFromDiagram(diagramElement, sceneNode);
if (sceneNode instanceof FlowIndicatorNode) {
PreferredPosition.set(sceneNode, convertPoint(diagramElement.getPosition()));
}
// Update the connection anchor
updateConnectionAnchors(diagramElement, (BaseConnectionNode) sceneNode);
// Set control points. Coordinates are specified in the diagram model relative to the diagram. The need to be specified relative to the
// connection position. For regular connection this is the same because the node's parent is the diagram node.
// However, flow indicators have a position and have parent nodes other than the diagram.
connectionNode.getInnerConnection().setControlPoints(diagramElement.getBendpoints().stream().map(p -> new org.eclipse.gef.geometry.planar.Point(p.x - controlPointOrigin.x, p.y - controlPointOrigin.y)).collect(Collectors.toList()));
PreferredPosition.set(gefDiagramElement.primaryLabel, convertPoint(diagramElement.getConnectionPrimaryLabelPosition()));
} else if (sceneNode instanceof LabelNode) {
// Such a label represents a secondary label
final LabelNode label = (LabelNode) sceneNode;
label.setText(Strings.nullToEmpty(diagramElement.getLabelName()));
setLabelVisibility(label);
// Update element position
if (gefDiagramElement.parentDiagramNodeSceneNode instanceof BaseConnectionNode) {
PreferredPosition.set(label, convertPoint(diagramElement.getPosition()));
}
} else if (sceneNode instanceof ContainerShape) {
final ContainerShape containerShape = (ContainerShape) sceneNode;
PreferredPosition.set(sceneNode, convertPoint(diagramElement.getPosition()));
// Set configured size
final Dimension size = diagramElement.getSize();
if (size == null) {
containerShape.setConfiguredWidth(ContainerShape.NOT_SPECIFIED);
containerShape.setConfiguredHeight(ContainerShape.NOT_SPECIFIED);
} else {
containerShape.setConfiguredWidth(size.width);
containerShape.setConfiguredHeight(size.height);
}
} else if (sceneNode instanceof DockedShape) {
final DockedShape n = (DockedShape) sceneNode;
PreferredPosition.set(sceneNode, convertPoint(diagramElement.getPosition()));
// Set configured size
final Dimension size = diagramElement.getSize();
if (size == null) {
n.setConfiguredWidth(ContainerShape.NOT_SPECIFIED);
n.setConfiguredHeight(ContainerShape.NOT_SPECIFIED);
} else {
n.setConfiguredWidth(size.width);
n.setConfiguredHeight(size.height);
}
final DockArea dockArea = diagramElement.getDockArea();
if (dockArea != null && dockArea != DockArea.GROUP && gefDiagramElement.parentDiagramNodeSceneNode instanceof ContainerShape) {
final DockSide side = GefAgeDiagramUtil.toDockSide(dockArea);
final ContainerShape cs = (ContainerShape) gefDiagramElement.parentDiagramNodeSceneNode;
cs.addOrUpdateDockedChild(n, side);
}
}
// Update the primary label
if (gefDiagramElement.primaryLabel != null) {
gefDiagramElement.primaryLabel.setText(getPrimaryLabelText(diagramElement));
setLabelVisibility(gefDiagramElement.primaryLabel);
gefDiagramElement.primaryLabel.setWrapText(diagramElement.getGraphicalConfiguration().isPrimaryLabelIsMultiline());
}
// Update the secondary label
if (gefDiagramElement.annotationLabel != null) {
final String annotation = diagramElement.getGraphicalConfiguration().getAnnotation();
gefDiagramElement.annotationLabel.setText(Strings.nullToEmpty(annotation));
setLabelVisibility(gefDiagramElement.annotationLabel);
}
}
use of org.osate.ge.gef.ConnectionNode in project osate2 by osate.
the class AgeFxTest method start.
@Override
public void start(final Stage primaryStage) throws Exception {
container = new GridPane();
container.setHgap(10.0);
container.setVgap(10.0);
container.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, CornerRadii.EMPTY, Insets.EMPTY)));
final Graphic[] graphics = new Graphic[] { RectangleBuilder.create().build(), RectangleBuilder.create().rounded().build(), EllipseBuilder.create().build(), FolderGraphicBuilder.create().build(), DeviceGraphicBuilder.create().build(), ParallelogramBuilder.create().horizontalOffset(20).build(), BusGraphicBuilder.create().build(), PolyBuilder.create().polygon().points(new Point(0.0, 1.0), new Point(1.0, 1.0), new Point(0.5, 0.0)).build(), PolyBuilder.create().polyline().points(new Point(0.0, 0.0), new Point(1.0, 0.5), new Point(0.0, 1.0)).build(), ProcessorGraphicBuilder.create().build(), MemoryGraphicBuilder.create().build(), FeatureGroupTypeGraphicBuilder.create().build(), ModeGraphicBuilder.create().build(), ModeGraphicBuilder.create().initialMode().build(), NoteGraphicBuilder.create().build(), LabelBuilder.create().build(), FeatureGraphicBuilder.create().abstractFeature().bidirectional().build(), FeatureGraphicBuilder.create().abstractFeature().input().build(), FeatureGraphicBuilder.create().abstractFeature().output().build(), FeatureGraphicBuilder.create().eventPort().bidirectional().build(), FeatureGraphicBuilder.create().eventPort().input().build(), FeatureGraphicBuilder.create().eventPort().output().build(), FeatureGraphicBuilder.create().dataPort().bidirectional().build(), FeatureGraphicBuilder.create().dataPort().input().build(), FeatureGraphicBuilder.create().dataPort().output().build(), FeatureGraphicBuilder.create().eventDataPort().bidirectional().build(), FeatureGraphicBuilder.create().eventDataPort().input().build(), FeatureGraphicBuilder.create().eventDataPort().output().build(), FeatureGraphicBuilder.create().subprogramAccess().input().build(), FeatureGraphicBuilder.create().subprogramAccess().output().build(), FeatureGraphicBuilder.create().subprogramGroupAccess().input().build(), FeatureGraphicBuilder.create().subprogramGroupAccess().output().build(), FeatureGraphicBuilder.create().dataAccess().input().build(), FeatureGraphicBuilder.create().dataAccess().output().build(), FeatureGraphicBuilder.create().featureGroup().build(), ConnectionBuilder.create().build(), ConnectionBuilder.create().sourceTerminator(OrthogonalLineBuilder.create().build()).build(), ConnectionBuilder.create().sourceTerminator(ArrowBuilder.create().filled().build()).destinationTerminator(ArrowBuilder.create().filled().small().build()).build(), ConnectionBuilder.create().destinationTerminator(ArrowBuilder.create().line().build()).build(), FlowIndicatorBuilder.create().build(), FlowIndicatorBuilder.create().sourceTerminator(ArrowBuilder.create().small().reverse().build()).destinationTerminator(OrthogonalLineBuilder.create().build()).build() };
final List<Node> nodes = Arrays.stream(graphics).map(GraphicToFx::createNode).collect(Collectors.toList());
// Create a container shape. This is useful for ensuring image in style is applied,.
final ContainerShape cs = new ContainerShape();
cs.setGraphic(new EllipseNode());
nodes.add(cs);
final CheckBox dashedCheckBox = new CheckBox("Dashed");
nodes.add(dashedCheckBox);
dashedCheckBox.selectedProperty().addListener((ChangeListener<Boolean>) (observable, oldValue, newValue) -> {
dashed = newValue;
refreshStyle();
});
// Finish additional configuraton for labels and connections
for (final Node n : nodes) {
if (n instanceof LabelNode) {
((LabelNode) n).setText("This is a test");
} else if (n instanceof ConnectionNode) {
final ConnectionNode cn = (ConnectionNode) n;
final StaticAnchor start = new StaticAnchor(new org.eclipse.gef.geometry.planar.Point(0, 5));
final StaticAnchor end = new StaticAnchor(new org.eclipse.gef.geometry.planar.Point(100, 5));
cn.setStartAnchor(start);
cn.setEndAnchor(end);
} else if (n instanceof FlowIndicatorNode) {
final FlowIndicatorNode fi = (FlowIndicatorNode) n;
final StaticAnchor startAnchor = new StaticAnchor(new org.eclipse.gef.geometry.planar.Point(0, 5));
fi.setTranslateX(100.0);
fi.setTranslateY(5.0);
fi.setStartAnchor(startAnchor);
}
}
final List<String> args = getParameters().getRaw();
final IPath imagePath = args.size() > 0 ? new Path(args.get(0)) : null;
baseStyle = StyleBuilder.create(Style.DEFAULT).fontSize(20.0).outlineColor(org.osate.ge.graphics.Color.BLUE).backgroundColor(org.osate.ge.graphics.Color.CYAN).imagePath(imagePath).build();
// Add Nodes and Assign them to Rows and Columns
final int numberOfColumns = 4;
int row = 0, col = -1;
for (final Node node : nodes) {
// Increment the row and column first so that the final values will be the indices of the last node
col++;
if (col > (numberOfColumns - 1)) {
col = 0;
row++;
}
container.add(node, col, row);
}
// Create Row and Column Constraints
for (int i = 0; i < numberOfColumns; i++) {
ColumnConstraints c = new ColumnConstraints(100, 100, Double.MAX_VALUE);
c.setHgrow(Priority.SOMETIMES);
container.getColumnConstraints().add(c);
}
for (int i = 0; i <= row; i++) {
RowConstraints rc = new RowConstraints(20, 20, Double.MAX_VALUE);
rc.setVgrow(Priority.SOMETIMES);
container.getRowConstraints().add(rc);
}
// Style the nodes
refreshStyle();
primaryStage.setScene(new Scene(container));
// Setup the stage
primaryStage.setResizable(true);
primaryStage.setWidth(1920);
primaryStage.setHeight(1080);
primaryStage.setTitle("GEF Graphics");
primaryStage.show();
}
Aggregations