Java Code Examples for javafx.scene.input.MouseEvent#getScreenY()
The following examples show how to use
javafx.scene.input.MouseEvent#getScreenY() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockUIPanel.java From AnchorFX with GNU Lesser General Public License v3.0 | 6 votes |
private void manageDragEvent(MouseEvent event) { if (!node.draggingProperty().get()) { if (!node.maximizingProperty().get()) { Bounds bounds = node.localToScreen(barPanel.getBoundsInLocal()); deltaDragging = new Point2D(event.getScreenX() - bounds.getMinX(), event.getScreenY() - bounds.getMinY()); node.enableDraggingOnPosition(event.getScreenX() - deltaDragging.getX(), event.getScreenY() - deltaDragging.getY()); } } else { if (node.getFloatableStage() != null && !node.getFloatableStage().inResizing() && node.draggingProperty().get()) { if (!node.maximizingProperty().get()) { node.moveFloatable(event.getScreenX() - deltaDragging.getX(), event.getScreenY() - deltaDragging.getY()); //node.stationProperty().get().searchTargetNode(event.getScreenX(), event.getScreenY()); AnchorageSystem.searchTargetNode(event.getScreenX(), event.getScreenY()); } } } }
Example 2
Source File: DragAndDropHandler.java From FxDock with Apache License 2.0 | 6 votes |
protected static void onDragDetected(MouseEvent ev, FxDockPane client) { if(dragWindow == null) { double x = ev.getScreenX(); double y = ev.getScreenY(); Point2D p = client.screenToLocal(x, y); deltax = p.getX(); deltay = p.getY(); // gets modified in createDragWindow() dragWindow = createDragWindow(client); dragWindow.addEventHandler(KeyEvent.KEY_PRESSED, (ke) -> cancelDrag()); dragWindow.setX(x - deltax); dragWindow.setY(y - deltay); dragWindow.show(); ev.consume(); } }
Example 3
Source File: UndecoratorController.java From DevToolBox with GNU Lesser General Public License v2.1 | 6 votes |
/** * Based on mouse position returns dock side * * @param mouseEvent * @return DOCK_LEFT,DOCK_RIGHT,DOCK_TOP */ int getDockSide(MouseEvent mouseEvent) { double minX = Double.POSITIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxX = 0; double maxY = 0; // Get "big" screen bounds ObservableList<Screen> screens = Screen.getScreens(); for (Screen screen : screens) { Rectangle2D visualBounds = screen.getVisualBounds(); minX = Math.min(minX, visualBounds.getMinX()); minY = Math.min(minY, visualBounds.getMinY()); maxX = Math.max(maxX, visualBounds.getMaxX()); maxY = Math.max(maxY, visualBounds.getMaxY()); } // Dock Left if (mouseEvent.getScreenX() == minX) { return DOCK_LEFT; } else if (mouseEvent.getScreenX() >= maxX - 1) { // MaxX returns the width? Not width -1 ?! return DOCK_RIGHT; } else if (mouseEvent.getScreenY() <= minY) { // Mac menu bar return DOCK_TOP; } return 0; }
Example 4
Source File: NodeGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { final Node node = (Node) event.getSource(); double offsetX = event.getScreenX() + dragContext.x; double offsetY = event.getScreenY() + dragContext.y; // adjust the offset in case we are zoomed final double scale = graph.getScale(); offsetX /= scale; offsetY /= scale; node.relocate(offsetX, offsetY); } }
Example 5
Source File: Zoomer.java From chart-fx with Apache License 2.0 | 5 votes |
private boolean isMouseEventWithinCanvas(final MouseEvent mouseEvent) { final Canvas canvas = getChart().getCanvas(); // listen to only events within the canvas final Point2D mouseLoc = new Point2D(mouseEvent.getScreenX(), mouseEvent.getScreenY()); final Bounds screenBounds = canvas.localToScreen(canvas.getBoundsInLocal()); return screenBounds.contains(mouseLoc); }
Example 6
Source File: JFXDecorator.java From JFoenix with Apache License 2.0 | 5 votes |
private void updateInitMouseValues(MouseEvent mouseEvent) { initStageX = primaryStage.getX(); initStageY = primaryStage.getY(); initWidth = primaryStage.getWidth(); initHeight = primaryStage.getHeight(); initX = mouseEvent.getScreenX(); initY = mouseEvent.getScreenY(); xOffset = mouseEvent.getSceneX(); yOffset = mouseEvent.getSceneY(); }
Example 7
Source File: DragAndDropHandler.java From FxDock with Apache License 2.0 | 5 votes |
protected static void onMouseDragged(MouseEvent ev, FxDockPane client) { if(dragWindow != null) { double x = ev.getScreenX(); double y = ev.getScreenY(); dragWindow.setX(x - deltax); dragWindow.setY(y - deltay); DropOp op = createDropOp(client, x, y); setDropOp(op); } }
Example 8
Source File: HoverGesture.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Updates the hover intent position (and restarts the hover intent delay) * if the mouse was moved too much. * * @param event * The {@link MouseEvent}. */ private void updateHoverIntentPosition(MouseEvent event) { if (hoverIntentDelay.getStatus().equals(Status.RUNNING)) { double dx = hoverIntentScreenPosition.x - event.getScreenX(); double dy = hoverIntentScreenPosition.y - event.getScreenY(); double threshold = getHoverIntentMouseMoveThreshold(); if (Math.abs(dx) > threshold || Math.abs(dy) > threshold) { hoverIntentDelay.playFromStart(); hoverIntentScreenPosition.x = event.getScreenX(); hoverIntentScreenPosition.y = event.getScreenY(); } } }
Example 9
Source File: HoverGesture.java From gef with Eclipse Public License 2.0 | 5 votes |
/** * Updates hover intent delays depending on the given event and hovered * node. * * @param event * The {@link MouseEvent}. * @param eventTarget * The hovered {@link Node}. */ private void updateHoverIntent(MouseEvent event, Node eventTarget) { if (eventTarget != hoverIntent) { potentialHoverIntent = eventTarget; hoverIntentScreenPosition = new Point(event.getScreenX(), event.getScreenY()); hoverIntentDelay.playFromStart(); } else { hoverIntentDelay.stop(); } }
Example 10
Source File: NodeGestures.java From fxgraph with Do What The F*ck You Want To Public License | 5 votes |
@Override public void handle(MouseEvent event) { final Node node = (Node) event.getSource(); final double scale = graph.getScale(); dragContext.x = node.getBoundsInParent().getMinX() * scale - event.getScreenX(); dragContext.y = node.getBoundsInParent().getMinY() * scale - event.getScreenY(); }
Example 11
Source File: WebViewEventDispatcher.java From oim-fx with MIT License | 5 votes |
private void processMouseEvent(MouseEvent ev) { if (page == null) { return; } // RT-24511 EventType<? extends MouseEvent> type = ev.getEventType(); double x = ev.getX(); double y = ev.getY(); double screenX = ev.getScreenX(); double screenY = ev.getScreenY(); if (type == MouseEvent.MOUSE_EXITED) { type = MouseEvent.MOUSE_MOVED; x = Short.MIN_VALUE; y = Short.MIN_VALUE; Point2D screenPoint = webView.localToScreen(x, y); if (screenPoint == null) { return; } screenX = screenPoint.getX(); screenY = screenPoint.getY(); } final Integer id = idMap.get(type); if (id == null) { // not supported by webkit return; } WCMouseEvent mouseEvent = new WCMouseEvent(id, idMap.get(ev.getButton()), ev.getClickCount(), (int) x, (int) y, (int) screenX, (int) screenY, System.currentTimeMillis(), ev.isShiftDown(), ev.isControlDown(), ev.isAltDown(), ev.isMetaDown(), ev.isPopupTrigger()); page.dispatchMouseEvent(mouseEvent); ev.consume(); }
Example 12
Source File: DragSupport.java From scenic-view with GNU General Public License v3.0 | 5 votes |
private double getCoord(MouseEvent t, Orientation orientation) { switch (orientation) { case HORIZONTAL: return t.getScreenX(); case VERTICAL: return -t.getScreenY(); default: throw new IllegalArgumentException("This orientation is not supported: " + orientation); } }
Example 13
Source File: EditDataSet.java From chart-fx with Apache License 2.0 | 5 votes |
protected boolean isMouseEventWithinCanvas(final MouseEvent mouseEvent) { final Canvas canvas = getChart().getCanvas(); // listen to only events within the canvas final Point2D mouseLoc = new Point2D(mouseEvent.getScreenX(), mouseEvent.getScreenY()); final Bounds screenBounds = canvas.localToScreen(canvas.getBoundsInLocal()); return screenBounds.contains(mouseLoc); }
Example 14
Source File: DataViewWindow.java From chart-fx with Apache License 2.0 | 5 votes |
private void dragFinish(final MouseEvent mevt) { if (isMinimised() || getParentView() == null || getParentView().getMinimisedChildren().contains(this)) { return; } if (!mouseFilter.test(mevt)) { return; } uninstallCursor(); if (!isDetachableWindow()) { return; } // detach only if window is dragged outside Scene if (getScene() == null) { return; } final Point2D mouseLoc = new Point2D(mevt.getScreenX(), mevt.getScreenY()); final Window window = getScene().getWindow(); final Bounds sceneBounds = new BoundingBox(window.getX(), window.getY(), window.getWidth(), window.getHeight()); final Bounds screenBounds = localToScreen(WindowDecoration.FRAME.equals(getWindowDecoration()) ? this.getBoundsInLocal() : getWindowDecorationBar().getBoundsInLocal()); if (MouseUtils.mouseOutsideBoundaryBoxDistance(screenBounds, mouseLoc) > MIN_DRAG_BORDER_WIDTH && MouseUtils.mouseOutsideBoundaryBoxDistance(sceneBounds, mouseLoc) > MIN_DRAG_BORDER_WIDTH) { // mouse move outside window and surrounding stage detected -- launch dialog if (!dialog.isShowing()) { dialog.show(this, mevt); return; } dialog.setX(mevt.getScreenX() - xOffset); dialog.setY(mevt.getScreenY() - yOffset); return; } if (!dialog.isShowing()) { return; } dialog.setX(mevt.getScreenX() - xOffset); dialog.setY(mevt.getScreenY() - yOffset); }
Example 15
Source File: ResizeHelper.java From Path-of-Leveling with MIT License | 4 votes |
@Override public void handle(MouseEvent mouseEvent) { EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType(); Scene scene = stage.getScene(); double mouseEventX = mouseEvent.getSceneX(); double mouseEventY = mouseEvent.getSceneY(); double sceneWidth = scene.getWidth(); double sceneHeight = scene.getHeight(); if (MouseEvent.MOUSE_MOVED.equals(mouseEventType)) { if (mouseEventX < border && mouseEventY < border) { cursorEvent = Cursor.NW_RESIZE; } else if (mouseEventX < border && mouseEventY > sceneHeight - border) { cursorEvent = Cursor.SW_RESIZE; } else if (mouseEventX > sceneWidth - border && mouseEventY < border) { cursorEvent = Cursor.NE_RESIZE; } else if (mouseEventX > sceneWidth - border && mouseEventY > sceneHeight - border) { cursorEvent = Cursor.SE_RESIZE; } else if (mouseEventX < border) { cursorEvent = Cursor.W_RESIZE; } else if (mouseEventX > sceneWidth - border) { cursorEvent = Cursor.E_RESIZE; } else if (mouseEventY < border) { cursorEvent = Cursor.N_RESIZE; } else if (mouseEventY > sceneHeight - border) { cursorEvent = Cursor.S_RESIZE; } else { cursorEvent = Cursor.DEFAULT; } scene.setCursor(cursorEvent); } else if (MouseEvent.MOUSE_EXITED.equals(mouseEventType) || MouseEvent.MOUSE_EXITED_TARGET.equals(mouseEventType)) { scene.setCursor(Cursor.DEFAULT); } else if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType)) { startX = stage.getWidth() - mouseEventX; startY = stage.getHeight() - mouseEventY; } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType)) { if (!Cursor.DEFAULT.equals(cursorEvent)) { if (!Cursor.W_RESIZE.equals(cursorEvent) && !Cursor.E_RESIZE.equals(cursorEvent)) { double minHeight = stage.getMinHeight() > (border * 2) ? stage.getMinHeight() : (border * 2); double maxHeight = stage.getMaxHeight(); if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.N_RESIZE.equals(cursorEvent) || Cursor.NE_RESIZE.equals(cursorEvent)) { double newHeight = stage.getHeight() - (mouseEvent.getScreenY() - stage.getY()); if (newHeight >= minHeight && newHeight <= maxHeight) { stage.setHeight(newHeight); stage.setY(mouseEvent.getScreenY()); } else { newHeight = Math.min(Math.max(newHeight, minHeight), maxHeight); // y1 + h1 = y2 + h2 // y1 = y2 + h2 - h1 stage.setY(stage.getY() + stage.getHeight() - newHeight); stage.setHeight(newHeight); } } else { stage.setHeight(Math.min(Math.max(mouseEventY + startY, minHeight), maxHeight)); } } if (!Cursor.N_RESIZE.equals(cursorEvent) && !Cursor.S_RESIZE.equals(cursorEvent)) { double minWidth = stage.getMinWidth() > (border * 2) ? stage.getMinWidth() : (border * 2); double maxWidth = stage.getMaxWidth(); if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.W_RESIZE.equals(cursorEvent) || Cursor.SW_RESIZE.equals(cursorEvent)) { double newWidth = stage.getWidth() - (mouseEvent.getScreenX() - stage.getX()); if (newWidth >= minWidth && newWidth <= maxWidth) { stage.setWidth(newWidth); stage.setX(mouseEvent.getScreenX()); } else { newWidth = Math.min(Math.max(newWidth, minWidth), maxWidth); // x1 + w1 = x2 + w2 // x1 = x2 + w2 - w1 stage.setX(stage.getX() + stage.getWidth() - newWidth); stage.setWidth(newWidth); } } else { stage.setWidth(Math.min(Math.max(mouseEventX + startX, minWidth), maxWidth)); } } } } if (MouseEvent.MOUSE_PRESSED.equals(mouseEventType)) { startScreenX = mouseEvent.getScreenX(); startScreenY = mouseEvent.getScreenY(); } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType)) { if (Cursor.DEFAULT.equals(cursorEvent) && !stage.isMaximized()) { stage.setX(stage.getX() + mouseEvent.getScreenX() - startScreenX); startScreenX = mouseEvent.getScreenX(); stage.setY(stage.getY() + mouseEvent.getScreenY() - startScreenY); startScreenY = mouseEvent.getScreenY(); } } }
Example 16
Source File: CreateCurveOnDragHandler.java From gef with Eclipse Public License 2.0 | 4 votes |
@Override public void startDrag(MouseEvent event) { // create new curve GeometricCurve curve = new GeometricCurve(new Point[] { new Point(), new Point() }, MvcLogoExample.GEF_COLOR_GREEN, MvcLogoExample.GEF_STROKE_WIDTH, MvcLogoExample.GEF_DASH_PATTERN, null); curve.addSourceAnchorage(getShapePart().getContent()); // create using CreationPolicy from root part CreationPolicy creationPolicy = getHost().getRoot().getAdapter(CreationPolicy.class); init(creationPolicy); curvePart = (GeometricCurvePart) creationPolicy.create(curve, getHost().getRoot(), HashMultimap.<IContentPart<? extends Node>, String> create()); commit(creationPolicy); // disable refresh visuals for the curvePart storeAndDisableRefreshVisuals(curvePart); // move curve to pointer location curvePart.getVisual().setEndPoint(getLocation(event)); // build operation to deselect all but the new curve part List<IContentPart<? extends Node>> toBeDeselected = new ArrayList<>( getHost().getRoot().getViewer().getAdapter(SelectionModel.class).getSelectionUnmodifiable()); toBeDeselected.remove(curvePart); DeselectOperation deselectOperation = new DeselectOperation(getHost().getRoot().getViewer(), toBeDeselected); // execute on stack try { getHost().getRoot().getViewer().getDomain().execute(deselectOperation, new NullProgressMonitor()); } catch (ExecutionException e) { throw new RuntimeException(e); } // find bend target part bendTargetPart = findBendTargetPart(curvePart, event.getTarget()); if (bendTargetPart != null) { dragPolicies = bendTargetPart.getAdapters(ClickDragGesture.ON_DRAG_POLICY_KEY); } if (dragPolicies != null) { MouseEvent dragEvent = new MouseEvent(event.getSource(), event.getTarget(), MouseEvent.MOUSE_DRAGGED, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), event.getButton(), event.getClickCount(), event.isShiftDown(), event.isControlDown(), event.isAltDown(), event.isMetaDown(), event.isPrimaryButtonDown(), event.isMiddleButtonDown(), event.isSecondaryButtonDown(), event.isSynthesized(), event.isPopupTrigger(), event.isStillSincePress(), event.getPickResult()); for (IOnDragHandler dragPolicy : dragPolicies.values()) { dragPolicy.startDrag(event); // XXX: send initial drag event so that the end position is set dragPolicy.drag(dragEvent, new Dimension()); } } }
Example 17
Source File: FxDump.java From FxDock with Apache License 2.0 | 4 votes |
protected void handleMouseEvent(MouseEvent ev) { x = ev.getScreenX(); y = ev.getScreenY(); r = ev.getPickResult(); }
Example 18
Source File: JFXDecorator.java From JFoenix with Apache License 2.0 | 4 votes |
private void handleDragEventOnDecoratorPane(MouseEvent mouseEvent) { isDragging = true; if (!mouseEvent.isPrimaryButtonDown() || (xOffset == -1 && yOffset == -1)) { return; } /* * Long press generates drag event! */ if (primaryStage.isFullScreen() || mouseEvent.isStillSincePress() || primaryStage.isMaximized() || maximized) { return; } newX = mouseEvent.getScreenX(); newY = mouseEvent.getScreenY(); double deltax = newX - initX; double deltay = newY - initY; Cursor cursor = this.getCursor(); if (Cursor.E_RESIZE.equals(cursor)) { setStageWidth(initWidth + deltax); mouseEvent.consume(); } else if (Cursor.NE_RESIZE.equals(cursor)) { if (setStageHeight(initHeight - deltay)) { primaryStage.setY(initStageY + deltay); } setStageWidth(initWidth + deltax); mouseEvent.consume(); } else if (Cursor.SE_RESIZE.equals(cursor)) { setStageWidth(initWidth + deltax); setStageHeight(initHeight + deltay); mouseEvent.consume(); } else if (Cursor.S_RESIZE.equals(cursor)) { setStageHeight(initHeight + deltay); mouseEvent.consume(); } else if (Cursor.W_RESIZE.equals(cursor)) { if (setStageWidth(initWidth - deltax)) { primaryStage.setX(initStageX + deltax); } mouseEvent.consume(); } else if (Cursor.SW_RESIZE.equals(cursor)) { if (setStageWidth(initWidth - deltax)) { primaryStage.setX(initStageX + deltax); } setStageHeight(initHeight + deltay); mouseEvent.consume(); } else if (Cursor.NW_RESIZE.equals(cursor)) { if (setStageWidth(initWidth - deltax)) { primaryStage.setX(initStageX + deltax); } if (setStageHeight(initHeight - deltay)) { primaryStage.setY(initStageY + deltay); } mouseEvent.consume(); } else if (Cursor.N_RESIZE.equals(cursor)) { if (setStageHeight(initHeight - deltay)) { primaryStage.setY(initStageY + deltay); } mouseEvent.consume(); } else if (allowMove) { primaryStage.setX(mouseEvent.getScreenX() - xOffset); primaryStage.setY(mouseEvent.getScreenY() - yOffset); mouseEvent.consume(); } }
Example 19
Source File: PopOver.java From logbook-kai with MIT License | 4 votes |
/** * ポップアップの表示位置を設定します * * @param popup ポップアップ * @param anchorNode アンカーノード * @param event {@link MouseEvent} */ protected void setLocation(Popup popup, Node anchorNode, MouseEvent event) { double x = event.getScreenX(); double y = event.getScreenY(); double width = popup.getWidth(); double height = popup.getHeight(); double gapSize = this.getGapSize(); PopupWindow.AnchorLocation anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_LEFT; double gapX = gapSize; double gapY = gapSize; for (Screen screen : Screen.getScreens()) { Rectangle2D screenRect = screen.getVisualBounds(); // 右下 に表示可能であれば if (screenRect.contains(x + gapSize, y + gapSize, width, height)) { // PopupWindow視点でアンカーノードがTOP_LEFTの位置 anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_LEFT; gapX = gapSize; gapY = gapSize; break; } // 左下 if (screenRect.contains(x - gapSize - width, y + gapSize, width, height)) { anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_RIGHT; gapX = -gapSize; gapY = gapSize; break; } // 右上 if (screenRect.contains(x + gapSize, y - gapSize - height, width, height)) { anchorLocation = PopupWindow.AnchorLocation.CONTENT_BOTTOM_LEFT; gapX = gapSize; gapY = -gapSize; break; } // 左上 if (screenRect.contains(x - gapSize - width, y - gapSize - height, width, height)) { anchorLocation = PopupWindow.AnchorLocation.CONTENT_BOTTOM_RIGHT; gapX = -gapSize; gapY = -gapSize; break; } } popup.setAnchorLocation(anchorLocation); popup.setAnchorX(x + gapX); popup.setAnchorY(y + gapY); }