Search in sources :

Example 6 with LabelNode

use of org.osate.ge.gef.LabelNode 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)

Example 7 with LabelNode

use of org.osate.ge.gef.LabelNode in project osate2 by osate.

the class SelectedElementsMover method handleEvent.

@Override
public HandledEvent handleEvent(final InputEvent e) {
    if (!editor.getPaletteModel().isSelectToolActive()) {
        return null;
    }
    if (e instanceof MouseEvent) {
        final MouseEvent mouseEvent = (MouseEvent) e;
        if ((mouseEvent.getEventType() != MouseEvent.MOUSE_PRESSED && mouseEvent.getEventType() != MouseEvent.MOUSE_DRAGGED) || mouseEvent.getButton() != MouseButton.PRIMARY) {
            return null;
        }
        final DiagramElement clickedDiagramElement = InputEventHandlerUtil.getTargetDiagramElement(editor.getGefDiagram(), e.getTarget());
        if (clickedDiagramElement == null) {
            return null;
        }
        if (e.getEventType() == MouseEvent.MOUSE_PRESSED) {
            // Store the starting position.
            mousePressLocationDiagram = editor.getGefDiagram().getSceneNode().getSceneToLocalTransform().transform(mouseEvent.getSceneX(), mouseEvent.getSceneY());
            // Determine if the primary label is the node being moved
            mousePressPrimaryConnectionLabel = null;
            if (DiagramElementPredicates.isConnection(clickedDiagramElement)) {
                for (Node tmp = (Node) e.getTarget(); tmp != null; tmp = tmp.getParent()) {
                    if (tmp instanceof BaseConnectionNode) {
                        break;
                    }
                    if (tmp instanceof LabelNode) {
                        mousePressPrimaryConnectionLabel = tmp;
                        break;
                    }
                }
            }
        } else if (e.getEventType() == MouseEvent.MOUSE_DRAGGED && mousePressLocationDiagram != null) {
            final Point2D newPositionDiagram = editor.getGefDiagram().getSceneNode().getSceneToLocalTransform().transform(mouseEvent.getSceneX(), mouseEvent.getSceneY());
            final double d = mousePressLocationDiagram.distance(newPositionDiagram);
            if (d > MIN_MOUSE_DRAGGED_DISTANCE) {
                try {
                    if (mousePressPrimaryConnectionLabel == null) {
                        final MouseMoveSelectedElementsInteraction newInteraction = new MouseMoveSelectedElementsInteraction(editor, mousePressLocationDiagram);
                        return HandledEvent.newInteraction(newInteraction);
                    } else {
                        final BaseConnectionNode cn = InputEventHandlerUtil.getClosestConnection(mousePressPrimaryConnectionLabel);
                        if (cn == null) {
                            return null;
                        }
                        final MovePrimaryConnectionLabelInteraction newInteraction = new MovePrimaryConnectionLabelInteraction(editor, mousePressLocationDiagram, cn, mousePressPrimaryConnectionLabel);
                        return HandledEvent.newInteraction(newInteraction);
                    }
                } finally {
                    mousePressLocationDiagram = null;
                }
            }
        }
        return HandledEvent.consumed();
    } else if (e instanceof KeyEvent) {
        if (e.getEventType() != KeyEvent.KEY_PRESSED) {
            return null;
        }
        final KeyEvent keyEvent = (KeyEvent) e;
        if (keyEvent.getCode() != KeyCode.PERIOD) {
            return null;
        }
        final KeyboardMoveSelectedElementsInteraction newInteraction = new KeyboardMoveSelectedElementsInteraction(editor);
        return HandledEvent.newInteraction(newInteraction);
    } else {
        return null;
    }
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) LabelNode(org.osate.ge.gef.LabelNode) KeyEvent(javafx.scene.input.KeyEvent) MouseEvent(javafx.scene.input.MouseEvent) Point2D(javafx.geometry.Point2D) LabelNode(org.osate.ge.gef.LabelNode) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) Node(javafx.scene.Node) ConnectionNode(org.osate.ge.gef.ConnectionNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode)

Example 8 with LabelNode

use of org.osate.ge.gef.LabelNode in project osate2 by osate.

the class Overlays method refresh.

/**
 * Refreshes the overlays based on the current selection
 * This should be called by the editor whenever a change could affect the overlay.
 * Specifically, it needs to be called whenever the diagram changes. Connection diagram elements may change to shapes and vice versa
 * which would cause the nodes to change without changing the selected diagram elements.
 * @param selection the current selection.
 */
