Search in sources :

Example 56 with Group

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

the class LienzoShapeGlyphRenderer method render.

@Override
@SuppressWarnings("unchecked")
public Group render(final ShapeGlyph glyph, final double width, final double height) {
    final String definitionId = glyph.getDefinitionId();
    final Supplier<ShapeFactory> factorySupplier = glyph.getFactorySupplier();
    final Shape shape = factorySupplier.get().newShape(factoryManager.newDefinition(definitionId));
    final ShapeView<?> view = shape.getShapeView();
    final BoundingBox bb = boundingBoxProvider.apply(view);
    Group group = groupProvider.apply(view);
    if (null == group) {
        throw new RuntimeException("Shape view [" + view.toString() + "] not supported for " + "this shape glyph builder [" + this.getClass().getName());
    }
    if (view instanceof HasTitle) {
        final HasTitle hasTitle = (HasTitle) view;
        hasTitle.setTitle(null);
    }
    // Create a copy of this view.
    group = group.copy();
    // Scale, if necessary, to the given glyph size.
    final double[] scale = LienzoShapeUtils.getScaleFactor(bb.getWidth(), bb.getHeight(), width, height);
    group.setScale(scale[0], scale[1]);
    return group;
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) HasTitle(org.kie.workbench.common.stunner.core.client.shape.view.HasTitle) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) WiresShape(com.ait.lienzo.client.core.shape.wires.WiresShape) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory)

Example 57 with Group

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

the class LienzoCanvasDecoratorFactoryTest method testAuthoringDecorator.

