Search in sources :

Example 1 with RectDefinition

use of org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition in project kie-wb-common by kiegroup.

the class SVGViewDefinitionGeneratorTest method testGenerate.

@Test
public void testGenerate() throws Exception {
    final ViewFactory viewFactory = new ViewFactoryImpl("view1", "org.kie.test", "MyType.¢lass");
    final RectDefinition mainDef = new RectDefinition("rect1", 1, 2, 0);
    final CircleDefinition circleDefinition = new CircleDefinition("circle1", 25);
    final ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(ID, X, Y, WIDTH, HEIGHT, styleSheetDefinition, new ViewBoxDefinitionImpl(VBOX_MIN_X, VBOX_MIN_Y, VBOX_WIDTH, VBOX_HEIGHT), mainDef, circleDefinition);
    viewDefinition.setFactoryMethodName("svgViewTest");
    viewDefinition.setPath("svg-view-test.svg");
    final String generated = tested.generate(viewFactory, viewDefinition).toString();
    assertTrue(generated.contains("public SVGShapeViewResource svgViewTest()"));
    assertTrue(generated.contains("private SVGShapeView svgViewTestView(final boolean resizable)"));
    assertTrue(generated.contains("return this.svgViewTestView(25.50d, 225.45d, resizable);"));
    assertTrue(generated.contains("private SVGShapeView svgViewTestView(final double width, final double height, final boolean resizable) {"));
    assertTrue(generated.contains("final SVGShapeViewImpl view = new SVGShapeViewImpl(\"viewDef1\", mainShape, width, height, resizable)"));
    assertTrue(generated.contains("private SVGBasicShapeView svgViewTestBasicView() {"));
    assertTrue(generated.contains("return this.svgViewTestBasicView(25.50d, 225.45d);"));
    assertTrue(generated.contains("private SVGBasicShapeView svgViewTestBasicView(final double width, final double height) {"));
    assertTrue(generated.contains("final SVGBasicShapeViewImpl view = new SVGBasicShapeViewImpl(\"viewDef1\", mainShape, width, height)"));
}
Also used : CircleDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition) ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) ViewFactoryImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl) ViewFactory(org.kie.workbench.common.stunner.svg.gen.model.ViewFactory) ViewBoxDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewBoxDefinitionImpl) RectDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition) Test(org.junit.Test)

Example 2 with RectDefinition

use of org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition in project kie-wb-common by kiegroup.

the class RectangleDefinitionGeneratorTest method testGenerate.

@Test
public void testGenerate() throws Exception {
    final RectDefinition definition = new RectDefinition(ID, WIDTH, HEIGHT, CORNER_RADIUS);
    definition.setX(X);
    definition.setY(Y);
    definition.setAlpha(ALPHA);
    definition.setStyleDefinition(new StyleDefinitionImpl.Builder().setAlpha(ALPHA).setFillColor(FILL_COLOR).setFillAlpha(FILL_ALPHA).setStrokeColor(STROKE_COLOR).setStrokeAlpha(STROKE_ALPHA).setStrokeWidth(STROKE_WIDTH).build());
    definition.setTransformDefinition(new TransformDefinitionImpl(VBOX_WIDTH, VBOX_HEIGHT, VBOX_MIN_X, VBOX_MIN_Y));
    final String generated = tested.generate(definition).toString();
    assertTrue(generated.contains("new " + Rectangle.class.getName() + "(" + GeneratorAssertions.formatDouble(WIDTH) + ", " + GeneratorAssertions.formatDouble(HEIGHT) + ")"));
    GeneratorAssertions.assertDraggable(generated);
    GeneratorAssertions.assertID(generated, ID);
    GeneratorAssertions.assertX(generated, X);
    GeneratorAssertions.assertY(generated, Y);
    GeneratorAssertions.assertAlpha(generated, ALPHA);
    GeneratorAssertions.assertScale(generated, VBOX_WIDTH, VBOX_HEIGHT);
    GeneratorAssertions.assertFillColor(generated, FILL_COLOR);
    GeneratorAssertions.assertFillAlpha(generated, FILL_ALPHA);
    GeneratorAssertions.assertStrokeColor(generated, STROKE_COLOR);
    GeneratorAssertions.assertStrokeAlpha(generated, STROKE_ALPHA);
    GeneratorAssertions.assertStrokeWidth(generated, STROKE_WIDTH);
    GeneratorAssertions.assertListening(generated, LISTENING);
}
Also used : TransformDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.TransformDefinitionImpl) RectDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition) Test(org.junit.Test)

Example 3 with RectDefinition

use of org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition in project kie-wb-common by kiegroup.

the class SVGViewDefinitionGeneratorTest method testCheckReferencesExist.

