Search in sources :

Example 1 with Style

use of org.osate.ge.graphics.Style in project osate2 by osate.

the class ElkGraphBuilder method createElkLabels.

private void createElkLabels(final DiagramElement parentElement, final ElkGraphElement parentLayoutElement, final LayoutMapping mapping) {
    // Don't create labels for ElkPort. The bounds of the port contain their labels.
    if (parentLayoutElement instanceof ElkPort) {
        return;
    }
    final boolean isConnection = parentElement.getGraphic() instanceof AgeConnection;
    final Style style = styleProvider.getStyle(parentElement);
    if (style.getPrimaryLabelVisible()) {
        // Create Primary Label
        if (parentElement.getLabelName() != null) {
            final ElkLabel elkLabel = createElkLabel(parentLayoutElement, parentElement.getLabelName(), layoutInfoProvider.getPrimaryLabelSize(parentElement));
            if (isConnection) {
                if (!layoutConnectionLabels) {
                    elkLabel.setProperty(CoreOptions.NO_LAYOUT, true);
                }
                mapping.getGraphMap().put(elkLabel, new PrimaryConnectionLabelReference(parentElement));
            }
        }
    }
    // Create label for annotations which are part of the graphic configuration. These are only supported by non-connections.
    if (!isConnection && parentElement.getGraphicalConfiguration().getAnnotation() != null) {
        createElkLabel(parentLayoutElement, parentElement.getGraphicalConfiguration().getAnnotation(), layoutInfoProvider.getAnnotationLabelSize(parentElement));
    }
    // Create Secondary Labels
    parentElement.getChildren().stream().filter(c -> c.getGraphic() instanceof Label).forEachOrdered(labelElement -> {
        final ElkLabel elkLabel = createElkLabel(parentLayoutElement, labelElement.getLabelName(), layoutInfoProvider.getPrimaryLabelSize(labelElement));
        if (isConnection) {
            if (!layoutConnectionLabels) {
                elkLabel.setProperty(CoreOptions.NO_LAYOUT, true);
            }
            mapping.getGraphMap().put(elkLabel, new SecondaryConnectionLabelReference(labelElement));
        }
    });
    if (parentLayoutElement instanceof ElkNode) {
        parentLayoutElement.setProperty(CoreOptions.NODE_LABELS_PLACEMENT, getNodeLabelPlacement(style));
    }
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) PortSide(org.eclipse.elk.core.options.PortSide) Dimension(org.osate.ge.graphics.Dimension) HashMap(java.util.HashMap) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) ArrayList(java.util.ArrayList) Style(org.osate.ge.graphics.Style) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) ElkPadding(org.eclipse.elk.core.math.ElkPadding) Map(java.util.Map) AgeShape(org.osate.ge.graphics.internal.AgeShape) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) HierarchyHandling(org.eclipse.elk.core.options.HierarchyHandling) EnumSet(java.util.EnumSet) PortConstraints(org.eclipse.elk.core.options.PortConstraints) ElkLabel(org.eclipse.elk.graph.ElkLabel) Predicate(java.util.function.Predicate) KVector(org.eclipse.elk.core.math.KVector) Collection(java.util.Collection) Label(org.osate.ge.graphics.internal.Label) SizeOptions(org.eclipse.elk.core.options.SizeOptions) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Collectors(java.util.stream.Collectors) ElkConnectableShape(org.eclipse.elk.graph.ElkConnectableShape) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) DockingPosition(org.osate.ge.DockingPosition) Objects(java.util.Objects) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) Direction(org.eclipse.elk.core.options.Direction) Entry(java.util.Map.Entry) Optional(java.util.Optional) ElkEdge(org.eclipse.elk.graph.ElkEdge) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) StyleProvider(org.osate.ge.internal.diagram.runtime.styling.StyleProvider) Collections(java.util.Collections) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) ElkLabel(org.eclipse.elk.graph.ElkLabel) Label(org.osate.ge.graphics.internal.Label) Style(org.osate.ge.graphics.Style)

Example 2 with Style

use of org.osate.ge.graphics.Style in project osate2 by osate.

the class DiagramSerialization method convertElementToMetamodel.

