javafx.scene.input.MouseEvent#getScreenX ( )源码实例Demo

下面列出了javafx.scene.input.MouseEvent#getScreenX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: DevToolBox   文件: UndecoratorController.java
/**
 * 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;
}
 
源代码2 项目: fxgraph   文件: NodeGestures.java
@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);
	}
}
 
源代码3 项目: FxDock   文件: DragAndDropHandler.java
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();
	}
}
 
源代码4 项目: AnchorFX   文件: DockUIPanel.java
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());
            }
        }
    }
}
 
源代码5 项目: chart-fx   文件: DataViewWindow.java
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);
}
 
源代码6 项目: chart-fx   文件: Zoomer.java
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);
}
 
源代码7 项目: chart-fx   文件: EditDataSet.java
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);
}
 
源代码8 项目: scenic-view   文件: DragSupport.java
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);
    }
}
 
源代码9 项目: oim-fx   文件: WebViewEventDispatcher.java
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();
}
 
源代码10 项目: fxgraph   文件: NodeGestures.java
@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();
}
 
源代码11 项目: gef   文件: HoverGesture.java
/**
 * 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();
	}
}
 
源代码12 项目: gef   文件: HoverGesture.java
/**
 * 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();
		}
	}
}
 
源代码13 项目: FxDock   文件: DragAndDropHandler.java
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);
	}
}
 
源代码14 项目: JFoenix   文件: JFXDecorator.java
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();
}
 
源代码15 项目: Path-of-Leveling   文件: ResizeHelper.java
@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();
        }
    }
}
 
源代码16 项目: gef   文件: CreateCurveOnDragHandler.java
@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());
		}
	}
}
 
源代码17 项目: FxDock   文件: FxDump.java
protected void handleMouseEvent(MouseEvent ev)
{
	x = ev.getScreenX();
	y = ev.getScreenY();
	r = ev.getPickResult();
}
 
源代码18 项目: JFoenix   文件: JFXDecorator.java
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();
    }
}
 
源代码19 项目: logbook-kai   文件: PopOver.java
/**
 * ポップアップの表示位置を設定します
 *
 * @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);
}