Search in sources :

Example 36 with Shape

use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.

the class CanvasHighlightVisitor method animate.

private void animate(final int index, final Command callback) {
    if (index < shapes.size()) {
        final Shape shape = shapes.get(index);
        shape.applyState(ShapeState.HIGHLIGHT);
        canvasHandler.getCanvas().draw();
        final Timer t = new Timer() {

            @Override
            public void run() {
                animate(index + 1, callback);
            }
        };
        t.schedule(TIMER_DELAY);
    } else {
        callback.execute();
    }
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Timer(com.google.gwt.user.client.Timer)

Example 37 with Shape

use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.

the class CanvasHighlightVisitor method prepareVisit.

@SuppressWarnings("unchecked")
private void prepareVisit(final Command command) {
    final Graph graph = canvasHandler.getDiagram().getGraph();
    final TreeWalkTraverseProcessor treeWalkTraverseProcessor = new TreeWalkTraverseProcessorImpl().useStartNodePredicate(this::isStartNode);
    new ViewTraverseProcessorImpl(treeWalkTraverseProcessor).traverse(graph, new ContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() {

        @Override
        public void startGraphTraversal(final Graph<DefinitionSet, Node<View, Edge>> graph) {
        }

        @Override
        public void startEdgeTraversal(final Edge<View<?>, Node> edge) {
            addShape(edge.getUUID());
        }

        @Override
        public void endEdgeTraversal(final Edge<View<?>, Node> edge) {
        }

        @Override
        public void startNodeTraversal(final Node<View, Edge> node) {
            addShape(node.getUUID());
        }

        @Override
        public void endNodeTraversal(final Node<View, Edge> node) {
        }

        @Override
        public void endGraphTraversal() {
            command.execute();
        }

        private void addShape(final String uuid) {
            final Shape shape = canvasHandler.getCanvas().getShape(uuid);
            if (null != shape) {
                shapes.add(shape);
            }
        }
    });
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Node(org.kie.workbench.common.stunner.core.graph.Node) ViewTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.content.ViewTraverseProcessorImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TreeWalkTraverseProcessorImpl(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessorImpl) TreeWalkTraverseProcessor(org.kie.workbench.common.stunner.core.graph.processing.traverse.tree.TreeWalkTraverseProcessor) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 38 with Shape

use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.

the class BaseCanvasHandlerTest method getElementAtWhenCanvasDoesNotHaveShapeAtPosition.

@Test
@SuppressWarnings("unchecked")
public void getElementAtWhenCanvasDoesNotHaveShapeAtPosition() {
    final Optional<Shape> oShape = Optional.empty();
    final Index index = mock(Index.class);
    when(canvas.getShapeAt(anyDouble(), anyDouble())).thenReturn(oShape);
    when(commandExecutionContext.getGraphIndex()).thenReturn(index);
    final Optional<Element> oElement = tested.getElementAt(0.0, 0.0);
    assertFalse(oElement.isPresent());
}
Also used : ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Element(org.kie.workbench.common.stunner.core.graph.Element) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) Test(org.junit.Test)

Example 39 with Shape

use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.

the class BaseCanvasHandlerTest method getElementAtWhenCanvasHasShapeAtPosition.

@Test
@SuppressWarnings("unchecked")
public void getElementAtWhenCanvasHasShapeAtPosition() {
    final Optional<Shape> oShape = Optional.of(mock(Shape.class));
    final Index index = mock(Index.class);
    final Node n = mock(Node.class);
    when(canvas.getShapeAt(anyDouble(), anyDouble())).thenReturn(oShape);
    when(commandExecutionContext.getGraphIndex()).thenReturn(index);
    when(index.getNode(anyString())).thenReturn(n);
    final Optional<Element> oElement = tested.getElementAt(0.0, 0.0);
    assertTrue(oElement.isPresent());
}
Also used : ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Node(org.kie.workbench.common.stunner.core.graph.Node) Element(org.kie.workbench.common.stunner.core.graph.Element) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) Test(org.junit.Test)

Example 40 with Shape

use of org.kie.workbench.common.stunner.core.client.shape.Shape in project kie-wb-common by kiegroup.

the class LienzoShapeGlyphRenderer method render.

@Override
@SuppressWarnings("unchecked")
public Group render(final ShapeGlyph glyph, final double width, final double height) {
    final String definitionId = glyph.getDefinitionId();
    final Supplier<ShapeFactory> factorySupplier = glyph.getFactorySupplier();
    final Shape shape = factorySupplier.get().newShape(factoryManager.newDefinition(definitionId));
    final ShapeView<?> view = shape.getShapeView();
    final BoundingBox bb = boundingBoxProvider.apply(view);
    Group group = groupProvider.apply(view);
    if (null == group) {
        throw new RuntimeException("Shape view [" + view.toString() + "] not supported for " + "this shape glyph builder [" + this.getClass().getName());
    }
    if (view instanceof HasTitle) {
        final HasTitle hasTitle = (HasTitle) view;
        hasTitle.setTitle(null);
    }
    // Create a copy of this view.
    group = group.copy();
    // Scale, if necessary, to the given glyph size.
    final double[] scale = LienzoUtils.getScaleFactor(bb.getWidth(), bb.getHeight(), width, height);
    group.setScale(scale[0], scale[1]);
    return group;
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) HasTitle(org.kie.workbench.common.stunner.core.client.shape.view.HasTitle) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) WiresShape(com.ait.lienzo.client.core.shape.wires.WiresShape) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory)

Aggregations

Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)42 Test (org.junit.Test)14 Element (org.kie.workbench.common.stunner.core.graph.Element)8 ElementShape (org.kie.workbench.common.stunner.core.client.shape.ElementShape)7 NullShape (org.kie.workbench.common.stunner.cm.client.shape.NullShape)5 Node (org.kie.workbench.common.stunner.core.graph.Node)4 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)3 EdgeShape (org.kie.workbench.common.stunner.core.client.shape.EdgeShape)3 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)3 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)3 CanvasShapeRemovedEvent (org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasShapeRemovedEvent)2 ShapeFactory (org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory)2 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)2 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)2 ShapeGlyph (org.kie.workbench.common.stunner.core.definition.shape.ShapeGlyph)2 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)2 Index (org.kie.workbench.common.stunner.core.graph.processing.index.Index)2 Group (com.ait.lienzo.client.core.shape.Group)1 WiresShape (com.ait.lienzo.client.core.shape.wires.WiresShape)1 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)1