Search in sources :

Example 6 with BoundingBox

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

the class WiresShapeViewExtTest method testTextNotIncludedInBoundBox.

@Test
public void testTextNotIncludedInBoundBox() {
    tested.addChild(new Circle(43));
    final BoundingBox startingBB = tested.getBoundingBox();
    // Adding a Tittle will add a label, but will not be included in bounding box
    tested.setTitle("Some Title");
    final BoundingBox endingBB = tested.getBoundingBox();
    assertTrue(startingBB.getMinX() == endingBB.getMinX());
    assertTrue(startingBB.getMinY() == endingBB.getMinY());
    assertTrue(startingBB.getMaxX() == endingBB.getMaxX());
    assertTrue(startingBB.getMaxY() == endingBB.getMaxY());
}
Also used : Circle(com.ait.lienzo.client.core.shape.Circle) BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) Test(org.junit.Test)

Example 7 with BoundingBox

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

the class LienzoCanvasCommandFactoryTest method testCreateResizeCommand.

@Test
@SuppressWarnings("unchecked")
public void testCreateResizeCommand() {
    Element element = mock(Element.class);
    BoundingBox boundingBox = new BoundingBox(0, 0, 1, 2);
    final CanvasCommand<AbstractCanvasHandler> command = tested.resize(element, boundingBox);
    assertNotNull(command);
    assertTrue(command instanceof LienzoResizeNodeCommand);
    LienzoResizeNodeCommand lienzoCommand = (LienzoResizeNodeCommand) command;
    assertEquals(element, lienzoCommand.getCandidate());
    assertEquals(boundingBox, lienzoCommand.getBoundingBox());
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Element(org.kie.workbench.common.stunner.core.graph.Element) BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) Test(org.junit.Test)

Example 8 with BoundingBox

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

the class ResizeNodeCommandTest method setup.

