use of org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl 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.BoundImpl 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.BoundImpl 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.BoundImpl 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]);
}
use of org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl in project kie-wb-common by kiegroup.
the class CanvasLayoutUtilsTest method getNextNewTaskWithNonEmptyPosition.
// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextNewTaskWithNonEmptyPosition() {
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(true);
this.graphTestHandler = new TestingGraphMockHandler();
graphInstance = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
Node newNode = mock(Node.class);
Bounds boundsNewNode = new BoundsImpl(new BoundImpl(200d, 300d), new BoundImpl(300d, 400d));
View viewNewNode = mock(View.class);
when(newNode.getContent()).thenReturn(viewNewNode);
when(viewNewNode.getBounds()).thenReturn(boundsNewNode);
when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstance.graph);
when(graphBoundsIndexer.getAt(140.0, 0.0, 100.0, 100.0, null)).thenReturn(graphInstance.intermNode);
graphInstance.startNode.getOutEdges().clear();
Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstance.startNode, newNode);
Node<View<?>, Edge> startNode = (Node<View<?>, Edge>) graphInstance.startNode;
double[] sizeStartNode = GraphUtils.getNodeSize(startNode.getContent());
Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstance.intermNode;
double[] sizeIntermNode = GraphUtils.getNodeSize(intermNode.getContent());
assertTrue(next.getX() == sizeStartNode[0] + CanvasLayoutUtils.getPaddingX());
assertTrue(next.getY() > sizeIntermNode[1]);
}
Aggregations