Search in sources :

Example 1 with IPrimitive

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

the class AbstractPalette method build.

public T build(final Item... items) {
    clear();
    this.add(itemsGroup);
    beforeBuild();
    final Grid grid = createGrid(items.length);
    final Iterator<Grid.Point> pointIterator = grid.iterator();
    for (int c = 0; c < items.length; c++) {
        final Grid.Point point = pointIterator.next();
        final Item item = items[c];
        final int index = c;
        final double px = x + point.getX();
        final double py = y + point.getY();
        final Decorator itemDecorator = item.getDecorator() != null ? createDecorator(index, px, py) : null;
        final IPrimitive<?> i = null != itemDecorator ? itemDecorator.build(item.getPrimitive(), toDouble(iconSize), toDouble(iconSize)) : item.getPrimitive();
        i.setX(px).setY(py).moveToTop();
        this.itemsGroup.add(i);
        handlerRegistrationManager.register(i.addNodeMouseDownHandler(event -> onItemMouseDown(index, event.getX(), event.getY(), px, py)));
        handlerRegistrationManager.register(i.addNodeMouseClickHandler(event -> onItemClick(index, event.getX(), event.getY(), px, py)));
    }
    afterBuild();
    return (T) this;
}
Also used : Decorator(org.kie.workbench.common.stunner.lienzo.Decorator) Iterator(java.util.Iterator) IPrimitive(com.ait.lienzo.client.core.shape.IPrimitive) HandlerRegistrationManager(com.ait.tooling.nativetools.client.event.HandlerRegistrationManager) ItemCallback(org.kie.workbench.common.stunner.lienzo.Decorator.ItemCallback) Group(com.ait.lienzo.client.core.shape.Group) Grid(org.kie.workbench.common.stunner.lienzo.grid.Grid) Decorator(org.kie.workbench.common.stunner.lienzo.Decorator) Grid(org.kie.workbench.common.stunner.lienzo.grid.Grid)

Example 2 with IPrimitive

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

the class PrimitiveTextTooltipTest method testAsPrimitive.

@Test
@SuppressWarnings("unchecked")
public void testAsPrimitive() {
    IPrimitive tp = mock(IPrimitive.class);
    when(tooltip.asPrimitive()).thenReturn(tp);
    IPrimitive<?> p = tested.asPrimitive();
    assertEquals(tp, p);
}
Also used : IPrimitive(com.ait.lienzo.client.core.shape.IPrimitive) Test(org.junit.Test)

Example 3 with IPrimitive

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

the class StunnerWiresControlPointHandler method onNodeMouseDoubleClick.

@Override
public void onNodeMouseDoubleClick(NodeMouseDoubleClickEvent event) {
    IPrimitive<?> node = (IPrimitive<?>) event.getSource();
    controlPointDoubleClickEvent.fire(new CanvasControlPointDoubleClickEvent(getPosition(node.getLocation().getX(), node.getLocation().getY())));
}
Also used : IPrimitive(com.ait.lienzo.client.core.shape.IPrimitive) CanvasControlPointDoubleClickEvent(org.kie.workbench.common.stunner.core.client.canvas.event.controlpoint.CanvasControlPointDoubleClickEvent)

Example 4 with IPrimitive

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

the class WiresConnectorViewTest method testConnectMagnetsByLocation.

