Search in sources :

Example 1 with InfiniteCanvas

use of org.eclipse.gef.fx.nodes.InfiniteCanvas in project osate2 by osate.

the class AgeEditor method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    // 
    // Create the FX canvas which is an SWT widget for embedding JavaFX content.
    // 
    fxCanvas = new FXCanvas(parent, SWT.NONE);
    fxCanvas.addDisposeListener(e -> {
        fxCanvas.getScene().setRoot(new Group());
        fxCanvas.setScene(null);
    });
    fxCanvas.addPaintListener(paintListener);
    // Suppress SWT key press handling when interaction is active
    fxCanvas.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(final org.eclipse.swt.events.KeyEvent e) {
            if (activeInteraction != null) {
                e.doit = false;
            }
        }
    });
    fxCanvas.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            deactivateInteraction();
        }
    });
    // Create the context menu
    contextMenuManager = new MenuManager(MENU_ID, MENU_ID);
    contextMenuManager.setRemoveAllWhenShown(true);
    final Menu contextMenu = contextMenuManager.createContextMenu(fxCanvas);
    fxCanvas.setMenu(contextMenu);
    getEditorSite().registerContextMenu(MENU_ID, contextMenuManager, selectionProvider, true);
    // Create the action executor. It will append an action to activate the editor when undoing and redoing actions.
    actionExecutor = (label, mode, action) -> {
        final boolean reverseActionWasSpecified = actionService.execute(label, mode, action);
        // This will ensure that when the action is undone, the editor will be switched to the one in which the action was performed.
        if (isEditorActive() && reverseActionWasSpecified && !actionService.isActionExecuting() && mode == ExecutionMode.NORMAL) {
            actionService.execute("Activate Editor", ExecutionMode.APPEND_ELSE_HIDE, new ActivateAgeEditorAction(AgeEditor.this));
        }
        fireDirtyPropertyChangeEvent();
        return reverseActionWasSpecified;
    };
    // Initialize the palette model
    final AgeEditorPaletteModel.ImageProvider imageProvider = id -> {
        final RegisteredImage img = extRegistry.getImageMap().get(id);
        if (img == null) {
            return Optional.empty();
        }
        final URI imageUri = URI.createPlatformPluginURI("/" + img.plugin + "/" + img.path, true);
        if (CommonPlugin.asLocalURI(imageUri).isFile()) {
            return Optional.of(new Image(imageUri.toString()));
        } else {
            return Optional.empty();
        }
    };
    Object diagramBo = AgeDiagramUtil.getConfigurationContextBusinessObject(diagram, projectReferenceService);
    if (diagramBo == null) {
        diagramBo = project;
    }
    this.paletteModel = new AgeEditorPaletteModel(extRegistry.getPaletteContributors(), diagramBo, imageProvider);
    // If the palette item changes while an interaction is active, deactivate the interaction.
    this.paletteModel.activeItemProperty().addListener((javafx.beans.value.ChangeListener<SimplePaletteItem>) (observable, oldValue, newValue) -> deactivateInteraction());
    // Initialize the JavaFX nodes based on the diagram
    canvas = new InfiniteCanvas();
    // Set show grid based on preferences
    canvas.setShowGrid(preferenceStore.getBoolean(Preferences.SHOW_GRID));
    final Scene scene = new Scene(new DiagramEditorNode(paletteModel, canvas));
    fxCanvas.setScene(scene);
    gefDiagram = new GefAgeDiagram(diagram, coloringService);
    // Create a wrapper around the diagram's scene node.
    final Group wrapper = new DiagramNodeWrapper(gefDiagram.getSceneNode());
    // Add the wrapper to the canvas
    canvas.getContentGroup().getChildren().add(wrapper);
    gefDiagram.updateDiagramFromSceneGraph(false);
    // Treat the current state of the diagram as clean.
    cleanDiagramChangeNumber = diagram.getCurrentChangeNumber();
    adapterMap.put(LayoutInfoProvider.class, gefDiagram);
    // Create overlays
    overlays = new Overlays(gefDiagram);
    selectionProvider.addSelectionChangedListener(overlays);
    canvas.getScrolledOverlayGroup().getChildren().add(overlays);
    // Perform the initial incremental layout
    diagram.modify("Incremental Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, gefDiagram));
    // Set action executor after initial load. This occurs after the incremental layout to prevent the loading and initial layout from being undoable
    diagram.setActionExecutor(actionExecutor);
    // Refresh the dirty state whenever an operation occurs
    final IOperationHistory history = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
    history.addOperationHistoryListener(operationHistoryListener);
    canvas.setOnScroll(e -> {
        if (e.isControlDown()) {
            // Adjust zoom
            if (e.getDeltaY() < 0.0) {
                zoomOut();
            } else {
                zoomIn();
            }
        } else {
            if (e.isShiftDown()) {
                // Scroll in X direction
                canvas.setHorizontalScrollOffset(canvas.getHorizontalScrollOffset() - e.getDeltaY());
            } else {
                // Scroll
                canvas.setHorizontalScrollOffset(canvas.getHorizontalScrollOffset() - e.getDeltaX());
                canvas.setVerticalScrollOffset(canvas.getVerticalScrollOffset() + e.getDeltaY());
            }
        }
    });
    // 
    // Listeners to handle tooltips
    // 
    canvas.addEventHandler(MouseEvent.MOUSE_ENTERED_TARGET, e -> {
        if (e.getTarget() instanceof Node && activeInteraction == null && tooltipManager != null && gefDiagram != null) {
            final DiagramElement de = gefDiagram.getDiagramElement((Node) e.getTarget());
            if (de != null) {
                tooltipManager.mouseEnter(de);
            }
        }
    });
    canvas.addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, e -> {
        if (e.getTarget() instanceof Node && activeInteraction == null && tooltipManager != null && gefDiagram != null) {
            final DiagramElement de = gefDiagram.getDiagramElement((Node) e.getTarget());
            if (de != null) {
                tooltipManager.mouseExit(de);
            }
        }
    });
    // 
    // General input handlers
    // 
    // Event handler. Delegates to input event handlers or the active interaction as appropriate
    final EventHandler<? super InputEvent> handleInput = e -> {
        if (activeInteraction == null) {
            // Delegate processing of the event to the input event handlers
            for (final InputEventHandler inputEventHandler : inputEventHandlers) {
                final InputEventHandler.HandledEvent r = inputEventHandler.handleEvent(e);
                if (r != null) {
                    activeInteraction = r.newInteraction;
                    if (activeInteraction != null) {
                        canvas.setCursor(activeInteraction.getCursor());
                        if (tooltipManager != null) {
                            tooltipManager.hideTooltip();
                        }
                    }
                    break;
                }
            }
        } else {
            if (activeInteraction.handleEvent(e) == InteractionState.COMPLETE) {
                deactivateInteraction();
            }
            canvas.setCursor(activeInteraction == null ? null : activeInteraction.getCursor());
        }
    };
    // Handle mouse button presses
    canvas.addEventFilter(MouseEvent.MOUSE_PRESSED, handleInput);
    canvas.addEventFilter(MouseEvent.MOUSE_DRAGGED, handleInput);
    canvas.addEventFilter(MouseEvent.MOUSE_RELEASED, handleInput);
    scene.addEventFilter(KeyEvent.KEY_PRESSED, handleInput);
    canvas.addEventFilter(MouseEvent.MOUSE_MOVED, e -> {
        if (activeInteraction == null) {
            Cursor cursor = Cursor.DEFAULT;
            for (final InputEventHandler inputEventHandler : inputEventHandlers) {
                final Cursor overrideCursor = inputEventHandler.getCursor(e);
                if (overrideCursor != null) {
                    cursor = overrideCursor;
                    break;
                }
            }
            canvas.setCursor(cursor);
        }
        handleInput.handle(e);
    });
    // Create input event handlers
    inputEventHandlers.add(new OpenPropertiesViewInputEventHandler(this));
    inputEventHandlers.add(new ResizeInputEventHandler(this));
    inputEventHandlers.add(new MarqueeSelectInputEventHandler(this));
    inputEventHandlers.add(new MoveConnectionPointTool(this));
    inputEventHandlers.add(new RenameInputEventHandler(this));
    inputEventHandlers.add(new SelectInputEventHandler(this));
    inputEventHandlers.add(new MoveInputEventHandler(this));
    inputEventHandlers.add(new PaletteCommandInputEventHandler(this));
}
Also used : DiagramModifier(org.osate.ge.internal.diagram.runtime.DiagramModifier) Tool(org.osate.ge.internal.ui.tools.Tool) CoreException(org.eclipse.core.runtime.CoreException) FocusEvent(org.eclipse.swt.events.FocusEvent) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) InteractionState(org.osate.ge.gef.ui.editor.Interaction.InteractionState) BusinessObjectContext(org.osate.ge.BusinessObjectContext) DefaultQueryService(org.osate.ge.services.impl.DefaultQueryService) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) CommonPlugin(org.eclipse.emf.common.CommonPlugin) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) StatusManager(org.eclipse.ui.statushandlers.StatusManager) ProjectProvider(org.osate.ge.internal.services.ProjectProvider) Transform(javafx.scene.transform.Transform) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) GefAgeDiagram(org.osate.ge.gef.ui.diagram.GefAgeDiagram) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ChangeListener(org.osate.ge.internal.services.ModelChangeNotifier.ChangeListener) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) MenuManager(org.eclipse.jface.action.MenuManager) Status(org.eclipse.core.runtime.Status) Rectangle(javafx.scene.shape.Rectangle) AgeGefUiPlugin(org.osate.ge.gef.ui.AgeGefUiPlugin) KeyEvent(javafx.scene.input.KeyEvent) UiService(org.osate.ge.internal.services.UiService) Group(javafx.scene.Group) IContentOutlinePage(org.eclipse.ui.views.contentoutline.IContentOutlinePage) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IOperationHistoryListener(org.eclipse.core.commands.operations.IOperationHistoryListener) ReferenceService(org.osate.ge.internal.services.ReferenceService) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Overlays(org.osate.ge.gef.ui.editor.overlays.Overlays) SWT(org.eclipse.swt.SWT) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) EditorPart(org.eclipse.ui.part.EditorPart) AgeDiagramProvider(org.osate.ge.internal.AgeDiagramProvider) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Bounds(javafx.geometry.Bounds) PaintListener(org.eclipse.swt.events.PaintListener) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) URI(org.eclipse.emf.common.util.URI) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) ListenerList(org.eclipse.core.runtime.ListenerList) IEditorSite(org.eclipse.ui.IEditorSite) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IPropertySheetPage(org.eclipse.ui.views.properties.IPropertySheetPage) ArrayList(java.util.ArrayList) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ModelChangeNotifier(org.osate.ge.internal.services.ModelChangeNotifier) AgeContentOutlinePage(org.osate.ge.internal.ui.editor.AgeContentOutlinePage) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) ITabbedPropertySheetPageContributor(org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta) ReferenceResolutionService(org.osate.ge.services.ReferenceResolutionService) IFile(org.eclipse.core.resources.IFile) BusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectTreeUpdater) FXCanvas(javafx.embed.swt.FXCanvas) Color(javafx.scene.paint.Color) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SelectAllAction(org.osate.ge.internal.ui.editor.actions.SelectAllAction) Node(javafx.scene.Node) ContentOutline(org.eclipse.ui.views.contentoutline.ContentOutline) TabbedPropertySheetPage(org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) ProjectReferenceServiceProxy(org.osate.ge.internal.services.impl.ProjectReferenceServiceProxy) Cursor(javafx.scene.Cursor) QueryService(org.osate.ge.services.QueryService) IPartListener(org.eclipse.ui.IPartListener) IContextService(org.eclipse.ui.contexts.IContextService) InputEvent(javafx.scene.input.InputEvent) DiagramModificationAdapter(org.osate.ge.internal.diagram.runtime.DiagramModificationAdapter) LayoutInfoProvider(org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider) Preferences(org.osate.ge.gef.ui.preferences.Preferences) Image(javafx.scene.image.Image) EventHandler(javafx.event.EventHandler) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Affine(javafx.scene.transform.Affine) IAction(org.eclipse.jface.action.IAction) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) DefaultColoringService(org.osate.ge.internal.services.impl.DefaultColoringService) AgeGefRuntimeException(org.osate.ge.gef.AgeGefRuntimeException) ModificationsCompletedEvent(org.osate.ge.internal.diagram.runtime.ModificationsCompletedEvent) ActionService(org.osate.ge.internal.services.ActionService) IncrementalProjectBuilder(org.eclipse.core.resources.IncrementalProjectBuilder) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) InfiniteCanvas(org.eclipse.gef.fx.nodes.InfiniteCanvas) ISelectionListener(org.eclipse.ui.ISelectionListener) DiagramModificationListener(org.osate.ge.internal.diagram.runtime.DiagramModificationListener) SimplePaletteItem(org.osate.ge.gef.palette.SimplePaletteItem) BusinessObjectNodeFactory(org.osate.ge.internal.diagram.runtime.updating.BusinessObjectNodeFactory) DefaultReferenceResolutionService(org.osate.ge.services.impl.DefaultReferenceResolutionService) Bundle(org.osgi.framework.Bundle) ActionExecutor(org.osate.ge.internal.services.ActionExecutor) UndoRedoActionGroup(org.eclipse.ui.operations.UndoRedoActionGroup) RegisteredImage(org.osate.ge.internal.services.ExtensionRegistryService.RegisteredImage) Collection(java.util.Collection) Display(org.eclipse.swt.widgets.Display) DiagramSerialization(org.osate.ge.internal.diagram.runtime.DiagramSerialization) Collectors(java.util.stream.Collectors) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) DefaultActionService(org.osate.ge.internal.services.impl.DefaultActionService) List(java.util.List) DeactivatedEvent(org.osate.ge.internal.ui.tools.DeactivatedEvent) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) Optional(java.util.Optional) ISelection(org.eclipse.jface.viewers.ISelection) DiagramEditorNode(org.osate.ge.gef.DiagramEditorNode) DefaultDiagramElementGraphicalConfigurationProvider(org.osate.ge.internal.diagram.runtime.updating.DefaultDiagramElementGraphicalConfigurationProvider) SystemInstanceLoadingService(org.osate.ge.internal.services.SystemInstanceLoadingService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CopyAction(org.osate.ge.internal.ui.editor.actions.CopyAction) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Scene(javafx.scene.Scene) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ProjectReferenceService(org.osate.ge.internal.services.ProjectReferenceService) MouseEvent(javafx.scene.input.MouseEvent) HashMap(java.util.HashMap) DoubleProperty(javafx.beans.property.DoubleProperty) DiagramContextChecker(org.osate.ge.internal.ui.editor.DiagramContextChecker) ColoringService(org.osate.ge.internal.services.ColoringService) ImmutableList(com.google.common.collect.ImmutableList) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) DiagramUpdater(org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater) ActivatedEvent(org.osate.ge.internal.ui.tools.ActivatedEvent) IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) ActivateAgeEditorAction(org.osate.ge.internal.ui.editor.ActivateAgeEditorAction) DefaultBusinessObjectTreeUpdater(org.osate.ge.internal.diagram.runtime.updating.DefaultBusinessObjectTreeUpdater) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AgeDiagramUtil(org.osate.ge.internal.diagram.runtime.AgeDiagramUtil) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ExecutionMode(org.osate.ge.internal.services.ActionExecutor.ExecutionMode) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) IResource(org.eclipse.core.resources.IResource) Menu(org.eclipse.swt.widgets.Menu) FocusAdapter(org.eclipse.swt.events.FocusAdapter) PasteAction(org.osate.ge.internal.ui.editor.actions.PasteAction) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) Group(javafx.scene.Group) UndoRedoActionGroup(org.eclipse.ui.operations.UndoRedoActionGroup) FocusAdapter(org.eclipse.swt.events.FocusAdapter) ActivateAgeEditorAction(org.osate.ge.internal.ui.editor.ActivateAgeEditorAction) RegisteredImage(org.osate.ge.internal.services.ExtensionRegistryService.RegisteredImage) KeyAdapter(org.eclipse.swt.events.KeyAdapter) DiagramEditorNode(org.osate.ge.gef.DiagramEditorNode) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Node(javafx.scene.Node) DiagramEditorNode(org.osate.ge.gef.DiagramEditorNode) Image(javafx.scene.image.Image) RegisteredImage(org.osate.ge.internal.services.ExtensionRegistryService.RegisteredImage) SimplePaletteItem(org.osate.ge.gef.palette.SimplePaletteItem) Cursor(javafx.scene.Cursor) FocusEvent(org.eclipse.swt.events.FocusEvent) URI(org.eclipse.emf.common.util.URI) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) InfiniteCanvas(org.eclipse.gef.fx.nodes.InfiniteCanvas) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) Menu(org.eclipse.swt.widgets.Menu) FXCanvas(javafx.embed.swt.FXCanvas) Scene(javafx.scene.Scene) Overlays(org.osate.ge.gef.ui.editor.overlays.Overlays) GefAgeDiagram(org.osate.ge.gef.ui.diagram.GefAgeDiagram) MenuManager(org.eclipse.jface.action.MenuManager)