@SuppressWarnings("unchecked")
public void refresh(final IStructuredSelection selection) {
    Display.getCurrent().asyncExec(() -> {
        final ImmutableMap.Builder<DiagramElement, SelectedNodeOverlay> newDiagramElementToSelectedNodeOverlayMapBuilder = ImmutableMap.builderWithExpectedSize(selection.size());
        final ArrayList<DiagramElement> selectedDiagramElements = selectionToDiagramElements(selection);
        // Add existing selected node overlays for selected diagram elements to new map.
        for (final Entry<DiagramElement, SelectedNodeOverlay> existingEntry : diagramElementToSelectedNodeOverlayMap.entrySet()) {
            if (selectedDiagramElements.contains(existingEntry.getKey()) && gefDiagram.getSceneNode(existingEntry.getKey()) == existingEntry.getValue().getSelectedNode()) {
                newDiagramElementToSelectedNodeOverlayMapBuilder.put(existingEntry.getKey(), existingEntry.getValue());
            }
        }
        // Create selected node overlays for newly selected nodes.
        for (int i = 0; i < selectedDiagramElements.size(); i++) {
            final DiagramElement selectedDiagramElement = selectedDiagramElements.get(i);
            final boolean primary = i == selectedDiagramElements.size() - 1;
            final SelectedNodeOverlay existingOverlay = diagramElementToSelectedNodeOverlayMap.get(selectedDiagramElement);
            if (diagramElementToSelectedNodeOverlayMap.containsKey(selectedDiagramElement)) {
                // Set whether it is primary
                existingOverlay.setPrimary(primary);
            } else {
                final Node selectedNode = gefDiagram.getSceneNode(selectedDiagramElement);
                if (selectedNode != null) {
                    if (selectedNode instanceof ContainerShape || selectedNode instanceof DockedShape || selectedNode instanceof LabelNode) {
                        newDiagramElementToSelectedNodeOverlayMapBuilder.put(selectedDiagramElement, new SelectedShapeOverlay(this, selectedDiagramElement, selectedNode, primary));
                    } else if (selectedNode instanceof BaseConnectionNode) {
                        // Create overlay for connection nodes
                        newDiagramElementToSelectedNodeOverlayMapBuilder.put(selectedDiagramElement, new SelectedConnectionOverlay(this, selectedDiagramElement, (BaseConnectionNode) selectedNode, primary));
                    }
                }
            }
        }
        diagramElementToSelectedNodeOverlayMap = newDiagramElementToSelectedNodeOverlayMapBuilder.build();
        // Update children to reflect the new nodes.
        selectionOverlays.getChildren().setAll((Collection<? extends Node>) diagramElementToSelectedNodeOverlayMap.values());
    });
}
Also used : LabelNode(org.osate.ge.gef.LabelNode) LabelNode(org.osate.ge.gef.LabelNode) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode) Node(javafx.scene.Node) FlowIndicatorNode(org.osate.ge.gef.FlowIndicatorNode) DockedShape(org.osate.ge.gef.DockedShape) ImmutableMap(com.google.common.collect.ImmutableMap) Point(org.eclipse.gef.geometry.planar.Point) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ContainerShape(org.osate.ge.gef.ContainerShape) BaseConnectionNode(org.osate.ge.gef.BaseConnectionNode)

Example 9 with LabelNode

use of org.osate.ge.gef.LabelNode in project osate2 by osate.

the class GefAgeDiagram method getPrimaryLabelSize.

@Override
public Dimension getPrimaryLabelSize(final DiagramElement de) {
    final LabelNode primaryLabel = getPrimaryLabelSceneNode(de);
    if (primaryLabel == null) {
        return Dimension.ZERO;
    }
    final double width = primaryLabel.computePrefWidth(-1);
    return new Dimension(width, primaryLabel.computePrefHeight(width));
}
Also used : LabelNode(org.osate.ge.gef.LabelNode) Dimension(org.osate.ge.graphics.Dimension)

Aggregations

LabelNode (org.osate.ge.gef.LabelNode)9 Node (javafx.scene.Node)7 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)6 BaseConnectionNode (org.osate.ge.gef.BaseConnectionNode)5 ConnectionNode (org.osate.ge.gef.ConnectionNode)5 ContainerShape (org.osate.ge.gef.ContainerShape)5 DockedShape (org.osate.ge.gef.DockedShape)4 FlowIndicatorNode (org.osate.ge.gef.FlowIndicatorNode)4 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)3 Point2D (javafx.geometry.Point2D)2 MouseEvent (javafx.scene.input.MouseEvent)2 DiagramRootNode (org.osate.ge.gef.DiagramRootNode)2 DockSide (org.osate.ge.gef.DockSide)2 FeatureGroupNode (org.osate.ge.gef.FeatureGroupNode)2 Dimension (org.osate.ge.graphics.Dimension)2 DockArea (org.osate.ge.internal.diagram.runtime.DockArea)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1