@Before
@SuppressWarnings("all")
public void setup() {
    when(canvasHandler.getDefinitionManager()).thenReturn(definitionManager);
    when(definitionManager.adapters()).thenReturn(adapterManager);
    when(adapterManager.registry()).thenReturn(adapterRegistry);
    when(adapterManager.forProperty()).thenReturn(propertyAdapter);
    when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter);
    when(adapterRegistry.getPropertyAdapter(anyObject())).thenReturn(propertyAdapter);
    when(definitionAdapter.getId(eq(definition))).thenReturn(DefinitionId.build(DEF_ID));
    when(propertyAdapter.getId(eq(wProperty))).thenReturn(W_PROPERTY_ID);
    when(propertyAdapter.getId(eq(hProperty))).thenReturn(H_PROPERTY_ID);
    when(propertyAdapter.getId(eq(rProperty))).thenReturn(R_PROPERTY_ID);
    when(definitionAdapter.getMetaPropertyField(eq(definition), eq(PropertyMetaTypes.WIDTH))).thenReturn(W_PROPERTY_ID);
    when(definitionAdapter.getMetaPropertyField(eq(definition), eq(PropertyMetaTypes.HEIGHT))).thenReturn(H_PROPERTY_ID);
    when(definitionAdapter.getMetaPropertyField(eq(definition), eq(PropertyMetaTypes.RADIUS))).thenReturn(R_PROPERTY_ID);
    when(definitionAdapter.getProperty(eq(definition), eq(W_PROPERTY_ID))).thenReturn((Optional) Optional.of(wProperty));
    when(definitionAdapter.getProperty(eq(definition), eq(H_PROPERTY_ID))).thenReturn((Optional) Optional.of(hProperty));
    when(definitionAdapter.getProperty(eq(definition), eq(R_PROPERTY_ID))).thenReturn((Optional) Optional.of(rProperty));
    when(element.getUUID()).thenReturn(ELEMENT_UUID);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(element.getContent()).thenReturn(elementContent);
    when(elementContent.getDefinition()).thenReturn(definition);
    when(elementContent.getBounds()).thenReturn(ELEMENT_BOUNDS);
    when(graph.getContent()).thenReturn(graphContent);
    when(diagram.getGraph()).thenReturn(graph);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvasHandler.getAbstractCanvas()).thenReturn(canvas);
    when(canvas.getView()).thenReturn(canvasView);
    when(canvasView.getPanel()).thenReturn(canvasPanel);
    when(canvas.getShape(eq(ELEMENT_UUID))).thenReturn(shape);
    when(canvas.getShapes()).thenReturn(Collections.singletonList(shape));
    when(shape.getUUID()).thenReturn(ELEMENT_UUID);
    when(shape.getShapeView()).thenReturn(shapeView);
    when(element.getOutEdges()).thenReturn(Arrays.asList(dockEdge, connectorEdge));
    when(element.getInEdges()).thenReturn(Collections.singletonList(connectorEdgeTarget));
    when(dockEdge.getContent()).thenReturn(new Dock());
    when(dockEdge.getTargetNode()).thenReturn(dockedNode);
    when(dockedNode.getUUID()).thenReturn(DOCKED_NODE_UUID);
    when(canvas.getShape(DOCKED_NODE_UUID)).thenReturn(dockedShape);
    when(dockedShape.getShapeView()).thenReturn(dockedShapeView);
    when(dockedShapeView.getShapeX()).thenReturn(SHAPE_X);
    when(dockedShapeView.getShapeY()).thenReturn(SHAPE_Y);
    when(connectorEdge.getSourceNode()).thenReturn(element);
    when(connectorEdge.getContent()).thenReturn(viewConnector);
    when(connectorEdge.getUUID()).thenReturn(CONNECTOR_EDGE_UUID);
    when(connectorEdgeTarget.getTargetNode()).thenReturn(element);
    when(connectorEdgeTarget.getContent()).thenReturn(viewConnectorTarget);
    when(connectorEdgeTarget.getUUID()).thenReturn(CONNECTOR_EDGE_TARGET_UUID);
    MagnetConnection magnetConnection = new MagnetConnection.Builder().atX(0).atY(0).magnet(MagnetConnection.MAGNET_CENTER).build();
    MagnetConnection magnetConnectionTarget = new MagnetConnection.Builder().magnet(1).build();
    when(viewConnector.getSourceConnection()).thenReturn(Optional.of(magnetConnection));
    when(viewConnectorTarget.getTargetConnection()).thenReturn(Optional.of(magnetConnectionTarget));
    when(canvas.getShape(CONNECTOR_EDGE_UUID)).thenReturn(connectorShape);
    when(canvas.getShape(CONNECTOR_EDGE_TARGET_UUID)).thenReturn(connectorShapeTarget);
    boundingBox = new BoundingBox(0, 0, 100, 200);
    tested = new ResizeNodeCommand(element, boundingBox, magnetLocationProvider, onResize);
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Dock(org.kie.workbench.common.stunner.core.graph.content.relationship.Dock) CanvasCommandResultBuilder(org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder) BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) Before(org.junit.Before)

Example 9 with BoundingBox

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

the class AddCanvasNodeCommandTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    super.setUp();
    BoundingBox boundingBox = new BoundingBox(0d, 0d, 50d, 50d);
    when(shape.getShapeView()).thenReturn(view);
    when(view.getBoundingBox()).thenReturn(boundingBox);
    when(canvas.getShape(eq("someUUID"))).thenReturn(shape);
    when(candidate.getUUID()).thenReturn("someUUID");
    when(candidate.getContent()).thenReturn(content);
    this.tested = new AddCanvasNodeCommand(candidate, SHAPE_SET_ID);
}
Also used : BoundingBox(org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox) Before(org.junit.Before)

Aggregations

BoundingBox (org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox)9 Before (org.junit.Before)4 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)3 Test (org.junit.Test)2 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)2 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)2 Circle (com.ait.lienzo.client.core.shape.Circle)1 OptionalInt (java.util.OptionalInt)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 CanvasCommandResultBuilder (org.kie.workbench.common.stunner.core.client.command.CanvasCommandResultBuilder)1 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)1 Element (org.kie.workbench.common.stunner.core.graph.Element)1 Dock (org.kie.workbench.common.stunner.core.graph.content.relationship.Dock)1