private static void convertElementToMetamodel(final IProject project, final org.osate.ge.diagram.DiagramNode mmContainer, final DiagramElement e) {
    // Write BO Reference
    final org.osate.ge.diagram.DiagramElement newElement = new org.osate.ge.diagram.DiagramElement();
    mmContainer.getElement().add(newElement);
    newElement.setUuid(e.getId().toString());
    newElement.setBo(e.getRelativeReference().toMetamodel());
    // Store embedded business object data.
    if (e.getBusinessObject() instanceof EmbeddedBusinessObject) {
        final EmbeddedBusinessObject bo = (EmbeddedBusinessObject) e.getBusinessObject();
        newElement.setBoData(bo.getData());
    }
    newElement.setManual(true);
    if (e.hasPosition()) {
        newElement.setPosition(e.getPosition().toMetamodel());
    }
    if (e.hasSize() && DiagramElementPredicates.isResizeable(e)) {
        newElement.setSize(e.getSize().toMetamodel());
    }
    if (e.getDockArea() != null && e.getDockArea() != DockArea.GROUP) {
        // Don't serialize null or group dock areas
        newElement.setDockArea(e.getDockArea().id);
    }
    final Style currentStyle = e.getStyle();
    final org.osate.ge.graphics.Color backgroundColor = currentStyle.getBackgroundColor();
    if (backgroundColor != null) {
        newElement.setBackground(colorToHex(backgroundColor));
    }
    final IPath image = currentStyle.getImagePath();
    if (image != null) {
        // Get image path relative to the diagram's project
        final String portablePath = image.makeRelativeTo(project.getFullPath()).toPortableString();
        newElement.setImage(portablePath);
        newElement.setShowAsImage(currentStyle.getShowAsImage());
    }
    final org.osate.ge.graphics.Color fontColor = currentStyle.getFontColor();
    if (fontColor != null) {
        newElement.setFontColor(colorToHex(fontColor));
    }
    final org.osate.ge.graphics.Color outlineColor = currentStyle.getOutlineColor();
    if (outlineColor != null) {
        newElement.setOutline(colorToHex(outlineColor));
    }
    final Double fontSize = currentStyle.getFontSize();
    if (fontSize != null) {
        newElement.setFontSize(fontSize);
    }
    final Double lineWidth = currentStyle.getLineWidth();
    if (lineWidth != null) {
        newElement.setLineWidth(lineWidth);
    }
    if (currentStyle.getPrimaryLabelVisible() != null) {
        newElement.setPrimaryLabelVisible(currentStyle.getPrimaryLabelVisible());
    }
    // Connection Specific
    if (e.getBendpoints().size() > 0) {
        final org.osate.ge.diagram.BendpointList mmBendpoints = new org.osate.ge.diagram.BendpointList();
        newElement.setBendpoints(mmBendpoints);
        for (final Point bendpoint : e.getBendpoints()) {
            mmBendpoints.getPoint().add(bendpoint.toMetamodel());
        }
    }
    if (e.getConnectionPrimaryLabelPosition() != null) {
        newElement.setPrimaryLabelPosition(e.getConnectionPrimaryLabelPosition().toMetamodel());
    }
    convertElementsToMetamodel(project, newElement, e.getChildren());
}
Also used : Color(org.osate.ge.graphics.Color) IPath(org.eclipse.core.runtime.IPath) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) Point(org.osate.ge.graphics.Point) Style(org.osate.ge.graphics.Style)

Example 3 with Style

use of org.osate.ge.graphics.Style in project osate2 by osate.

the class ImageErrorTooltipContributor method addTooltipContents.

@Override
public void addTooltipContents(final TooltipContributorContext ctx) {
    final BusinessObjectContext boc = ctx.getBusinessObjectContext();
    if (boc instanceof DiagramElement) {
        final DiagramElement de = (DiagramElement) boc;
        final Style style = de.getStyle();
        if (style != null && Boolean.TRUE.equals(style.getShowAsImage())) {
            final IPath imagePath = style.getImagePath();
            if (imagePath != null) {
                final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                final IResource imageResource = workspaceRoot.findMember(imagePath);
                if (imageResource == null) {
                    final Label lbl = new Label(ctx.getTooltip(), SWT.NONE);
                    lbl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                    lbl.setText("Unable to load image: " + imagePath.toPortableString());
                }
            }
        }
    }
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) Label(org.eclipse.swt.widgets.Label) Style(org.osate.ge.graphics.Style) BusinessObjectContext(org.osate.ge.BusinessObjectContext) IResource(org.eclipse.core.resources.IResource)

Example 4 with Style

use of org.osate.ge.graphics.Style in project osate2 by osate.

the class AgeFxTest method refreshStyle.

private void refreshStyle() {
    final Style style = StyleBuilder.create(baseStyle).lineStyle(dashed ? LineStyle.DASHED : LineStyle.SOLID).build();
    final FxStyle fxStyle = styleToFx.createStyle(style);
    for (final Node node : container.getChildrenUnmodifiable()) {
        FxStyleApplier.applyStyle(node, fxStyle);
    }
}
Also used : EllipseNode(org.osate.ge.gef.EllipseNode) LabelNode(org.osate.ge.gef.LabelNode) Node(javafx.scene.Node) ConnectionNode(org.osate.ge.gef.ConnectionNode) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) LineStyle(org.osate.ge.graphics.LineStyle) FxStyle(org.osate.ge.gef.FxStyle) Style(org.osate.ge.graphics.Style) FxStyle(org.osate.ge.gef.FxStyle)

Example 5 with Style

