use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent in project kie-wb-common by kiegroup.
the class ViewEventHandlerManagerTest method testMouseEXitHandler.
@Test
@SuppressWarnings("unchecked")
public void testMouseEXitHandler() {
final ViewHandler<ViewEvent> clickHandler = mock(ViewHandler.class);
final HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
when(shape.addNodeMouseExitHandler(any(NodeMouseExitHandler.class))).thenReturn(handlerRegistration);
tested.addHandler(ViewEventType.MOUSE_EXIT, clickHandler);
final ArgumentCaptor<NodeMouseExitHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseExitHandler.class);
verify(shape, times(1)).addNodeMouseExitHandler(clickHandlerArgumentCaptor.capture());
final NodeMouseExitHandler nodeCLickHandler = clickHandlerArgumentCaptor.getValue();
final NodeMouseExitEvent clickEvent = mock(NodeMouseExitEvent.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.onNodeMouseExit(clickEvent);
final ArgumentCaptor<ViewEvent> eventArgumentCaptor = ArgumentCaptor.forClass(ViewEvent.class);
verify(clickHandler, times(1)).handle(eventArgumentCaptor.capture());
final MouseExitEvent viewEvent = (MouseExitEvent) 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_EXIT));
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent in project kie-wb-common by kiegroup.
the class ViewEventHandlerManager method registerExitHandler.
protected HandlerRegistration[] registerExitHandler(final ViewHandler<ViewEvent> eventHandler) {
return new HandlerRegistration[] { shape.addNodeMouseExitHandler(e -> {
if (isEnabled()) {
final MouseExitEvent event = new MouseExitEvent(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);
}
}) };
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent 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 AbstractCanvas<?> canvas = canvasHandler.getAbstractCanvas();
final Shape<?> shape = canvas.getShape(element.getUUID());
final ShapeView shapeView = shape.getShapeView();
// Enable drag & ensure location constraints are set, if any.
shapeView.setDragEnabled(true);
ensureDragConstraints(canvas, shapeView);
// Register handlers.
if (shape.getShapeView() instanceof HasEventHandlers) {
final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
// 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.DEFAULT);
}
};
hasEventHandlers.addHandler(ViewEventType.MOUSE_EXIT, outHandler);
registerHandler(shape.getUUID(), outHandler);
// Adding DragHandler on the shape to check whether the moving shape is not selected, th
final DragHandler dragHandler = new DragHandler() {
@Override
public void start(DragEvent event) {
// Instead of firing the event on Drag start, now will be fired at the end, hence improving performance
}
@Override
public void end(DragEvent event) {
selectionEvent.fire(new CanvasSelectionEvent(canvasHandler, shape.getUUID()));
}
@Override
public void handle(DragEvent event) {
}
};
hasEventHandlers.addHandler(ViewEventType.DRAG, dragHandler);
registerHandler(shape.getUUID(), dragHandler);
}
}
}
}
Aggregations