Search in sources :

Example 1 with MouseEnterEvent

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

the class LocationControlImpl method register.

@Override
@SuppressWarnings("unchecked")
public void register(final Element element) {
    if (null != element.asNode() && checkNotRegistered(element)) {
        final Canvas<?> canvas = canvasHandler.getCanvas();
        final Shape<?> shape = canvas.getShape(element.getUUID());
        // Drag & constraints.
        shape.getShapeView().setDragEnabled(true);
        if (shape.getShapeView() instanceof HasDragBounds) {
            ensureDragConstraints((HasDragBounds<?>) shape.getShapeView());
        }
        if (shape.getShapeView() instanceof HasEventHandlers) {
            final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
            // Change mouse cursor, if shape supports it.
            if (supportsMouseEnter(hasEventHandlers) && supportsMouseExit(hasEventHandlers)) {
                final MouseEnterHandler overHandler = new MouseEnterHandler() {

                    @Override
                    public void handle(MouseEnterEvent event) {
                        canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.MOVE);
                    }
                };
                hasEventHandlers.addHandler(ViewEventType.MOUSE_ENTER, overHandler);
                registerHandler(shape.getUUID(), overHandler);
                final MouseExitHandler outHandler = new MouseExitHandler() {

                    @Override
                    public void handle(MouseExitEvent event) {
                        canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.AUTO);
                    }
                };
                hasEventHandlers.addHandler(ViewEventType.MOUSE_EXIT, outHandler);
                registerHandler(shape.getUUID(), outHandler);
            }
        }
    }
}
Also used : HasDragBounds(org.kie.workbench.common.stunner.core.client.shape.view.HasDragBounds) MouseExitHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitHandler) MouseEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent) MouseExitEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) MouseEnterHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterHandler)

Example 2 with MouseEnterEvent

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

the class ViewEventHandlerManager method registerEnterHandler.

protected HandlerRegistration[] registerEnterHandler(final ViewHandler<ViewEvent> eventHandler) {
    return new HandlerRegistration[] { shape.addNodeMouseEnterHandler(e -> {
        if (isEnabled()) {
            final MouseEnterEvent event = new MouseEnterEvent(e.getX(), e.getY(), e.getMouseEvent().getClientX(), e.getMouseEvent().getClientY());
            event.setShiftKeyDown(e.isShiftKeyDown());
            event.setAltKeyDown(e.isAltKeyDown());
            event.setMetaKeyDown(e.isMetaKeyDown());
            eventHandler.handle(event);
        }
    }) };
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) MouseEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent)

Example 3 with MouseEnterEvent

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

the class ViewEventHandlerManagerTest method testMouseEnterHandler.

@Test
@SuppressWarnings("unchecked")
public void testMouseEnterHandler() {
    final ViewHandler<ViewEvent> clickHandler = mock(ViewHandler.class);
    final HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
    when(shape.addNodeMouseEnterHandler(any(NodeMouseEnterHandler.class))).thenReturn(handlerRegistration);
    tested.addHandler(ViewEventType.MOUSE_ENTER, clickHandler);
    final ArgumentCaptor<NodeMouseEnterHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseEnterHandler.class);
    verify(shape, times(1)).addNodeMouseEnterHandler(clickHandlerArgumentCaptor.capture());
    final NodeMouseEnterHandler nodeCLickHandler = clickHandlerArgumentCaptor.getValue();
    final NodeMouseEnterEvent clickEvent = mock(NodeMouseEnterEvent.class);
    final MouseEvent mouseEvent = mock(MouseEvent.class);
    final int x = 102;
    final int y = 410;
    when(clickEvent.getX()).thenReturn(x);
    when(clickEvent.getY()).thenReturn(y);
    when(clickEvent.isShiftKeyDown()).thenReturn(true);
    when(clickEvent.isAltKeyDown()).thenReturn(true);
    when(clickEvent.isMetaKeyDown()).thenReturn(true);
    when(clickEvent.getMouseEvent()).thenReturn(mouseEvent);
    when(mouseEvent.getClientX()).thenReturn(x);
    when(mouseEvent.getClientY()).thenReturn(y);
    nodeCLickHandler.onNodeMouseEnter(clickEvent);
    final ArgumentCaptor<ViewEvent> eventArgumentCaptor = ArgumentCaptor.forClass(ViewEvent.class);
    verify(clickHandler, times(1)).handle(eventArgumentCaptor.capture());
    final MouseEnterEvent viewEvent = (MouseEnterEvent) eventArgumentCaptor.getValue();
    assertEquals(x, viewEvent.getX(), 0d);
    assertEquals(y, viewEvent.getY(), 0d);
    assertEquals(x, viewEvent.getClientX(), 0d);
    assertEquals(y, viewEvent.getClientY(), 0d);
    assertTrue(viewEvent.isAltKeyDown());
    assertTrue(viewEvent.isMetaKeyDown());
    assertTrue(viewEvent.isShiftKeyDown());
    assertNotNull(tested.getRegistrationMap().get(ViewEventType.MOUSE_ENTER));
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) MouseEvent(com.google.gwt.event.dom.client.MouseEvent) ViewEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEvent) NodeMouseEnterEvent(com.ait.lienzo.client.core.event.NodeMouseEnterEvent) NodeMouseEnterEvent(com.ait.lienzo.client.core.event.NodeMouseEnterEvent) MouseEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent) NodeMouseEnterHandler(com.ait.lienzo.client.core.event.NodeMouseEnterHandler) Test(org.junit.Test)

Aggregations

MouseEnterEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent)3 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)2 NodeMouseEnterEvent (com.ait.lienzo.client.core.event.NodeMouseEnterEvent)1 NodeMouseEnterHandler (com.ait.lienzo.client.core.event.NodeMouseEnterHandler)1 MouseEvent (com.google.gwt.event.dom.client.MouseEvent)1 Test (org.junit.Test)1 HasDragBounds (org.kie.workbench.common.stunner.core.client.shape.view.HasDragBounds)1 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)1 MouseEnterHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterHandler)1 MouseExitEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent)1 MouseExitHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitHandler)1 ViewEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEvent)1