use of org.osate.ge.graphics.Style 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();
}
Also used : Arrays(java.util.Arrays) PolyBuilder(org.osate.ge.graphics.PolyBuilder) StaticAnchor(org.eclipse.gef.fx.anchors.StaticAnchor) FxStyleApplier(org.osate.ge.gef.FxStyleApplier) NoteGraphicBuilder(org.osate.ge.graphics.internal.NoteGraphicBuilder) Application(javafx.application.Application) IPath(org.eclipse.core.runtime.IPath) Graphic(org.osate.ge.graphics.Graphic) ConnectionBuilder(org.osate.ge.graphics.ConnectionBuilder) LineStyle(org.osate.ge.graphics.LineStyle) ContainerShape(org.osate.ge.gef.ContainerShape) Point(org.osate.ge.graphics.Point) ModeGraphicBuilder(org.osate.ge.graphics.internal.ModeGraphicBuilder) Collectors(java.util.stream.Collectors) ArrowBuilder(org.osate.ge.graphics.ArrowBuilder) ParallelogramBuilder(org.osate.ge.graphics.internal.ParallelogramBuilder) StyleBuilder(org.osate.ge.graphics.StyleBuilder) EllipseNode(org.osate.ge.gef.EllipseNode) Priority(javafx.scene.layout.Priority) List(java.util.List) Path(org.eclipse.core.runtime.Path) BusGraphicBuilder(org.osate.ge.graphics.internal.BusGraphicBuilder) DeviceGraphicBuilder(org.osate.ge.graphics.internal.DeviceGraphicBuilder) ProcessorGraphicBuilder(org.osate.ge.graphics.internal.ProcessorGraphicBuilder) FxStyle(org.osate.ge.gef.FxStyle) OrthogonalLineBuilder(org.osate.ge.graphics.internal.OrthogonalLineBuilder) CornerRadii(javafx.scene.layout.CornerRadii) Scene(javafx.scene.Scene) ColumnConstraints(javafx.scene.layout.ColumnConstraints) RowConstraints(javafx.scene.layout.RowConstraints) LabelNode(org.osate.ge.gef.LabelNode) FeatureGraphicBuilder(org.osate.ge.graphics.internal.FeatureGraphicBuilder) FeatureGroupTypeGraphicBuilder(org.osate.ge.graphics.internal.FeatureGroupTypeGraphicBuilder) Style(org.osate.ge.graphics.Style) Insets(javafx.geometry.Insets) BackgroundFill(javafx.scene.layout.BackgroundFill) GridPane(javafx.scene.layout.GridPane) LabelBuilder(org.osate.ge.graphics.LabelBuilder) Color(javafx.scene.paint.Color) FolderGraphicBuilder(org.osate.ge.graphics.internal.FolderGraphicBuilder) EllipseBuilder(org.osate.ge.graphics.EllipseBuilder) FlowIndicatorBuilder(org.osate.ge.graphics.FlowIndicatorBuilder) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) ConnectionNode(org.osate.ge.gef.ConnectionNode) MemoryGraphicBuilder(org.osate.ge.graphics.internal.MemoryGraphicBuilder) RectangleBuilder(org.osate.ge.graphics.RectangleBuilder) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) Background(javafx.scene.layout.Background) Stage(javafx.stage.Stage) ImageManager(org.osate.ge.gef.ImageManager) ChangeListener(javafx.beans.value.ChangeListener) LabelNode(org.osate.ge.gef.LabelNode) ColumnConstraints(javafx.scene.layout.ColumnConstraints) EllipseNode(org.osate.ge.gef.EllipseNode) LabelNode(org.osate.ge.gef.LabelNode) Node(javafx.scene.Node) ConnectionNode(org.osate.ge.gef.ConnectionNode) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) RowConstraints(javafx.scene.layout.RowConstraints) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) ContainerShape(org.osate.ge.gef.ContainerShape) ConnectionNode(org.osate.ge.gef.ConnectionNode) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) GridPane(javafx.scene.layout.GridPane) Background(javafx.scene.layout.Background) IPath(org.eclipse.core.runtime.IPath) EllipseNode(org.osate.ge.gef.EllipseNode) Graphic(org.osate.ge.graphics.Graphic) BackgroundFill(javafx.scene.layout.BackgroundFill) Point(org.osate.ge.graphics.Point) Scene(javafx.scene.Scene) Point(org.osate.ge.graphics.Point) CheckBox(javafx.scene.control.CheckBox) StaticAnchor(org.eclipse.gef.fx.anchors.StaticAnchor)

Aggregations

Style (org.osate.ge.graphics.Style)8 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IPath (org.eclipse.core.runtime.IPath)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 EnumSet (java.util.EnumSet)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Node (javafx.scene.Node)2 FxStyle (org.osate.ge.gef.FxStyle)2 Graphic (org.osate.ge.graphics.Graphic)2 Point (org.osate.ge.graphics.Point)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1