Search in sources :

Example 6 with ShapeView

use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.

the class CanvasInPlaceTextEditorControlImpl method register.

@Override
public void register(final Element element) {
    if (checkNotRegistered(element)) {
        final Shape<?> shape = getShape(element.getUUID());
        if (null != shape) {
            final ShapeView shapeView = shape.getShapeView();
            if (shapeView instanceof HasEventHandlers) {
                final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
                if (hasEventHandlers.supports(ViewEventType.TEXT_DBL_CLICK)) {
                    final TextDoubleClickHandler clickHandler = new TextDoubleClickHandler() {

                        @Override
                        public void handle(final TextDoubleClickEvent event) {
                            CanvasInPlaceTextEditorControlImpl.this.show(element, event.getClientX(), event.getClientY());
                        }
                    };
                    hasEventHandlers.addHandler(ViewEventType.TEXT_DBL_CLICK, clickHandler);
                    registerHandler(shape.getUUID(), clickHandler);
                    // Change mouse cursor, if shape supports it.
                    if (hasEventHandlers.supports(ViewEventType.TEXT_ENTER) && hasEventHandlers.supports(ViewEventType.TEXT_EXIT)) {
                        final TextEnterHandler enterHandler = new TextEnterHandler() {

                            @Override
                            public void handle(TextEnterEvent event) {
                                canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.TEXT);
                            }
                        };
                        hasEventHandlers.addHandler(ViewEventType.TEXT_ENTER, enterHandler);
                        registerHandler(shape.getUUID(), enterHandler);
                        final TextExitHandler exitHandler = new TextExitHandler() {

                            @Override
                            public void handle(TextExitEvent event) {
                                canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.AUTO);
                            }
                        };
                        hasEventHandlers.addHandler(ViewEventType.TEXT_EXIT, exitHandler);
                        registerHandler(shape.getUUID(), exitHandler);
                    }
                }
            }
        }
    }
}
Also used : TextEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.TextEnterEvent) TextEnterHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.TextEnterHandler) TextDoubleClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.TextDoubleClickEvent) TextExitHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.TextExitHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) TextExitEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.TextExitEvent) TextDoubleClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.TextDoubleClickHandler)

Example 7 with ShapeView

use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.

the class BPMNViewHandlersTest method testFontHandler.

@Test
@SuppressWarnings("unchecked")
public void testFontHandler() {
    final FontHandler<BPMNViewDefinition, ShapeView> fontHandler = new BPMNShapeViewHandlers.FontHandlerBuilder<>().build();
    final StartNoneEvent bean = new StartNoneEvent.StartNoneEventBuilder().build();
    bean.getFontSet().getFontColor().setValue("fontColor");
    bean.getFontSet().getFontFamily().setValue("fontFamily");
    bean.getFontSet().getFontSize().setValue(12d);
    bean.getFontSet().getFontBorderColor().setValue("borderColor");
    bean.getFontSet().getFontBorderSize().setValue(8d);
    fontHandler.handle(bean, view);
    verify(view, times(1)).setTitleFontColor(eq("fontColor"));
    verify(view, times(1)).setTitleFontFamily(eq("fontFamily"));
    verify(view, times(1)).setTitleFontSize(eq(12d));
    verify(view, times(1)).setTitleStrokeColor(eq("borderColor"));
    verify(view, times(1)).setTitleStrokeWidth(eq(8d));
}
Also used : ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) BPMNViewDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNViewDefinition) StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) Test(org.junit.Test)

Example 8 with ShapeView

use of org.kie.workbench.common.stunner.core.client.shape.view.ShapeView in project kie-wb-common by kiegroup.

the class BPMNViewHandlersTest method testViewHandler.

@Test
@SuppressWarnings("unchecked")
public void testViewHandler() {
    final ViewAttributesHandler<BPMNViewDefinition, ShapeView> fontHandler = new BPMNShapeViewHandlers.ViewAttributesHandlerBuilder<>().build();
    final StartNoneEvent bean = new StartNoneEvent.StartNoneEventBuilder().build();
    bean.getBackgroundSet().getBgColor().setValue("bgColor");
    bean.getBackgroundSet().getBorderColor().setValue("borderColor");
    bean.getBackgroundSet().getBorderSize().setValue(5d);
    fontHandler.handle(bean, view);
    verify(view, times(1)).setFillGradient(any(HasFillGradient.Type.class), eq("bgColor"), anyString());
    verify(view, times(1)).setStrokeColor(eq("borderColor"));
    verify(view, times(1)).setStrokeWidth(eq(5d));
}
Also used : ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) BPMNViewDefinition(org.kie.workbench.common.stunner.bpmn.definition.BPMNViewDefinition) StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) Test(org.junit.Test)

Aggregations

ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)8 Test (org.junit.Test)4 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)3 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)3 BPMNViewDefinition (org.kie.workbench.common.stunner.bpmn.definition.BPMNViewDefinition)2 StartNoneEvent (org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent)2 BoundingBox (org.kie.workbench.common.stunner.core.client.shape.view.BoundingBox)2 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)2 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)2 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)2 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)2 Collections (java.util.Collections)1 OptionalInt (java.util.OptionalInt)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1