@Test
public void testConnectMagnetsByLocation() {
    // Mocks for head stuff.
    IControlHandleList headControlHandleList = new ControlHandleList(mock(Shape.class));
    WiresMagnet headMagnet1 = mock(WiresMagnet.class);
    when(headMagnet1.getX()).thenReturn(10d);
    when(headMagnet1.getY()).thenReturn(20d);
    when(headMagnet1.getIndex()).thenReturn(0);
    IPrimitive ch1 = mock(IPrimitive.class);
    when(ch1.getLocation()).thenReturn(new Point2D(10d, 20d));
    when(headMagnet1.getControl()).thenReturn(ch1);
    WiresMagnet headMagnet2 = mock(WiresMagnet.class);
    when(headMagnet2.getX()).thenReturn(100d);
    when(headMagnet2.getY()).thenReturn(200d);
    IPrimitive ch2 = mock(IPrimitive.class);
    when(ch2.getLocation()).thenReturn(new Point2D(100d, 200d));
    when(headMagnet2.getControl()).thenReturn(ch2);
    headControlHandleList.add(headMagnet1);
    headControlHandleList.add(headMagnet2);
    MagnetManager.Magnets headMagnets = mock(MagnetManager.Magnets.class);
    when(headMagnets.getMagnets()).thenReturn(headControlHandleList);
    Point2D headAbs = new Point2D(0, 0);
    MagnetConnection headConnection = MagnetConnection.Builder.at(10, 20);
    // Mocks for head tail.
    IControlHandleList tailControlHandleList = new ControlHandleList(mock(Shape.class));
    WiresMagnet tailMagnet1 = mock(WiresMagnet.class);
    when(tailMagnet1.getX()).thenReturn(10d);
    when(tailMagnet1.getY()).thenReturn(20d);
    IPrimitive th1 = mock(IPrimitive.class);
    when(th1.getLocation()).thenReturn(new Point2D(10d, 20d));
    when(tailMagnet1.getControl()).thenReturn(th1);
    WiresMagnet tailMagnet2 = mock(WiresMagnet.class);
    when(tailMagnet2.getX()).thenReturn(100d);
    when(tailMagnet2.getY()).thenReturn(200d);
    when(tailMagnet2.getIndex()).thenReturn(2);
    IPrimitive th2 = mock(IPrimitive.class);
    when(th2.getLocation()).thenReturn(new Point2D(100d, 200d));
    when(tailMagnet2.getControl()).thenReturn(th2);
    tailControlHandleList.add(tailMagnet1);
    tailControlHandleList.add(tailMagnet2);
    MagnetManager.Magnets tailMagnets = mock(MagnetManager.Magnets.class);
    when(tailMagnets.getMagnets()).thenReturn(tailControlHandleList);
    Point2D tailAbs = new Point2D(0, 0);
    MagnetConnection tailConnection = MagnetConnection.Builder.at(100, 200);
    // Mocks both source/target actual connections.
    WiresConnection headWiresConnection = mock(WiresConnection.class);
    WiresConnection tailWiresConnection = mock(WiresConnection.class);
    tested.setHeadConnection(headWiresConnection);
    tested.setTailConnection(tailWiresConnection);
    // Perform the connection.
    tested.connect(headMagnets, headAbs, headConnection, tailMagnets, tailAbs, tailConnection);
    // Verify it sets the right magnets (closest to the location):
    verify(headWiresConnection, never()).setXOffset(anyDouble());
    verify(headWiresConnection, never()).setYOffset(anyDouble());
    verify(headWiresConnection, times(1)).setAutoConnection(eq(false));
    verify(headWiresConnection, times(1)).setMagnet(eq(headMagnet1));
    verify(tailWiresConnection, times(1)).setXOffset(eq(0d));
    verify(tailWiresConnection, times(1)).setYOffset(eq(0d));
    verify(tailWiresConnection, times(1)).setAutoConnection(eq(false));
    verify(tailWiresConnection, times(1)).setMagnet(eq(tailMagnet2));
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Shape(com.ait.lienzo.client.core.shape.Shape) Point2D(com.ait.lienzo.client.core.types.Point2D) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) MagnetManager(com.ait.lienzo.client.core.shape.wires.MagnetManager) IControlHandleList(com.ait.lienzo.client.core.shape.wires.IControlHandleList) ControlHandleList(com.ait.lienzo.client.core.shape.wires.ControlHandleList) IPrimitive(com.ait.lienzo.client.core.shape.IPrimitive) WiresMagnet(com.ait.lienzo.client.core.shape.wires.WiresMagnet) IControlHandleList(com.ait.lienzo.client.core.shape.wires.IControlHandleList) Test(org.junit.Test)

Example 5 with IPrimitive

use of com.ait.lienzo.client.core.shape.IPrimitive in project lienzo-core by ahome-it.

the class AlignAndDistribute method addShape.

public AlignAndDistributeControl addShape(final IDrawable<?> group) {
    final String uuid = group.uuid();
    AlignAndDistributeControl handler = m_shapes.get(uuid);
    // only add if the group has not already been added
    if (null == handler) {
        handler = new AlignAndDistributeControlImpl((IPrimitive<?>) group, this, m_alignmentCallback, group.getBoundingBoxAttributes());
        m_shapes.put(uuid, handler);
    }
    return handler;
}
Also used : IPrimitive(com.ait.lienzo.client.core.shape.IPrimitive) AlignAndDistributeControl(com.ait.lienzo.client.core.shape.wires.handlers.AlignAndDistributeControl) AlignAndDistributeControlImpl(com.ait.lienzo.client.core.shape.wires.handlers.impl.AlignAndDistributeControlImpl)

Aggregations

IPrimitive (com.ait.lienzo.client.core.shape.IPrimitive)6 Test (org.junit.Test)2 TouchPoint (com.ait.lienzo.client.core.event.TouchPoint)1 Group (com.ait.lienzo.client.core.shape.Group)1 Shape (com.ait.lienzo.client.core.shape.Shape)1 ControlHandleList (com.ait.lienzo.client.core.shape.wires.ControlHandleList)1 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)1 MagnetManager (com.ait.lienzo.client.core.shape.wires.MagnetManager)1 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)1 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)1 AlignAndDistributeControl (com.ait.lienzo.client.core.shape.wires.handlers.AlignAndDistributeControl)1 AlignAndDistributeControlImpl (com.ait.lienzo.client.core.shape.wires.handlers.impl.AlignAndDistributeControlImpl)1 Point2D (com.ait.lienzo.client.core.types.Point2D)1 EventPropagationMode (com.ait.lienzo.shared.core.types.EventPropagationMode)1 HandlerRegistrationManager (com.ait.tooling.nativetools.client.event.HandlerRegistrationManager)1 Iterator (java.util.Iterator)1 CanvasControlPointDoubleClickEvent (org.kie.workbench.common.stunner.core.client.canvas.event.controlpoint.CanvasControlPointDoubleClickEvent)1 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)1 Decorator (org.kie.workbench.common.stunner.lienzo.Decorator)1 ItemCallback (org.kie.workbench.common.stunner.lienzo.Decorator.ItemCallback)1