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();
}
}
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);
}
}
});
}
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());
}
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());
}
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;
}
Aggregations