Search in sources :

Example 36 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class WiresShapeViewExt method setFillGradient.

@Override
@SuppressWarnings("unchecked")
public T setFillGradient(final Type type, final String startColor, final String endColor) {
    this.fillGradientType = type;
    this.fillGradientStartColor = startColor;
    this.fillGradientEndColor = endColor;
    if (null != getShape()) {
        final BoundingBox bb = getShape().getBoundingBox();
        final double width = bb.getWidth();
        final double height = bb.getHeight();
        updateFillGradient(width, height);
    }
    return cast();
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 37 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class LocationControlImplTest method testMove.

@Test
@SuppressWarnings("unchecked")
public void testMove() throws Exception {
    final WiresShapeView wiresShape = mock(WiresShapeView.class);
    final WiresShapeView childWiresShape = mock(WiresShapeView.class);
    final MagnetManager.Magnets magnets = mock(MagnetManager.Magnets.class);
    final WiresMagnet magnet = mock(WiresMagnet.class);
    final WiresConnection connection = mock(WiresConnection.class);
    final NFastArrayList<WiresConnection> connections = new NFastArrayList<>(connection);
    final WiresConnector connector = mock(WiresConnector.class);
    final String connectorUUID = UUID.uuid();
    final NFastArrayList<WiresShape> children = new NFastArrayList<>(childWiresShape);
    final Group connectorGroup = mock(Group.class);
    final Edge connectorEdge = mock(Edge.class);
    final com.ait.lienzo.client.core.types.Point2D controlPointLienzo = new com.ait.lienzo.client.core.types.Point2D(100, 100);
    final Point2DArray controlPointsLienzo = new Point2DArray(controlPointLienzo);
    final ViewConnector viewConnector = mock(ViewConnector.class);
    Group parentGroup = mock(Group.class);
    BoundingBox parentBB = new BoundingBox(0, 0, 200, 200);
    MultiPath head = mock(MultiPath.class);
    MultiPath tail = mock(MultiPath.class);
    when(childWiresShape.getMagnets()).thenReturn(magnets);
    when(childWiresShape.getParent()).thenReturn(wiresShape);
    when(wiresShape.getGroup()).thenReturn(parentGroup);
    when(parentGroup.getBoundingBox()).thenReturn(parentBB);
    when(wiresShape.getX()).thenReturn(0d);
    when(wiresShape.getY()).thenReturn(0d);
    when(magnets.size()).thenReturn(1);
    when(magnets.getMagnet(0)).thenReturn(magnet);
    when(magnet.getConnectionsSize()).thenReturn(connections.size());
    when(magnet.getConnections()).thenReturn(connections);
    when(connection.getConnector()).thenReturn(connector);
    when(connector.getGroup()).thenReturn(connectorGroup);
    when(connectorGroup.uuid()).thenReturn(connectorUUID);
    when(connector.getControlPoints()).thenReturn(controlPointsLienzo);
    when(connector.getHead()).thenReturn(head);
    when(connector.getTail()).thenReturn(tail);
    when(head.getLocation()).thenReturn(new com.ait.lienzo.client.core.types.Point2D(1, 1));
    when(tail.getLocation()).thenReturn(new com.ait.lienzo.client.core.types.Point2D(2, 2));
    when(wiresShape.getChildShapes()).thenReturn(children);
    when(shape.getShapeView()).thenReturn(wiresShape);
    when(graphIndex.getEdge(connectorUUID)).thenReturn(connectorEdge);
    when(connectorEdge.getContent()).thenReturn(viewConnector);
    when(connectorGroup.getUserData()).thenReturn(new WiresUtils.UserData(connectorUUID, ""));
    tested.init(canvasHandler);
    tested.register(element);
    Point2D location = new Point2D(45d, 65.5d);
    tested.move(new Element[] { element }, new Point2D[] { location });
    ArgumentCaptor<CanvasCommand> commandArgumentCaptor = forClass(CanvasCommand.class);
    verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    ArgumentCaptor<ShapeLocationsChangedEvent> shapeLocationsChangedEventCaptor = forClass(ShapeLocationsChangedEvent.class);
    verify(shapeLocationsChangedEvent, times(1)).fire(shapeLocationsChangedEventCaptor.capture());
    assertTrue(shapeLocationsChangedEventCaptor.getValue() instanceof ShapeLocationsChangedEvent);
    // assert parent node move
    final CompositeCommand command = (CompositeCommand) commandArgumentCaptor.getValue();
    UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) command.getCommands().get(0);
    assertEquals(element, updateElementPositionCommand.getElement());
    assertEquals(location, updateElementPositionCommand.getLocation());
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) MagnetManager(com.ait.lienzo.client.core.shape.wires.MagnetManager) NFastArrayList(com.ait.tooling.nativetools.client.collection.NFastArrayList) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) WiresUtils(org.kie.workbench.common.stunner.client.lienzo.canvas.wires.WiresUtils) MultiPath(com.ait.lienzo.client.core.shape.MultiPath) WiresConnector(com.ait.lienzo.client.core.shape.wires.WiresConnector) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) WiresShape(com.ait.lienzo.client.core.shape.wires.WiresShape) ShapeLocationsChangedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent) WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) WiresMagnet(com.ait.lienzo.client.core.shape.wires.WiresMagnet) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 38 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class WiresConnectorViewTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    Node lineNode = line;
    Node headPathNode = headPath;
    Node tailPathNode = tailPath;
    point2DArray = new Point2DArray(new Point2D(0, 10), new Point2D(10, 10), new Point2D(20, 20), new Point2D(30, 30), new Point2D(40, 40));
    when(line.getPoint2DArray()).thenReturn(point2DArray);
    when(line.asShape()).thenReturn(lineShape);
    when(line.asNode()).thenReturn(lineNode);
    when(lineShape.setFillColor(anyString())).thenReturn(lineShape);
    when(lineShape.setFillColor(any(IColor.class))).thenReturn(lineShape);
    when(lineShape.setFillAlpha(anyDouble())).thenReturn(lineShape);
    when(lineShape.setStrokeColor(anyString())).thenReturn(lineShape);
    when(lineShape.setStrokeColor(any(IColor.class))).thenReturn(lineShape);
    when(lineShape.setStrokeAlpha(anyDouble())).thenReturn(lineShape);
    when(lineShape.setStrokeWidth(anyDouble())).thenReturn(lineShape);
    when(line.isControlPointShape()).thenReturn(true);
    when(headDecorator.getPath()).thenReturn(headPath);
    when(tailDecorator.getPath()).thenReturn(tailPath);
    when(headPath.asNode()).thenReturn(headPathNode);
    when(tailPath.asNode()).thenReturn(tailPathNode);
    when(headPath.getBoundingBox()).thenReturn(new BoundingBox(0, 0, 10, 10));
    this.tested = new WiresConnectorView(line, headDecorator, tailDecorator);
    this.tested.setControl(wiresConnectorControl);
    tested = spy(tested);
}
Also used : Point2DArray(com.ait.lienzo.client.core.types.Point2DArray) Point2D(com.ait.lienzo.client.core.types.Point2D) Node(com.ait.lienzo.client.core.shape.Node) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) IColor(com.ait.lienzo.shared.core.types.IColor) Before(org.junit.Before)

