List of usage examples for javafx.scene.input MouseEvent getX
public final double getX()
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.TooltipHandlerFX.java
/** * Handles a mouse moved event by updating the tooltip. * //from w w w. j a v a 2s.c o m * @param canvas the chart canvas (<code>null</code> not permitted). * @param e the mouse event. */ @Override public void handleMouseMoved(ChartCanvas canvas, MouseEvent e) { if (!canvas.isTooltipEnabled()) { return; } String text = getTooltipText(canvas, e.getX(), e.getY()); canvas.setTooltip(text, e.getScreenX(), e.getScreenY()); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java
/** * Handles a mouse pressed event by recording the initial mouse pointer * location.// w ww . ja va 2s. co m * * @param canvas the JavaFX canvas (<code>null</code> not permitted). * @param e the mouse event (<code>null</code> not permitted). */ @Override public void handleMousePressed(ChartCanvas canvas, MouseEvent e) { Point2D pt = new Point2D.Double(e.getX(), e.getY()); Rectangle2D dataArea = canvas.findDataArea(pt); if (dataArea != null) { this.startPoint = ShapeUtilities.getPointInRectangle(e.getX(), e.getY(), dataArea); } else { this.startPoint = null; canvas.clearLiveHandler(); } }
From source file:de.pixida.logtest.designer.automaton.Graph.java
private void mouseMovedOnPane(final MouseEvent event) { // Using double properties here to avoid spamming the heap with immutable objects like Point2D this.lastMousePositionOnPaneX = event.getX(); this.lastMousePositionOnPaneY = event.getY(); if (this.connectorSourceNode != null) { Validate.notNull(this.connector); if (this.currentConnectorTargetNode == null) { // Otherwise, connector was already aligned when object was hovered this.connector.align(this.connectorSourceNode, new Point2D(event.getX(), event.getY())); }/*from w w w .j ava 2 s . com*/ } }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.PanHandlerFX.java
/** * Handles a mouse dragged event by calculating the distance panned and * updating the axes accordingly./*from w w w.j a v a 2 s . com*/ * * @param canvas the JavaFX canvas (<code>null</code> not permitted). * @param e the mouse event (<code>null</code> not permitted). */ public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) { if (this.panLast == null) { //handle panning if we have a start point else unregister canvas.clearLiveHandler(); return; } JFreeChart chart = canvas.getChart(); double dx = e.getX() - this.panLast.getX(); double dy = e.getY() - this.panLast.getY(); if (dx == 0.0 && dy == 0.0) { return; } double wPercent = -dx / this.panW; double hPercent = dy / this.panH; boolean old = chart.getPlot().isNotify(); chart.getPlot().setNotify(false); Pannable p = (Pannable) chart.getPlot(); PlotRenderingInfo info = canvas.getRenderingInfo().getPlotInfo(); if (p.getOrientation().isVertical()) { p.panDomainAxes(wPercent, info, this.panLast); p.panRangeAxes(hPercent, info, this.panLast); } else { p.panDomainAxes(hPercent, info, this.panLast); p.panRangeAxes(wPercent, info, this.panLast); } this.panLast = new Point2D.Double(e.getX(), e.getY()); chart.getPlot().setNotify(old); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.PanHandlerFX.java
/** * Handles a mouse pressed event by recording the initial mouse pointer * location./*ww w .jav a2s . c o m*/ * * @param canvas the JavaFX canvas (<code>null</code> not permitted). * @param e the mouse event (<code>null</code> not permitted). */ @Override public void handleMousePressed(ChartCanvas canvas, MouseEvent e) { Plot plot = canvas.getChart().getPlot(); if (!(plot instanceof Pannable)) { canvas.clearLiveHandler(); return; } Pannable pannable = (Pannable) plot; if (pannable.isDomainPannable() || pannable.isRangePannable()) { Point2D point = new Point2D.Double(e.getX(), e.getY()); Rectangle2D dataArea = canvas.findDataArea(point); if (dataArea != null && dataArea.contains(point)) { this.panW = dataArea.getWidth(); this.panH = dataArea.getHeight(); this.panLast = point; canvas.setCursor(javafx.scene.Cursor.MOVE); } } // the actual panning occurs later in the mouseDragged() method }
From source file:de.pixida.logtest.designer.automaton.Graph.java
public void onMousePressed(final BaseObject baseObject, final MouseEvent event) { if (this.showConfigFrameOfObject(baseObject)) { event.consume();/*w ww. j av a2s. com*/ } if (baseObject instanceof BaseNode) { final BaseNode baseNode = (BaseNode) baseObject; this.dragPressedPoint = new Point2D(event.getX(), event.getY()); this.dragOriginalObjectPosition = baseNode.getPosition(); } }
From source file:de.pixida.logtest.designer.automaton.Graph.java
public void onMouseDragged(final BaseObject baseObject, final MouseEvent event) { if (baseObject instanceof BaseNode) { final BaseNode baseNode = (BaseNode) baseObject; Validate.notNull(this.dragPressedPoint); Validate.notNull(this.dragOriginalObjectPosition); final Point2D mouseMovement = new Point2D(event.getX(), event.getY()).subtract(this.dragPressedPoint); if (mouseMovement.getX() != 0d || mouseMovement.getY() != 0d) { Point2D newRectPos = this.dragOriginalObjectPosition.add(mouseMovement); newRectPos = new Point2D(Math.max(0d, newRectPos.getX()), Math.max(0d, newRectPos.getY())); baseNode.moveTo(newRectPos); this.handleMinorChange(); }/*w w w .j ava2 s. c o m*/ } }
From source file:Main.java
private Node makeDraggable(final Node node) { final DragContext dragContext = new DragContext(); final Group wrapGroup = new Group(node); wrapGroup.addEventFilter(MouseEvent.ANY, new EventHandler<MouseEvent>() { public void handle(final MouseEvent mouseEvent) { if (dragModeActiveProperty.get()) { // disable mouse events for all children mouseEvent.consume();/*ww w .j ava 2 s . c o m*/ } } }); wrapGroup.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() { public void handle(final MouseEvent mouseEvent) { if (dragModeActiveProperty.get()) { // remember initial mouse cursor coordinates // and node position dragContext.mouseAnchorX = mouseEvent.getX(); dragContext.mouseAnchorY = mouseEvent.getY(); dragContext.initialTranslateX = node.getTranslateX(); dragContext.initialTranslateY = node.getTranslateY(); } } }); wrapGroup.addEventFilter(MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() { public void handle(final MouseEvent mouseEvent) { if (dragModeActiveProperty.get()) { // shift node from its initial position by delta // calculated from mouse cursor movement node.setTranslateX( dragContext.initialTranslateX + mouseEvent.getX() - dragContext.mouseAnchorX); node.setTranslateY( dragContext.initialTranslateY + mouseEvent.getY() - dragContext.mouseAnchorY); } } }); return wrapGroup; }
From source file:Main.java
public static java.awt.event.MouseEvent toAwt(final MouseEvent event) { final EventType type = event.getEventType(); if (null == type) { return null; }/*from w w w.ja va 2 s. c o m*/ final int id; if (MouseEvent.MOUSE_MOVED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_MOVED; } else if (MouseEvent.MOUSE_DRAGGED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_DRAGGED; } else if (MouseEvent.MOUSE_CLICKED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_CLICKED; } else if (MouseEvent.MOUSE_PRESSED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_PRESSED; } else if (MouseEvent.MOUSE_RELEASED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_RELEASED; } else if (MouseEvent.MOUSE_ENTERED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_ENTERED; } else if (MouseEvent.MOUSE_EXITED.equals(type)) { id = java.awt.event.MouseEvent.MOUSE_EXITED; } else { return null; } final int button; if (event.isPrimaryButtonDown()) { button = java.awt.event.MouseEvent.BUTTON1; } else if (event.isMiddleButtonDown()) { button = java.awt.event.MouseEvent.BUTTON2; } else if (event.isSecondaryButtonDown()) { button = java.awt.event.MouseEvent.BUTTON3; } else { button = java.awt.event.MouseEvent.NOBUTTON; } final long when = -1; final int modifiers = modifiers(event); final int x = (int) event.getX(); final int y = (int) event.getY(); final int xAbs = Integer.MAX_VALUE; final int yAbs = Integer.MAX_VALUE; final int count = event.getClickCount(); boolean popup = event.isPopupTrigger(); if (MouseEvent.MOUSE_CLICKED.equals(type) && event.isMetaDown()) { // mack books use meta flag for right-clicks popup = true; } return new java.awt.event.MouseEvent(empty, id, when, modifiers, x, y, xAbs, yAbs, count, popup, button); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java
@Override public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) { Plot p = canvas.getChart().getPlot(); if (!(p instanceof Zoomable)) { return;/*from w ww . ja va 2 s.c o m*/ } boolean hZoom, vZoom; Zoomable z = (Zoomable) p; if (z.getOrientation().isHorizontal()) { hZoom = z.isRangeZoomable(); vZoom = z.isDomainZoomable(); } else { hZoom = z.isDomainZoomable(); vZoom = z.isRangeZoomable(); } boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.startPoint.getX()) >= 10; boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.startPoint.getY()) >= 10; if (zoomTrigger1 || zoomTrigger2) { Point2D endPoint = new Point2D.Double(e.getX(), e.getY()); PlotRenderingInfo pri = canvas.getRenderingInfo().getPlotInfo(); if ((hZoom && (e.getX() < this.startPoint.getX())) || (vZoom && (e.getY() < this.startPoint.getY()))) { boolean saved = p.isNotify(); p.setNotify(false); z.zoomDomainAxes(0, pri, endPoint); z.zoomRangeAxes(0, pri, endPoint); p.setNotify(saved); } else { double x = this.startPoint.getX(); double y = this.startPoint.getY(); double w = e.getX() - x; double h = e.getY() - y; Rectangle2D dataArea = canvas.findDataArea(this.startPoint); double maxX = dataArea.getMaxX(); double maxY = dataArea.getMaxY(); // for mouseReleased event, (horizontalZoom || verticalZoom) // will be true, so we can just test for either being false; // otherwise both are true if (!vZoom) { y = dataArea.getMinY(); w = Math.min(w, maxX - this.startPoint.getX()); h = dataArea.getHeight(); } else if (!hZoom) { x = dataArea.getMinX(); w = dataArea.getWidth(); h = Math.min(h, maxY - this.startPoint.getY()); } else { w = Math.min(w, maxX - this.startPoint.getX()); h = Math.min(h, maxY - this.startPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); boolean saved = p.isNotify(); p.setNotify(false); double pw0 = percentW(x, dataArea); double pw1 = percentW(x + w, dataArea); double ph0 = percentH(y, dataArea); double ph1 = percentH(y + h, dataArea); PlotRenderingInfo info = this.viewer.getRenderingInfo().getPlotInfo(); if (z.getOrientation().isVertical()) { z.zoomDomainAxes(pw0, pw1, info, endPoint); z.zoomRangeAxes(1 - ph1, 1 - ph0, info, endPoint); } else { z.zoomRangeAxes(pw0, pw1, info, endPoint); z.zoomDomainAxes(1 - ph1, 1 - ph0, info, endPoint); } p.setNotify(saved); } } viewer.hideZoomRectangle(); this.startPoint = null; canvas.clearLiveHandler(); }