Search in sources :

Example 6 with BoundingBox

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

the class AutoGridTest method testGrid2.

@Test
public void testGrid2() {
    final double size = 2.5;
    final double padding = 0.5;
    final Direction direction = Direction.SOUTH;
    final BoundingBox boundingBox = new BoundingBox(0d, 0d, 100d, 100d);
    tested = new AutoGrid.Builder().forBoundingBox(boundingBox).withIconSize(size).withPadding(padding).towards(direction).build();
    assertEquals(size, tested.getIconSize(), 0);
    assertEquals(padding, tested.getPadding(), 0);
    assertEquals(direction, tested.getDirection());
    assertEquals(100, tested.getMaxSize(), 0);
    assertEquals((size + padding) / 2, tested.getMargin(), 0);
    final List<Point2D> expectedPoints = new ArrayList<>();
    final Iterator<Point2D> points = tested.iterator();
    int count = 5;
    for (int i = 0; i < count; i++) {
        final Point2D point = points.next();
        expectedPoints.add(point);
    }
    assertEquals(5, expectedPoints.size());
    assertEquals(new Point2D(0d, 0d), expectedPoints.get(0));
    assertEquals(new Point2D(0d, 3d), expectedPoints.get(1));
    assertEquals(new Point2D(0d, 6d), expectedPoints.get(2));
    assertEquals(new Point2D(0d, 9d), expectedPoints.get(3));
    assertEquals(new Point2D(0d, 12d), expectedPoints.get(4));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ArrayList(java.util.ArrayList) Direction(com.ait.lienzo.shared.core.types.Direction) Test(org.junit.Test)

Example 7 with BoundingBox

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

the class ItemGridImplTest method testInit.

@Test
public void testInit() {
    assertEquals(group, tested.asPrimitive());
    assertEquals(group, tested.getPrimitive());
    assertEquals(groupItem, tested.getWrapped());
    assertFalse(tested.isVisible());
    assertEquals(2, tested.size());
    assertTrue(tested.iterator().hasNext());
    verify(button1, times(1)).hide();
    verify(button1, never()).show();
    verify(button2, times(1)).hide();
    verify(button2, never()).show();
    verify(groupItemWrap, times(1)).add(button1Prim);
    verify(groupItemWrap, times(1)).add(button2Prim);
    final BoundingBox boundingBox = tested.getBoundingBox().get();
    assertEquals(0, boundingBox.getX(), 0);
    assertEquals(0, boundingBox.getY(), 0);
    assertEquals(11, boundingBox.getWidth(), 0);
    assertEquals(11, boundingBox.getHeight(), 0);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Test(org.junit.Test)

Example 8 with BoundingBox

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

the class LienzoCanvasExport method layerToDataURL.

private static String layerToDataURL(final com.ait.lienzo.client.core.shape.Layer layer, final DataURLType dataURLType, final int x, final int y, final int width, final int height, final String bgColor) {
    ScratchPad scratchPad = layer.getScratchPad();
    if (null != bgColor) {
        scratchPad.getContext().setFillColor(bgColor);
        scratchPad.getContext().fillRect(x, y, width, height);
    }
    layer.drawWithTransforms(scratchPad.getContext(), 1, new BoundingBox(x, y, width, height));
    final String data = scratchPad.toDataURL(dataURLType, 1);
    scratchPad.clear();
    return data;
}
Also used : ScratchPad(com.ait.lienzo.client.core.util.ScratchPad) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 9 with BoundingBox

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

the class LocationControlImpl method ensureDragConstraints.

@SuppressWarnings("unchecked")
private void ensureDragConstraints(final HasDragBounds<?> shapeView) {
    if (null == boundsConstraint) {
        boundsConstraint = getLocationBounds();
        // Selection multiple bounding constraints.
        getWiresManager().getSelectionManager().getControl().setBoundsConstraint(new BoundingBox(boundsConstraint[0], boundsConstraint[1], boundsConstraint[2], boundsConstraint[3]));
    }
    // Shape drag bounds.
    shapeView.setDragBounds(boundsConstraint[0], boundsConstraint[1], boundsConstraint[2], boundsConstraint[3]);
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox)

Example 10 with BoundingBox

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

the class LocationControlImplTest method testRegisterAndSetBounds.

@Test
public void testRegisterAndSetBounds() {
    tested.enable(canvasHandler);
    assertFalse(tested.isRegistered(element));
    tested.register(element);
    assertTrue(tested.isRegistered(element));
    verify(shapeView, times(1)).setDragEnabled(eq(true));
    ArgumentCaptor<BoundingBox> bbCaptor = ArgumentCaptor.forClass(BoundingBox.class);
    verify(wiresCompositeControl, times(1)).setBoundsConstraint(bbCaptor.capture());
    BoundingBox bb = bbCaptor.getValue();
    assertEquals(1.0d, bb.getMinX(), 0d);
    assertEquals(2.0d, bb.getMinY(), 0d);
    assertEquals(3000.0d, bb.getMaxX(), 0d);
    assertEquals(4000.0d, bb.getMaxY(), 0d);
    verify(shapeView, times(1)).setDragBounds(1.0d, 2.0d, 3000d, 4000d);
    verify(shapeEventHandler, times(1)).supports(eq(ViewEventType.MOUSE_ENTER));
    verify(shapeEventHandler, times(1)).addHandler(eq(ViewEventType.MOUSE_ENTER), any(MouseEnterHandler.class));
    verify(shapeEventHandler, times(1)).supports(eq(ViewEventType.MOUSE_EXIT));
    verify(shapeEventHandler, times(1)).addHandler(eq(ViewEventType.MOUSE_EXIT), any(MouseEnterHandler.class));
}
Also used : BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) MouseEnterHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterHandler) 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