Example 39 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class LienzoLayerUtilsTest method testLayerToDataURL.

@Test
public void testLayerToDataURL() {
    ScratchPad scratchPad = mock(ScratchPad.class);
    Context2D context2D = mock(Context2D.class);
    when(layer.getScratchPad()).thenReturn(scratchPad);
    when(scratchPad.getContext()).thenReturn(context2D);
    when(scratchPad.toDataURL(eq(DataURLType.JPG), eq(1d))).thenReturn("theResultData");
    String result = LienzoLayerUtils.layerToDataURL(lienzoLayer, DataURLType.JPG, 1, 3, 111, 333, "#color1");
    assertEquals("theResultData", result);
    verify(scratchPad, times(1)).setPixelSize(eq(111), eq(333));
    verify(scratchPad, times(1)).clear();
    verify(context2D, times(1)).setFillColor(eq("#color1"));
    verify(context2D, times(1)).fillRect(eq(0d), eq(0d), eq(111d), eq(333d));
    verify(layer, times(1)).drawWithTransforms(eq(context2D), eq(1d), eq(new BoundingBox(1d, 3d, 111d, 333d)));
}
Also used : Context2D(com.ait.lienzo.client.core.Context2D) ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Test(org.junit.Test)

Example 40 with BoundingBox

use of com.ait.lienzo.client.core.types.BoundingBox in project kie-wb-common by kiegroup.

the class DirectionalLineTest method testBoundingBoxGeneration.

@Test
public void testBoundingBoxGeneration() throws Exception {
    final BoundingBox bb1 = tested.getBoundingBox();
    assertEquals(0d, bb1.getMinX(), 0d);
    assertEquals(0d, bb1.getMinY(), 0d);
    assertEquals(15.5d, bb1.getMaxX(), 0d);
    assertEquals(50.2d, bb1.getMaxY(), 0d);
    // Assert that BB must be re-generated after refreshing as well.
    tested.refresh();
    final BoundingBox bb2 = tested.getBoundingBox();
    assertEquals(0d, bb2.getMinX(), 0d);
    assertEquals(0d, bb2.getMinY(), 0d);
    assertEquals(15.5d, bb2.getMaxX(), 0d);
    assertEquals(50.2d, bb2.getMaxY(), 0d);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Test(org.junit.Test)

Aggregations

BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)79 Point2D (com.ait.lienzo.client.core.types.Point2D)24 Test (org.junit.Test)16 ScratchPad (com.ait.lienzo.client.core.util.ScratchPad)8 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)7 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)7 Context2D (com.ait.lienzo.client.core.Context2D)6 ArrayList (java.util.ArrayList)6 Direction (com.ait.lienzo.shared.core.types.Direction)5 Group (com.ait.lienzo.client.core.shape.Group)4 WiresShape (com.ait.lienzo.client.core.shape.wires.WiresShape)4 Text (com.ait.lienzo.client.core.shape.Text)3 Transform (com.ait.lienzo.client.core.types.Transform)3 NFastDoubleArrayJSO (com.ait.tooling.nativetools.client.collection.NFastDoubleArrayJSO)3 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)3 MultiPathDecorator (com.ait.lienzo.client.core.shape.MultiPathDecorator)2 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)2 WiresConnector (com.ait.lienzo.client.core.shape.wires.WiresConnector)2 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)2 BoundingPoints (com.ait.lienzo.client.core.types.BoundingPoints)2