Example 2 with InfiniteCanvas

use of org.eclipse.gef.fx.nodes.InfiniteCanvas in project osate2 by osate.

the class GefTest method main.

/**
 * Entry point for the test application
 * @param args command line arguments
 */
public static void main(final String[] args) {
    try (final ImageManager images = new ImageManager()) {
        NodeApplication.run(() -> {
            final DiagramRootNode root = new DiagramRootNode();
            // 
            // Create Top Level Node
            // 
            final ContainerShape top1 = new ContainerShape();
            top1.setGraphic(new RectangleNode(true));
            root.getChildren().setAll(top1);
            // 
            // Create Labels
            // 
            final LabelNode label1 = new LabelNode("Top Node");
            final LabelNode label2 = new LabelNode("Longer single-line label. This should be truncated if there isn't space.");
            final LabelNode label3 = new LabelNode("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
            label3.setWrapText(true);
            top1.getPrimaryLabels().setAll(label1);
            top1.getSecondaryLabels().setAll(label2, label3);
            // 
            // Left Features
            // 
            final DockedShape lfg1 = createDockedShape("lfg1", new FeatureGroupNode());
            top1.getLeftChildren().add(lfg1);
            lfg1.setConfiguredWidth(400.0);
            lfg1.setConfiguredHeight(50.0);
            PreferredPosition.set(lfg1, new Point2D(0, 300));
            final DockedShape lfg1Child1 = createDockedShape("lfg1Child1", new PortNode(false, true, FeatureDirection.IN));
            lfg1Child1.getSecondaryLabels().add(new LabelNode("<internal>"));
            PreferredPosition.set(lfg1Child1, new Point2D(0, 20));
            lfg1.getNestedChildren().add(lfg1Child1);
            final DockedShape lfg1Child2 = createDockedShape("lfg1Child2", new PortNode(false, true, FeatureDirection.OUT));
            PreferredPosition.set(lfg1Child2, new Point2D(0, 50));
            lfg1.getNestedChildren().add(lfg1Child2);
            // Nested feature groups
            final DockedShape nestedFg = createDockedShape("nestedFg", new FeatureGroupNode());
            lfg1.getNestedChildren().add(nestedFg);
            nestedFg.getNestedChildren().add(createDockedShape("c1", new PortNode(false, true, FeatureDirection.IN_OUT)));
            nestedFg.getNestedChildren().add(createDockedShape("c2", new PortNode(false, true, FeatureDirection.IN)));
            // 
            // Right Features
            // 
            final DockedShape rf1 = createDockedShape("rf1", new PortNode(false, true, FeatureDirection.OUT));
            rf1.getSecondaryLabels().add(new LabelNode("<internal>"));
            top1.getRightChildren().add(rf1);
            PreferredPosition.set(rf1, new Point2D(0, 230));
            final DockedShape rf2 = createDockedShape("rf2", new PortNode(false, true, FeatureDirection.OUT));
            top1.getRightChildren().add(rf2);
            // 
            // Create Free Children
            // 
            // mode
            final ContainerShape mode1 = new ContainerShape();
            final ModeNode mode1Graphic = new ModeNode();
            mode1Graphic.setInitialMode(true);
            mode1.setGraphic(mode1Graphic);
            mode1.getPrimaryLabels().setAll(new LabelNode("m1"));
            mode1.getSecondaryLabels().setAll(new LabelNode("<initial>"));
            PreferredPosition.set(mode1, new Point2D(400, 200));
            top1.getFreeChildren().add(mode1);
            // subcomponent
            final ContainerShape sc1 = new ContainerShape();
            sc1.apply(new FxStyle.Builder().horizontalLabelPosition(LabelPosition.CENTER).verticalLabelPosition(LabelPosition.BEGINNING).build());
            sc1.setGraphic(new DeviceNode());
            sc1.getPrimaryLabels().setAll(new LabelNode("sys1"));
            top1.getFreeChildren().add(sc1);
            PreferredPosition.set(sc1, new Point2D(200, 300));
            sc1.setConfiguredWidth(310);
            sc1.setConfiguredHeight(100);
            final DockedShape sys1In1 = createDockedShape("in1", new PortNode(true, true, FeatureDirection.IN));
            sc1.getLeftChildren().add(sys1In1);
            final DockedShape sys1In2 = createDockedShape("in2", new PortNode(true, true, FeatureDirection.IN));
            sc1.getLeftChildren().add(sys1In2);
            final DockedShape sys1Out1 = createDockedShape("out1", new PortNode(false, true, FeatureDirection.OUT));
            sc1.getRightChildren().add(sys1Out1);
            // 
            // Connections
            // 
            // Flow Indicator
            final FlowIndicatorNode fsnk1 = new FlowIndicatorNode();
            fsnk1.getPrimaryLabels().setAll(new LabelNode("fsnk1"));
            fsnk1.setStartDecoration(new PolygonNode(new Dimension2D(20.0, 12.0), 1.0, 1.0, 0.0, 0.5, 1.0, 0.0));
            fsnk1.setEndDecoration(new PolylineNode(new Dimension2D(0.0, 16.0), 0.0, 0.0, 0.0, 1.0));
            PreferredPosition.set(fsnk1, new Point2D(80.0, 30.0));
            fsnk1.setStartAnchor(sys1In1.getInteriorAnchor());
            sc1.getFreeChildren().add(fsnk1);
            // Connection
            final ConnectionNode c1 = new ConnectionNode();
            c1.setStartAnchor(sys1In2.getExteriorAnchor());
            c1.setEndAnchor(lfg1Child1.getInteriorAnchor());
            c1.getPrimaryLabels().setAll(new LabelNode("c1"));
            c1.getMidpointDecorations().setAll(new PolygonNode(new Dimension2D(20.0, 12.0), 1.0, 1.0, 0.0, 0.5, 1.0, 0.0), new PolygonNode(new Dimension2D(10.0, 12.0), 1.0, 1.0, 0.0, 0.5, 1.0, 0.0));
            c1.setStartDecoration(new PolygonNode(new Dimension2D(8.0, 12.0), 1.0, 1.0, 0.0, 0.5, 1.0, 0.0));
            c1.setEndDecoration(new PolygonNode(new Dimension2D(20.0, 10.0), 1.0, 1.0, 0.0, 0.5, 1.0, 0.0));
            root.getChildren().add(c1);
            final ConnectionNode fp1 = new ConnectionNode();
            fp1.getPrimaryLabels().setAll(new LabelNode("fp1"));
            fp1.getSecondaryLabels().setAll(new LabelNode("Latency := 30ms>"));
            fp1.setStartAnchor(sys1In2.getInteriorAnchor());
            fp1.setEndAnchor(sys1Out1.getInteriorAnchor());
            fp1.getInnerConnection().setControlPoints(ImmutableList.of(new org.eclipse.gef.geometry.planar.Point(350, 380), new org.eclipse.gef.geometry.planar.Point(350, 330)));
            root.getChildren().add(fp1);
            final ConnectionNode c2 = new ConnectionNode();
            c2.setStartAnchor(sys1Out1.getExteriorAnchor());
            c2.setEndAnchor(rf2.getInteriorAnchor());
            root.getChildren().add(c2);
            final BaseConnectionNode c3 = new ConnectionNode();
            c3.setStartAnchor(mode1.getAnchor());
            c3.setEndAnchor(c2.getMidpointAnchor());
            root.getChildren().add(c3);
            mode1.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
                PreferredPosition.set(mode1, new Point2D(300, 200));
                event.consume();
            });
            final InfiniteCanvas canvas = new InfiniteCanvas();
            canvas.getContentGroup().getChildren().add(root);
            canvas.boundsInLocalProperty().addListener((ChangeListener<Bounds>) (observable, oldValue, newValue) -> {
                top1.setConfiguredWidth(newValue.getWidth());
                top1.setConfiguredHeight(newValue.getHeight());
            });
            // Start a service which will reload images
            ScheduledService<Void> svc = new ScheduledService<Void>() {

                @Override
                protected Task<Void> createTask() {
                    return new Task<Void>() {

                        @Override
                        protected Void call() {
                            images.refreshImages();
                            return null;
                        }
                    };
                }
            };
            svc.setPeriod(Duration.seconds(1));
            svc.start();
            final ImageReference testImage = args.length > 0 ? images.getImageReference(Paths.get(args[0])) : null;
            // 
            // Style test
            // 
            final Font f1 = Font.font("Arial", FontWeight.NORMAL, 14.0);
            final FxStyle s1 = new FxStyle.Builder().primaryLabelsVisible(true).font(f1).image(testImage).build();
            final FxStyle s2 = new FxStyle.Builder().outlineColor(Color.BLUE).primaryLabelsVisible(true).lineWidth(4).build();
            StyleRoot.set(top1, true);
            StyleRoot.set(mode1, true);
            StyleRoot.set(sc1, true);
            FxStyleApplier.applyStyle(mode1, s2);
            FxStyleApplier.applyStyle(sc1, s2);
            FxStyleApplier.applyStyle(top1, s1);
            return canvas;
        });
    }
}
Also used : FontWeight(javafx.scene.text.FontWeight) Color(javafx.scene.paint.Color) Dimension2D(javafx.geometry.Dimension2D) ScheduledService(javafx.concurrent.ScheduledService) Node(javafx.scene.Node) MouseEvent(javafx.scene.input.MouseEvent) Font(javafx.scene.text.Font) Task(javafx.concurrent.Task) Duration(javafx.util.Duration) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) InfiniteCanvas(org.eclipse.gef.fx.nodes.InfiniteCanvas) Point2D(javafx.geometry.Point2D) ChangeListener(javafx.beans.value.ChangeListener) Bounds(javafx.geometry.Bounds) Task(javafx.concurrent.Task) Font(javafx.scene.text.Font) InfiniteCanvas(org.eclipse.gef.fx.nodes.InfiniteCanvas) Point2D(javafx.geometry.Point2D) ScheduledService(javafx.concurrent.ScheduledService) Dimension2D(javafx.geometry.Dimension2D) Bounds(javafx.geometry.Bounds)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 Bounds (javafx.geometry.Bounds)2 Node (javafx.scene.Node)2 MouseEvent (javafx.scene.input.MouseEvent)2 Color (javafx.scene.paint.Color)2 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 DoubleProperty (javafx.beans.property.DoubleProperty)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 ChangeListener (javafx.beans.value.ChangeListener)1 ScheduledService (javafx.concurrent.ScheduledService)1 Task (javafx.concurrent.Task)1