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;
}
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());
}
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());
}
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;
}
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;
}
Aggregations