@Override protected boolean changeTarget(Widget aMovableTarget, Widget aResizableTarget, int dx, int dy, MouseEvent<?> aEvent) { if (isNresizable()) { double newTop = targetScrollTop + dy; aMovableTarget.getElement().getStyle().setTop(newTop >= 0 ? newTop : 0, Style.Unit.PX); if (newTop >= 0) { aResizableTarget.getElement().getStyle().setHeight(targetHeight - dy, Style.Unit.PX); /* if (aResizableTarget instanceof RequiresResize) { ((RequiresResize) aResizableTarget).onResize(); } */ } return true; } else { return false; } }
@Override protected boolean changeTarget(Widget aMovableTarget, Widget aResizableTarget, int dx, int dy, MouseEvent<?> aEvent) { if (isWresizable()) { double newLeft = targetScrollLeft + dx; aMovableTarget.getElement().getStyle().setLeft(newLeft >= 0 ? newLeft : 0, Style.Unit.PX); if (newLeft >= 0) { aResizableTarget.getElement().getStyle().setWidth(targetWidth - dx, Style.Unit.PX); /* if (aResizableTarget instanceof RequiresResize) { ((RequiresResize) aResizableTarget).onResize(); } */ } return true; } else { return false; } }
private static Map<String,String> getMouseInfo(MouseEvent event) { Map<String,String> mouseInfo = new HashMap<String,String>(); int posX = -1; int posY = -1; try { // In QTree class a SelectionEvent is translated to a ClickEvent, // so position X and Y are not present (nativeEvent is null, is used to get the clientX and clientY) posX = event.getClientX(); posY = event.getClientY(); } catch (Exception e) { // Ignore } mouseInfo.put(EventDataI.MOUSE_X, String.valueOf(posX)); mouseInfo.put(EventDataI.MOUSE_Y, String.valueOf(posY)); return mouseInfo; }
@Override public Coordinate getLocation(HumanInputEvent<?> event, RenderSpace renderSpace) { switch (renderSpace) { case WORLD: Coordinate screen = getLocation(event, RenderSpace.SCREEN); return mapWidget.getMapModel().getMapView().getWorldViewTransformer().viewToWorld(screen); case SCREEN: default: if (event instanceof MouseEvent<?>) { Element element = mapWidget.getDOM(); double offsetX = ((MouseEvent<?>) event).getRelativeX(element); double offsetY = ((MouseEvent<?>) event).getRelativeY(element); return new Coordinate(offsetX, offsetY); } else if (event instanceof TouchEvent<?>) { Touch touch = ((TouchEvent<?>) event).getTouches().get(0); return new Coordinate(touch.getClientX(), touch.getClientY()); } return new Coordinate(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY()); } }
protected void createTempLines(FeatureTransaction featureTransaction, MouseEvent<?> event) { if (featureTransaction.getNewFeatures() != null && featureTransaction.getNewFeatures().length > 0 && tempLine1 == null) { Coordinate position = getPanPosition(event); Geometry geom = getGeometryIndex().getGeometry(featureTransaction); LineString lineString = geom.getGeometryFactory().createLineString(new Coordinate[] { position, position }); tempLine1 = new GfxGeometry("LineStringEditController.updateLine1"); tempLine1.setGeometry(lineString); tempLine1.setStyle(new ShapeStyle("#FFFFFF", 0, "#FF3322", 1, 1)); mapWidget.render(tempLine1, RenderGroup.VECTOR, RenderStatus.ALL); tempLine2 = new GfxGeometry("LineStringEditController.updateLine2"); tempLine2.setGeometry(lineString); tempLine2.setStyle(new ShapeStyle("#FFFFFF", 0, "#FF3322", 1, 1)); mapWidget.render(tempLine2, RenderGroup.VECTOR, RenderStatus.ALL); } }
public PressCancelEvent(MouseEvent<MouseOutHandler> sourceEvent) { super(sourceEvent); clientXPos = sourceEvent.getClientX(); clientYPos = sourceEvent.getClientY(); screenXPos = sourceEvent.getScreenX(); screenYPos = sourceEvent.getScreenY(); }
private void handleClickEvent(MouseEvent clickEvent) { Element clickedTarget = Element.as(clickEvent.getNativeEvent().getEventTarget()); if (clickedTarget.getClassName().contains("cr-component-cell") || clickedTarget.getClassName().contains("v-layout")) { NativeEvent event = cloneClickEvent(clickEvent); clickedTarget.getParentElement().dispatchEvent(event); } else { clickEvent.stopPropagation(); } }
private NativeEvent cloneClickEvent(MouseEvent clickEvent) { return Document.get().createClickEvent(SINGLE_CLICK, clickEvent.getNativeEvent().getScreenX(), clickEvent.getNativeEvent().getScreenY(), clickEvent.getNativeEvent().getClientX(), clickEvent.getNativeEvent().getClientY(), clickEvent.getNativeEvent().getCtrlKey(), clickEvent.getNativeEvent().getAltKey(), clickEvent.getNativeEvent().getShiftKey(), clickEvent.getNativeEvent().getMetaKey()); }
private int getAbsoluteX(HumanInputEvent ev) { if (ev instanceof MouseEvent) { return ((MouseEvent)ev).getClientX()+Window.getScrollLeft(); } if (ev instanceof TouchEvent) { JsArray<Touch> tAry= ((TouchEvent)ev).getTargetTouches(); return tAry.get(0).getClientX()+Window.getScrollLeft(); } return 0; }
private int getAbsoluteY(HumanInputEvent ev) { if (ev instanceof MouseEvent) { return ((MouseEvent)ev).getClientY()+ Window.getScrollTop(); } if (ev instanceof TouchEvent) { JsArray<Touch> tAry= ((TouchEvent)ev).getTargetTouches(); return tAry.get(0).getClientY() + Window.getScrollTop(); } return 0; }
private static Point getPoint(EventHandlingTarget drawPanelCanvas, HumanInputEvent<?> event) { Element e = drawPanelCanvas.getElement(); if (event instanceof MouseEvent<?>) { return new Point(((MouseEvent<?>) event).getRelativeX(e), ((MouseEvent<?>) event).getRelativeY(e)); } else if (event instanceof TouchEndEvent) { return new Point(((TouchEvent<?>) event).getChangedTouches().get(0).getRelativeX(e), ((TouchEvent<?>) event).getChangedTouches().get(0).getRelativeY(e)); } else if (event instanceof TouchEvent<?>) { return new Point(((TouchEvent<?>) event).getTouches().get(0).getRelativeX(e), ((TouchEvent<?>) event).getTouches().get(0).getRelativeY(e)); } else { throw new RuntimeException("Unknown Event Type: " + event); } }
private static Point getPointAbsolute(HumanInputEvent<?> event) { if (event instanceof MouseEvent<?>) { return new Point(((MouseEvent<?>) event).getClientX(), ((MouseEvent<?>) event).getClientY()); } else if (event instanceof TouchEndEvent) { return new Point(((TouchEvent<?>) event).getChangedTouches().get(0).getPageX(), ((TouchEvent<?>) event).getChangedTouches().get(0).getPageY()); } else if (event instanceof TouchEvent<?>) { return new Point(((TouchEvent<?>) event).getTouches().get(0).getPageX(), ((TouchEvent<?>) event).getTouches().get(0).getPageY()); } else { throw new RuntimeException("Unknown Event Type: " + event); } }
@SuppressWarnings("rawtypes") private Node findAtomicNodeForMouseEvent(MouseEvent me) { double x = (((double) me.getX()) / ((double) _gc.width())); double y = (((double) me.getY()) / ((double) _gc.height())); return _graph.findAtomicNodeAt(new Point(x, y)); }
@Override protected boolean changeTarget(Widget aMovableTarget, Widget aResizableTarget, int dx, int dy, MouseEvent<?> aEvent) { if (isSresizable()) { aResizableTarget.getElement().getStyle().setHeight(targetHeight + dy, Style.Unit.PX); /* if (aResizableTarget instanceof RequiresResize) { ((RequiresResize) aResizableTarget).onResize(); } */ return true; } else { return false; } }
@Override protected boolean changeTarget(Widget aMovableTarget, Widget aResizableTarget, int dx, int dy, MouseEvent<?> aEvent) { if (isEresizable()) { aResizableTarget.getElement().getStyle().setWidth(targetWidth + dx, Style.Unit.PX); /* if (aResizableTarget instanceof RequiresResize) { ((RequiresResize) aResizableTarget).onResize(); } */ return true; } else { return false; } }
@Override protected boolean changeTarget(Widget aMovableTarget, Widget aResizableTarget, int dx, int dy, MouseEvent<?> aEvent) { n.assignMouseState(nw); n.changeTarget(aMovableTarget, aResizableTarget, dx, dy, aEvent); w.assignMouseState(nw); w.changeTarget(aMovableTarget, aResizableTarget, dx, dy, aEvent); return true; }
@Override protected boolean changeTarget(Widget aMovableTarget, Widget aResizableTarget, int dx, int dy, MouseEvent<?> aEvent) { n.assignMouseState(ne); n.changeTarget(aMovableTarget, aResizableTarget, dx, dy, aEvent); e.assignMouseState(ne); e.changeTarget(aMovableTarget, aResizableTarget, dx, dy, aEvent); return true; }
@Override protected boolean changeTarget(Widget aMovableTarget, Widget aResizableTarget, int dx, int dy, MouseEvent<?> aEvent) { s.assignMouseState(sw); s.changeTarget(aMovableTarget, aResizableTarget, dx, dy, aEvent); w.assignMouseState(sw); w.changeTarget(aMovableTarget, aResizableTarget, dx, dy, aEvent); return true; }
@Override protected boolean changeTarget(Widget aMovableTarget, Widget aResizableTarget, int dx, int dy, MouseEvent<?> aEvent) { s.assignMouseState(se); s.changeTarget(aMovableTarget, aResizableTarget, dx, dy, aEvent); e.assignMouseState(se); e.changeTarget(aMovableTarget, aResizableTarget, dx, dy, aEvent); return true; }
/** * Given a click event, return the Cell that was clicked, or null if the event * did not hit this table. The cell can also be null if the click event does * not occur on a specific cell. * * @param event A click event of indeterminate origin * @return The appropriate cell, or null */ public Cell getCellForEvent(MouseEvent<? extends EventHandler> event) { Element td = getEventTargetCell(Event.as(event.getNativeEvent())); if (td == null) { return null; } int row = TableRowElement.as(td.getParentElement()).getSectionRowIndex(); int column = TableCellElement.as(td).getCellIndex(); return new Cell(row, column); }
protected void updateTempLineAfterMove(MouseEvent<?> event) { if (tempLine == null) { updateTempLineAfterClick(); } if (currentLineStringCoordinates != null && currentLineStringCoordinates.length > 0) { Coordinate[] newCoords = new Coordinate[currentLineStringCoordinates.length + 1]; System.arraycopy(currentLineStringCoordinates, 0, newCoords, 0, currentLineStringCoordinates.length); newCoords[currentLineStringCoordinates.length] = getPanPosition(event); LineString lineString = geometry.getGeometryFactory().createLineString(newCoords); tempLine.setGeometry(lineString); mapWidget.render(tempLine, RenderGroup.VECTOR, RenderStatus.UPDATE); } }
@Override protected void updateTempLineAfterMove(MouseEvent<?> event) { if (tempPolygon == null) { updateTempLineAfterClick(); } Polygon polygon = (Polygon) geometry; if (polygon != null && polygon.getCoordinates() != null && polygon.getCoordinates().length > 0) { LinearRing ring = geometry.getGeometryFactory().createLinearRing(polygon.getCoordinates()); if (ring != null && geometry.getCoordinates().length > 0) { Coordinate[] coordinates = ring.getCoordinates(); Coordinate firstCoordinate = coordinates[0]; Coordinate lastCoordinate = coordinates[coordinates.length - 2]; LineString lineStringPan = geometry.getGeometryFactory().createLineString(new Coordinate[] { getTransformer().worldToPan(lastCoordinate), getPanPosition(event), getTransformer().worldToPan(firstCoordinate) }); tempLine.setGeometry(lineStringPan); mapWidget.render(tempLine, RenderGroup.VECTOR, RenderStatus.ALL); } } }
private void updateGraphics(MouseEvent<?> event) { Coordinate position = getScreenPosition(event); double deltaX = position.getX() - getScreenCenter().getX(); double deltaY = position.getY() - getScreenCenter().getY(); radius = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY)); LineString radiusLine = mapWidget.getMapModel().getGeometryFactory().createLineString( new Coordinate[] { center, position }); mapWidget.getVectorContext().drawCircle(circleGroup, "outer", center, radius, circleStyle); mapWidget.getVectorContext().drawLine(circleGroup, "radius", radiusLine, circleStyle); }
protected void updateMeasure(MouseEvent event, boolean complete) { Geometry lastClickedLineGeometry = (Geometry) distanceLine.getOriginalLocation(); Coordinate lastClickedCoordinate = lastClickedLineGeometry.getCoordinates()[distanceLine.getGeometry() .getNumPoints() - 1]; Coordinate mouseCoordinate = getWorldPosition(event); lineSegment.setGeometry(getFactory().createLineString( new Coordinate[] { lastClickedCoordinate, mouseCoordinate })); mapWidget.render(mapWidget.getMapModel(), RenderGroup.VECTOR, RenderStatus.UPDATE); }
/** * Return the screen position of the mouse event, unless snapping is activated. If that is the case, a snapped * point will be returned (still in screen space). */ protected Coordinate getScreenPosition(MouseEvent<?> event) { if (snappingActive) { return getTransformer().worldToView(getWorldPosition(event)); } return super.getScreenPosition(event); }
/** * Return the screen position of the mouse event, unless snapping is activated. If that is the case, a snapped * point will be returned (still in pan space). */ protected Coordinate getPanPosition(MouseEvent<?> event) { if (snappingActive) { return getTransformer().worldToPan(getWorldPosition(event)); } return super.getPanPosition(event); }
/** * Return the world position of the mouse event, unless snapping is activated. If that is the case, a snapped point * will be returned (still in world space). */ protected Coordinate getWorldPosition(MouseEvent<?> event) { Coordinate world = super.getWorldPosition(event); if (snappingActive) { return snapper.snap(world); } return world; }
private void createTempLine(FeatureTransaction featureTransaction, MouseEvent<?> event) { if (featureTransaction.getNewFeatures() != null && featureTransaction.getNewFeatures().length > 0 && tempLine == null) { Coordinate position = getPanPosition(event); LineString lineString = getGeometryIndex().getGeometry(featureTransaction).getGeometryFactory() .createLineString(new Coordinate[] { position, position }); tempLine = new GfxGeometry("LineStringEditController.updateLine"); tempLine.setGeometry(lineString); tempLine.setStyle(new ShapeStyle("#FFFFFF", 0, "#FF3322", 1, 1)); mapWidget.render(tempLine, RenderGroup.VECTOR, RenderStatus.ALL); } }
private void updateTempLine(FeatureTransaction featureTransaction, MouseEvent<?> event) { if (featureTransaction.getNewFeatures() != null && featureTransaction.getNewFeatures().length > 0) { if (tempLine == null) { createTempLine(featureTransaction, event); } Coordinate[] coordinates = getGeometryIndex().getGeometry(featureTransaction).getCoordinates(); if (coordinates != null && coordinates.length > 0) { Coordinate lastCoordinate = getTransformer().worldToPan(coordinates[coordinates.length - 1]); LineString lineString = featureTransaction.getNewFeatures()[0].getGeometry().getGeometryFactory() .createLineString(new Coordinate[] { lastCoordinate, getPanPosition(event) }); tempLine.setGeometry(lineString); mapWidget.render(tempLine, RenderGroup.VECTOR, RenderStatus.ALL); } } }
protected void updateTempLines(FeatureTransaction featureTransaction, MouseEvent<?> event) { if (featureTransaction.getNewFeatures() != null && featureTransaction.getNewFeatures().length > 0) { if (tempLine1 == null) { createTempLines(featureTransaction, event); } Polygon polygon = (Polygon) getGeometryIndex().getGeometry(featureTransaction); LinearRing ring = getGeometryIndex().getLinearRing(polygon); if (ring != null) { Coordinate[] coordinates = ring.getCoordinates(); if (coordinates != null && coordinates.length > 0) { Coordinate lastCoordinate = coordinates[coordinates.length - 2]; LineString lineString1 = featureTransaction.getNewFeatures()[index.getFeatureIndex()].getGeometry() .getGeometryFactory().createLineString( new Coordinate[] {getTransformer().worldToPan(lastCoordinate), getPanPosition(event)}); tempLine1.setGeometry(lineString1); mapWidget.render(tempLine1, RenderGroup.VECTOR, RenderStatus.ALL); LineString lineString2 = featureTransaction.getNewFeatures()[index.getFeatureIndex()].getGeometry() .getGeometryFactory().createLineString( new Coordinate[] {getTransformer().worldToPan(coordinates[0]), getPanPosition(event)}); tempLine2.setGeometry(lineString2); mapWidget.render(tempLine2, RenderGroup.VECTOR, RenderStatus.ALL); } } } }
protected void updateTempLines(FeatureTransaction featureTransaction, MouseEvent<?> event) { if (featureTransaction.getNewFeatures() != null && featureTransaction.getNewFeatures().length > 0) { if (tempLine1 == null) { createTempLines(featureTransaction, event); } MultiPolygon multiPolygon = (MultiPolygon) getGeometryIndex().getGeometry(featureTransaction); LinearRing ring = getGeometryIndex().getLinearRing(multiPolygon.getGeometryN(0)); if (ring != null) { Coordinate[] coordinates = ring.getCoordinates(); if (coordinates != null && coordinates.length > 0) { Coordinate lastCoordinate = coordinates[coordinates.length - 2]; LineString lineString1 = featureTransaction.getNewFeatures()[index.getFeatureIndex()].getGeometry() .getGeometryFactory().createLineString( new Coordinate[] {getTransformer().worldToPan(lastCoordinate), getPanPosition(event)}); tempLine1.setGeometry(lineString1); mapWidget.render(tempLine1, RenderGroup.VECTOR, RenderStatus.ALL); LineString lineString2 = featureTransaction.getNewFeatures()[index.getFeatureIndex()].getGeometry() .getGeometryFactory().createLineString( new Coordinate[] {getTransformer().worldToPan(coordinates[0]), getPanPosition(event)}); tempLine2.setGeometry(lineString2); mapWidget.render(tempLine2, RenderGroup.VECTOR, RenderStatus.ALL); } } } }
@Override public boolean isRightMouseButton(HumanInputEvent<?> event) { if (event instanceof MouseEvent<?>) { return ((MouseEvent<?>) event).getNativeButton() == NativeEvent.BUTTON_RIGHT; } return false; }
@SuppressWarnings("unchecked") protected void testAddButton(final Consumer<MouseClickEvent> clickEventConsumer) { // Verify tootlip. verify(toolboxTooltip, times(1)).createItem(eq("title1")); verify(buttonItem, times(1)).tooltip(any(TooltipItem.class)); // Verify mouse enter. final ArgumentCaptor<NodeMouseEnterHandler> enterHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseEnterHandler.class); verify(buttonItem, times(1)).onMouseEnter(enterHandlerArgumentCaptor.capture()); final NodeMouseEnterHandler enterHandler = enterHandlerArgumentCaptor.getValue(); final NodeMouseEnterEvent mouseEnterEvent = mock(NodeMouseEnterEvent.class); enterHandler.onNodeMouseEnter(mouseEnterEvent); verify(canvasView, times(1)).setCursor(eq(AbstractCanvas.Cursors.POINTER)); // Verify mouse exit. final ArgumentCaptor<NodeMouseExitHandler> exitHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseExitHandler.class); verify(buttonItem, times(1)).onMouseExit(exitHandlerArgumentCaptor.capture()); final NodeMouseExitHandler exitHandler = exitHandlerArgumentCaptor.getValue(); final NodeMouseExitEvent mouseExitEvent = mock(NodeMouseExitEvent.class); exitHandler.onNodeMouseExit(mouseExitEvent); verify(canvasView, times(1)).setCursor(eq(AbstractCanvas.Cursors.AUTO)); // Verify mouse click. final ArgumentCaptor<NodeMouseClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseClickHandler.class); verify(buttonItem, times(1)).onClick(clickHandlerArgumentCaptor.capture()); final NodeMouseClickHandler clickHandler = clickHandlerArgumentCaptor.getValue(); final NodeMouseClickEvent mouseClickEvent = mock(NodeMouseClickEvent.class); when(mouseClickEvent.getMouseEvent()).thenReturn(mock(MouseEvent.class)); clickHandler.onNodeMouseClick(mouseClickEvent); verify(clickEventConsumer, times(1)).accept(any(MouseClickEvent.class)); }
private void updateMousePosition(MouseEvent<?> e) { mouse.x = e.getClientX(); mouse.y = e.getClientY(); OMSVGRect viewbox = svg.getViewBox().getBaseVal(); offset.x = (int) viewbox.getX(); offset.y = (int) viewbox.getY(); }
@Override public void contextHelpIconClick(MouseEvent event) { contextHelpIconClick(event.getNativeEvent()); }
private double[] canvasPosition(Canvas canvas, MouseEvent<?> e) { return new double[] { e.getRelativeX(canvas.getElement()), e.getRelativeY(canvas.getElement()) }; }
private void setColour(MouseEvent event, Canvas targetCanvas, VerticalPanel targetPanel) { setColour(event.getRelativeX(targetCanvas.getElement()), event.getRelativeY(targetCanvas.getElement()), targetCanvas, targetPanel); }
private void setHue(MouseEvent event, Canvas targetCanvas) { setHue(event.getRelativeX(targetCanvas.getElement()), event.getRelativeY(targetCanvas.getElement()), targetCanvas); }
public static Point FromMouseEvent(MouseEvent event) { return new Point(event.getClientX(), event.getClientY()); }
public static Point FromMouseEvent(MouseEvent event, Document doc) { return FromMouseEvent(event).plus(new Point(doc.getScrollLeft(), doc.getScrollTop())); }