use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.
the class AddCanvasNodeCommandTest method testExecuteAndSetViewBounds.
@Test
@SuppressWarnings("unchecked")
public void testExecuteAndSetViewBounds() {
when(content.getBounds()).thenReturn(BoundsImpl.build(0d, 0d, 0d, 0d));
final CommandResult<CanvasViolation> result = tested.execute(canvasHandler);
assertNotEquals(CommandResult.Type.ERROR, result.getType());
verify(canvasHandler, times(1)).register(eq(SHAPE_SET_ID), eq(candidate));
verify(canvasHandler, times(1)).applyElementMutation(eq(candidate), any(MutationContext.class));
final ArgumentCaptor<Bounds> boundsArgumentCaptor = ArgumentCaptor.forClass(Bounds.class);
verify(content, times(1)).setBounds(boundsArgumentCaptor.capture());
final BoundsImpl bounds = (BoundsImpl) boundsArgumentCaptor.getValue();
assertEquals(0d, bounds.getX(), 0d);
assertEquals(0d, bounds.getY(), 0d);
assertEquals(50d, bounds.getWidth(), 0d);
assertEquals(50d, bounds.getHeight(), 0d);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.
the class UpdateElementPositionCommand method getTargetBounds.
@SuppressWarnings("unchecked")
private BoundsImpl getTargetBounds(final Element<? extends View<?>> element) {
final double[] oldSize = GraphUtils.getNodeSize(element.getContent());
final double w = oldSize[0];
final double h = oldSize[1];
return new BoundsImpl(new BoundImpl(location.getX(), location.getY()), new BoundImpl(location.getX() + w, location.getY() + h));
}
use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.
the class DefinitionUtils method buildBounds.
@SuppressWarnings("unchecked")
public Bounds buildBounds(final Object definition, final double x, final double y) {
final DefinitionAdapter<Object> adapter = definitionManager.adapters().registry().getDefinitionAdapter(definition.getClass());
final Object r = adapter.getMetaProperty(PropertyMetaTypes.RADIUS, definition);
Double width = null;
Double height = null;
if (null != r) {
final Double rv = (Double) definitionManager.adapters().forProperty().getValue(r);
if (null != rv) {
width = rv * 2;
height = width;
}
} else {
final Object w = adapter.getMetaProperty(PropertyMetaTypes.WIDTH, definition);
final Object h = adapter.getMetaProperty(PropertyMetaTypes.HEIGHT, definition);
if (null != w && null != h) {
width = (Double) definitionManager.adapters().forProperty().getValue(w);
height = (Double) definitionManager.adapters().forProperty().getValue(h);
}
}
final double _width = null != width ? width : 0d;
final double _height = null != height ? height : 0d;
return new BoundsImpl(new BoundImpl(x, y), new BoundImpl(x + _width, y + _height));
}
use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.
the class CanvasLayoutUtilsTest method getNextFromNewTaskWithNonEmptyPositionWithParent.
// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextFromNewTaskWithNonEmptyPositionWithParent() {
when(ruleManager.evaluate(eq(ruleSet), any(RuleEvaluationContext.class))).thenReturn(ruleViolations);
when(ruleViolations.violations(Violation.Type.ERROR)).thenReturn(ruleViolationIterable);
when(ruleViolations.violations(Violation.Type.ERROR).iterator()).thenReturn(ruleViolationIterator);
when(ruleViolations.violations(Violation.Type.ERROR).iterator().hasNext()).thenReturn(false);
this.graphTestHandlerParent = new TestingGraphMockHandler();
graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
Node newNode = mock(Node.class);
Bounds boundsNewNode = new BoundsImpl(new BoundImpl(100d, 200d), new BoundImpl(300d, 300d));
View viewNewNode = mock(View.class);
when(newNode.getContent()).thenReturn(viewNewNode);
when(viewNewNode.getBounds()).thenReturn(boundsNewNode);
when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstanceParent.graph);
when(graphBoundsIndexer.getAt(280.0, 100.0, 100.0, 100.0, graphInstanceParent.parentNode)).thenReturn(graphInstanceParent.intermNode);
graphInstanceParent.startNode.getOutEdges().clear();
Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstanceParent.startNode, newNode);
Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstanceParent.intermNode;
double[] size = GraphUtils.getNodeSize(intermNode.getContent());
assertTrue(next.getX() == CanvasLayoutUtils.getPaddingX());
assertTrue(next.getY() > size[1]);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl in project kie-wb-common by kiegroup.
the class CanvasLayoutUtilsTest method getNextFromRootWithParent.
@Test
@SuppressWarnings("unchecked")
public void getNextFromRootWithParent() {
this.graphTestHandlerParent = new TestingGraphMockHandler();
graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
Node node = mock(Node.class);
Bounds boundsNode = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(300d, 200d));
View viewNode = mock(View.class);
when(node.getContent()).thenReturn(viewNode);
when(viewNode.getBounds()).thenReturn(boundsNode);
when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstanceParent.graph);
Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstanceParent.startNode, node);
Node<View<?>, Edge> start = (Node<View<?>, Edge>) graphInstanceParent.startNode;
double[] size = GraphUtils.getNodeSize(start.getContent());
assertTrue(next.getX() == CanvasLayoutUtils.getPaddingX());
assertTrue(next.getY() > size[1]);
}
Aggregations