@Test
public void testAuthoringDecorator() {
    IPrimitive<?> decorator = LienzoCanvasDecoratorFactory.AUTHORING.apply(20, 33);
    assertNotNull(decorator);
    assertTrue(decorator instanceof Group);
    Group group = (Group) decorator;
    IPrimitive<?> child0 = group.getChildNodes().get(0);
    assertNotNull(child0);
    assertTrue(child0 instanceof Line);
    Line line0 = (Line) child0;
    assertFalse(line0.isDraggable());
    assertFalse(line0.isListening());
    assertEquals(0, line0.getFillAlpha(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_ALPHA, line0.getStrokeAlpha(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_AUTHORING_WIDTH, line0.getStrokeWidth(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_AUTHORING_COLOR, line0.getStrokeColor());
    IPrimitive<?> child1 = group.getChildNodes().get(1);
    assertNotNull(child1);
    assertTrue(child1 instanceof Line);
    Line line1 = (Line) child1;
    assertFalse(line1.isDraggable());
    assertFalse(line1.isListening());
    assertEquals(0, line1.getFillAlpha(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_ALPHA, line1.getStrokeAlpha(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_AUTHORING_WIDTH, line1.getStrokeWidth(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_AUTHORING_COLOR, line1.getStrokeColor());
}
Also used : Line(com.ait.lienzo.client.core.shape.Line) Group(com.ait.lienzo.client.core.shape.Group) Test(org.junit.Test)

Example 58 with Group

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

the class LienzoCanvasDecoratorFactoryTest method testPreviewDecorator.

@Test
public void testPreviewDecorator() {
    IPrimitive<?> decorator = LienzoCanvasDecoratorFactory.PREVIEW.apply(20, 33);
    assertNotNull(decorator);
    assertTrue(decorator instanceof Group);
    Group group = (Group) decorator;
    IPrimitive<?> child0 = group.getChildNodes().get(0);
    assertNotNull(child0);
    assertTrue(child0 instanceof Line);
    Line line0 = (Line) child0;
    assertFalse(line0.isDraggable());
    assertFalse(line0.isListening());
    assertEquals(0, line0.getFillAlpha(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_ALPHA, line0.getStrokeAlpha(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_PREVIEW_WIDTH, line0.getStrokeWidth(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_PREVIEW_COLOR, line0.getStrokeColor());
    IPrimitive<?> child1 = group.getChildNodes().get(1);
    assertNotNull(child1);
    assertTrue(child1 instanceof Line);
    Line line1 = (Line) child1;
    assertFalse(line1.isDraggable());
    assertFalse(line1.isListening());
    assertEquals(0, line1.getFillAlpha(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_ALPHA, line1.getStrokeAlpha(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_PREVIEW_WIDTH, line1.getStrokeWidth(), 0d);
    assertEquals(LienzoCanvasDecoratorFactory.DECORATOR_PREVIEW_COLOR, line1.getStrokeColor());
}
Also used : Line(com.ait.lienzo.client.core.shape.Line) Group(com.ait.lienzo.client.core.shape.Group) Test(org.junit.Test)

Example 59 with Group

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

the class PrimitiveTooltip method buildDecorator.

private IPrimitive<?> buildDecorator(final double width, final double height, final Direction direction) {
    final boolean isWest = isWest(direction);
    final boolean isNorth = isNorth(direction);
    final double h2 = height / 2;
    final double w2 = width / 2;
    final double s2 = TRIANGLE_SIZE / 2;
    final Point2D a = isWest ? new Point2D(0, h2) : new Point2D(10, 0);
    final Point2D b = isWest ? new Point2D(TRIANGLE_SIZE, h2 + s2) : new Point2D(10 + s2, TRIANGLE_SIZE);
    final Point2D c = isWest ? new Point2D(TRIANGLE_SIZE, h2 - s2) : new Point2D(10 - s2, TRIANGLE_SIZE);
    final Triangle triangle = new Triangle(a, b, c).setFillColor(BG_COLOR).setFillAlpha(ALPHA).setStrokeWidth(0);
    final Rectangle rectangle = new Rectangle(width + (isWest ? TRIANGLE_SIZE : 0), height + (isNorth ? TRIANGLE_SIZE : 0)).setX(isWest ? TRIANGLE_SIZE : 0).setY(isWest ? 0 : TRIANGLE_SIZE).setCornerRadius(10).setFillColor(BG_COLOR).setFillAlpha(ALPHA).setStrokeAlpha(0).setCornerRadius(5);
    final Group decorator = new Group();
    decorator.add(rectangle);
    decorator.add(triangle);
    return decorator;
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) Point2D(com.ait.lienzo.client.core.types.Point2D) Triangle(com.ait.lienzo.client.core.shape.Triangle) Rectangle(com.ait.lienzo.client.core.shape.Rectangle)

Example 60 with Group

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

the class PrimitiveTooltip method show.

public PrimitiveTooltip show(final IPrimitive<?> _glyph, final String text, final Point2D location, final double width, final double height, final Direction direction) {
    clearTimers();
    final IPrimitive<?> glyph = null != _glyph ? (IPrimitive<?>) _glyph.copy() : null;
    final Text descText = new Text(text).setFontSize(TEXT_SIZE).setFontStyle("").setFontFamily(TEXT_FAMILY).setStrokeWidth(TEXT_WIDTH).setStrokeColor(TEXT_COLOR).setStrokeAlpha(1);
    final BoundingBox descTextBB = descText.getBoundingBox();
    final double descTextBbW = descTextBB.getWidth();
    final double descTextBbH = descTextBB.getHeight();
    final double dw = (descTextBbW > width ? (descTextBbW + PADDING) : (width + PADDING));
    final double dh = height + descTextBbH + PADDING;
    final IPrimitive<?> decorator = buildDecorator(dw, dh, direction);
    final double w = dw + (isWest(direction) ? TRIANGLE_SIZE * 2 : 0);
    final double h = dh + (isNorth(direction) ? TRIANGLE_SIZE * 2 : 0);
    ;
    final Group g = new Group();
    g.add(decorator);
    if (null != glyph) {
        g.add(glyph);
    }
    g.add(descText);
    super.show(g, w, h, location.getX(), location.getY());
    double _x = (w / 2) + (isWest(direction) ? PADDING / 2 : 0);
    double _y = PADDING / 2 + (isNorth(direction) ? TRIANGLE_SIZE : 0);
    if (null != glyph) {
        glyph.setX(_x - (width / 2));
        glyph.setY(_y);
        _x += width;
        _y += height;
    }
    descText.setX(_x - (descTextBbW / 2));
    descText.setY(_y + descTextBbH);
    // Ensure text is on top.
    descText.moveToTop();
    canvasLayer.draw();
    startTimers();
    return this;
}
Also used : Group(com.ait.lienzo.client.core.shape.Group) BoundingBox(com.ait.lienzo.client.core.types.BoundingBox) Text(com.ait.lienzo.client.core.shape.Text)

Aggregations

Group (com.ait.lienzo.client.core.shape.Group)66 Test (org.junit.Test)17 Rectangle (com.ait.lienzo.client.core.shape.Rectangle)10 Before (org.junit.Before)10 Text (com.ait.lienzo.client.core.shape.Text)9 GridRenderer (org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.grids.GridRenderer)8 Layer (com.ait.lienzo.client.core.shape.Layer)7 Point2D (com.ait.lienzo.client.core.types.Point2D)7 Command (org.uberfire.mvp.Command)6 BoundingBox (com.ait.lienzo.client.core.types.BoundingBox)4 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)4 Line (com.ait.lienzo.client.core.shape.Line)3 ArrayList (java.util.ArrayList)3 SVGContainer (org.kie.workbench.common.stunner.svg.client.shape.view.SVGContainer)3 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)3 GridRendererTheme (org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.themes.GridRendererTheme)3 IPathClipper (com.ait.lienzo.client.core.shape.IPathClipper)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)2 WiresShape (com.ait.lienzo.client.core.shape.wires.WiresShape)2 Point2DArray (com.ait.lienzo.client.core.types.Point2DArray)2