@Test(expected = RuntimeException.class)
public void testCheckReferencesExist() throws Exception {
    final ViewFactory viewFactory = new ViewFactoryImpl("view1", "org.kie.test", "MyType.¢lass");
    final RectDefinition mainDef = new RectDefinition("rect1", 1, 2, 0);
    final CircleDefinition circleDefinition = new CircleDefinition("circle1", 25);
    final ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(ID, X, Y, WIDTH, HEIGHT, styleSheetDefinition, new ViewBoxDefinitionImpl(VBOX_MIN_X, VBOX_MIN_Y, VBOX_WIDTH, VBOX_HEIGHT), null, mainDef, circleDefinition);
    viewDefinition.setFactoryMethodName("svgViewTest");
    viewDefinition.setPath("svg-view-test.svg");
    final ViewRefDefinition refDefinition = new ViewRefDefinitionImpl("#circle1", "rect1", "circle1", "circle1");
    viewDefinition.getSVGViewRefs().add(refDefinition);
    tested.generate(viewFactory, viewDefinition).toString();
}
Also used : CircleDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition) ViewRefDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewRefDefinitionImpl) ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) ViewFactoryImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl) ViewFactory(org.kie.workbench.common.stunner.svg.gen.model.ViewFactory) ViewRefDefinition(org.kie.workbench.common.stunner.svg.gen.model.ViewRefDefinition) ViewBoxDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewBoxDefinitionImpl) RectDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition) Test(org.junit.Test)

Example 4 with RectDefinition

use of org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition in project kie-wb-common by kiegroup.

the class SVGDocumentTranslatorTest method testTranslate.

@Test
public void testTranslate() throws Exception {
    final ViewDefinition<SVGShapeView> viewDefinition = translator.translate(new SVGTranslatorContext(svgTest, "", styleSheetDefinition));
    assertNotNull(viewDefinition);
    assertEquals("svg-test-file", viewDefinition.getId());
    // View definition's viewBox.
    final ViewDefinition.ViewBoxDefinition viewBox = viewDefinition.getViewBox();
    assertNotNull(viewBox);
    final double minX = viewBox.getMinX();
    final double minY = viewBox.getMinY();
    final double width = viewBox.getWidth();
    final double height = viewBox.getHeight();
    assertEquals(minX, 0d, 0d);
    assertEquals(minY, 0d, 0d);
    assertEquals(width, 448d, 0d);
    assertEquals(height, 448d, 0d);
    // View definition's main shape.
    final PrimitiveDefinition mainShapeDef = viewDefinition.getMain();
    assertNotNull(mainShapeDef);
    assertTrue(mainShapeDef instanceof MultiPathDefinition);
    final MultiPathDefinition mainPathDef = (MultiPathDefinition) mainShapeDef;
    SVGTranslationTestAssertions.assertPath(mainPathDef);
    assertTrue(mainPathDef.isListening());
    // View definition's child shapes.
    final List<PrimitiveDefinition> childrenDefs = viewDefinition.getChildren();
    assertNotNull(childrenDefs);
    assertTrue(childrenDefs.size() == 3);
    final RectDefinition rectDefinition = (RectDefinition) childrenDefs.get(0);
    SVGTranslationTestAssertions.assertRectangle(rectDefinition);
    assertFalse(rectDefinition.isListening());
    final CircleDefinition circleDefinition = (CircleDefinition) childrenDefs.get(1);
    SVGTranslationTestAssertions.assertCircle(circleDefinition);
    assertFalse(circleDefinition.isListening());
    // Assert other svg reference elements.
    final GroupDefinition groupDefinition = (GroupDefinition) childrenDefs.get(2);
    assertFalse(groupDefinition.isListening());
    SVGTranslationTestAssertions.assertGroupRef(groupDefinition);
    final List<ViewRefDefinition> svgViewRefs = viewDefinition.getSVGViewRefs();
    assertNotNull(svgViewRefs);
    assertTrue(svgViewRefs.size() == 1);
    final ViewRefDefinition viewRefDef = svgViewRefs.get(0);
    SVGTranslationTestAssertions.assertViewRef(viewRefDef);
}
Also used : CircleDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition) ViewDefinition(org.kie.workbench.common.stunner.svg.gen.model.ViewDefinition) SVGShapeView(org.kie.workbench.common.stunner.svg.client.shape.view.SVGShapeView) PrimitiveDefinition(org.kie.workbench.common.stunner.svg.gen.model.PrimitiveDefinition) MultiPathDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.MultiPathDefinition) GroupDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.GroupDefinition) ViewRefDefinition(org.kie.workbench.common.stunner.svg.gen.model.ViewRefDefinition) SVGTranslatorContext(org.kie.workbench.common.stunner.svg.gen.translator.SVGTranslatorContext) RectDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 RectDefinition (org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition)4 CircleDefinition (org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition)3 ViewFactory (org.kie.workbench.common.stunner.svg.gen.model.ViewFactory)2 ViewRefDefinition (org.kie.workbench.common.stunner.svg.gen.model.ViewRefDefinition)2 ViewBoxDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewBoxDefinitionImpl)2 ViewDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl)2 ViewFactoryImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl)2 SVGShapeView (org.kie.workbench.common.stunner.svg.client.shape.view.SVGShapeView)1 PrimitiveDefinition (org.kie.workbench.common.stunner.svg.gen.model.PrimitiveDefinition)1 ViewDefinition (org.kie.workbench.common.stunner.svg.gen.model.ViewDefinition)1 GroupDefinition (org.kie.workbench.common.stunner.svg.gen.model.impl.GroupDefinition)1 MultiPathDefinition (org.kie.workbench.common.stunner.svg.gen.model.impl.MultiPathDefinition)1 TransformDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.TransformDefinitionImpl)1 ViewRefDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewRefDefinitionImpl)1 SVGTranslatorContext (org.kie.workbench.common.stunner.svg.gen.translator.SVGTranslatorContext)1