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

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

源代码1 项目: arma-dialog-creator   文件: ADCCanvasView.java
@Override
public void handle(MouseEvent event) {
	//use this so that when the mouse moves over the canvas and something in canvas controls has focus, the key presses
	//and mouse events are sent to the canvas rather than the focuses control
	canvasView.focusToCanvas(event.getTarget() == canvasView.uiCanvasEditor.getCanvas());

	double sceneX = event.getSceneX();
	double sceneY = event.getSceneY();
	for (Node node : canvasView.notificationPane.getContentPane().getChildren()) {
		Point2D point2D = node.sceneToLocal(sceneX, sceneY);
		if (node.contains(point2D)) {
			canvasView.notificationPane.getContentPane().setMouseTransparent(false);
			return;
		}
	}
	canvasView.notificationPane.getContentPane().setMouseTransparent(true);

}
 
源代码2 项目: chart-fx   文件: EditDataSet.java
protected void performPointDrag(final MouseEvent event) {
    if (event.getButton() == MouseButton.PRIMARY && !controlDown && isPointDragActive) {
        if (mouseOriginX < 0) {
            mouseOriginX = event.getSceneX();
        }
        if (mouseOriginY < 0) {
            mouseOriginY = event.getSceneY();
        }
        final double deltaX = event.getSceneX() - mouseOriginX;
        final double deltaY = event.getSceneY() - mouseOriginY;

        // get the latest mouse coordinate.
        mouseOriginX = event.getSceneX();
        mouseOriginY = event.getSceneY();

        applyDrag(deltaX, deltaY);
        event.consume();
    } else {
        isPointDragActive = false;
    }
}
 
源代码3 项目: mzmine2   文件: Fx3DStageController.java
public void handleMouseDragged(MouseEvent me) {
    double rotateFactor = 0.12;
    mousePosX = me.getSceneX();
    mousePosY = me.getSceneY();
    if (me.isPrimaryButtonDown()) {
        rotateX.setAngle(rotateX.getAngle()
                + rotateFactor * (mousePosY - mouseOldY));
        rotateY.setAngle(rotateY.getAngle()
                - rotateFactor * (mousePosX - mouseOldX));
    }
    if (me.isSecondaryButtonDown()) {
        translateX.setX(translateX.getX() + (mousePosX - mouseOldX));
        translateY.setY(translateY.getY() + (mousePosY - mouseOldY));

    }
    mouseOldX = mousePosX;
    mouseOldY = mousePosY;
}
 
源代码4 项目: gef   文件: MouseDragSnippet.java
protected void onMousePress(MouseEvent event) {
	pressed = (Node) event.getTarget();
	System.out.println("press " + pressed);
	startMousePosition = new Point2D(event.getSceneX(), event.getSceneY());
	startLayoutPosition = new Point2D(pressed.getLayoutX(),
			pressed.getLayoutY());

	// add effect
	pressed.setEffect(new Bloom(0));
	IAnchor ifxAnchor = anchors.get(pressed);
	if (ifxAnchor != null) {
		Set<AnchorKey> keys = ifxAnchor.positionsUnmodifiableProperty()
				.keySet();
		for (AnchorKey key : keys) {
			key.getAnchored().setEffect(null);
		}
	}
}
 
源代码5 项目: gef   文件: BendOnSegmentDragHandler.java
@Override
public void drag(MouseEvent e, Dimension delta) {
	if (isInvalid) {
		return;
	}

	Point newEndPointInScene = new Point(e.getSceneX(), e.getSceneY());
	if (snapToSupport != null) {
		if (!isPrecise(e)) {
			newEndPointInScene.translate(snapToSupport.snap(delta));
		} else {
			snapToSupport.clearSnappingFeedback();
		}
	}

	// perform changes
	bendPolicy.move(initialMouseInScene, newEndPointInScene);
	updateHandles();
}
 
源代码6 项目: jace   文件: WolfensteinCheats.java
private void processMouseEvent(MouseEvent evt) {
    if (evt.isPrimaryButtonDown() || evt.isSecondaryButtonDown()) {
        Node source = (Node) evt.getSource();
        double mouseX = evt.getSceneX() / source.getBoundsInLocal().getWidth();
        double mouseY = evt.getSceneY() / source.getBoundsInLocal().getHeight();
        int x = Math.max(0, Math.min(7, (int) ((mouseX - 0.148) * 11)));
        int y = Math.max(0, Math.min(7, (int) ((mouseY - 0.101) * 11)));
        int location = x + (y << 3);
        if (evt.getButton() == MouseButton.PRIMARY) {
            killEnemyAt(location);
        } else {
            teleportTo(location);
        }
    }
}
 
源代码7 项目: chart-fx   文件: ChartPlugin.java
/**
 * Converts mouse location within the scene to the location relative to the plot area.
 *
 * @param event mouse event
 * @return location within the plot area
 */
protected final Point2D getLocationInPlotArea(final MouseEvent event) {
    final Point2D mouseLocationInScene = new Point2D(event.getSceneX(), event.getSceneY());
    final Chart chart = getChart();
    if (!(chart instanceof XYChart)) {
        return null;
    }
    final XYChart xyChart = (XYChart) chart;
    final double xInAxis = ((Node) xyChart.getXAxis()).sceneToLocal(mouseLocationInScene).getX();
    final double yInAxis = ((Node) xyChart.getYAxis()).sceneToLocal(mouseLocationInScene).getY();
    return new Point2D(xInAxis, yInAxis);
}
 
源代码8 项目: 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();
}
 
源代码9 项目: fxgraph   文件: CellGestures.java
private static void dragNorth(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) {
	final double deltaY = event.getSceneY() - mouseLocation.value.getY();
	final double newY = region.getLayoutY() + deltaY;
	if(newY != 0 && newY >= handleRadius && newY <= region.getLayoutY() + region.getHeight() - handleRadius) {
		region.setLayoutY(newY);
		region.setPrefHeight(region.getPrefHeight() - deltaY);
	}
}
 
源代码10 项目: fxgraph   文件: CellGestures.java
private static void dragSouth(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) {
	final double deltaY = event.getSceneY() - mouseLocation.value.getY();
	final double newMaxY = region.getLayoutY() + region.getHeight() + deltaY;
	if(newMaxY >= region.getLayoutY() && newMaxY <= region.getParent().getBoundsInLocal().getHeight() - handleRadius) {
		region.setPrefHeight(region.getPrefHeight() + deltaY);
	}
}
 
源代码11 项目: graph-editor   文件: GeometryUtils.java
/**
 * Gets the position of the cursor relative to some node.
 *
 * @param event a {@link MouseEvent} storing the cursor position
 * @param node some {@link Node}
 *
 * @return the position of the cursor relative to the node origin
 */
public static Point2D getCursorPosition(final MouseEvent event, final Node node) {

    final double sceneX = event.getSceneX();
    final double sceneY = event.getSceneY();

    final double containerSceneX = node.localToScene(0, 0).getX();
    final double containerSceneY = node.localToScene(0, 0).getY();

    return new Point2D(sceneX - containerSceneX, sceneY - containerSceneY);
}
 
源代码12 项目: FXyzLib   文件: CameraController.java
private Point2D getMouseDelta(MouseEvent event) {
    Point2D res = new Point2D(event.getSceneX() - previousX, event.getSceneY() - previousY);
    previousX = event.getSceneX();
    previousY = event.getSceneY();

    return res;
}
 
源代码13 项目: mzmine3   文件: Fx3DStageController.java
public void handleMousePressed(MouseEvent me) {
  mouseOldX = me.getSceneX();
  mouseOldY = me.getSceneY();
}
 
源代码14 项目: JavaFX-Chat   文件: ResizeHelper.java
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(),
            mouseEventY = mouseEvent.getSceneY(),
            sceneWidth = scene.getWidth(),
            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) == false) {
            if (Cursor.W_RESIZE.equals(cursorEvent) == false && Cursor.E_RESIZE.equals(cursorEvent) == false) {
                double minHeight = stage.getMinHeight() > (border*2) ? stage.getMinHeight() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.N_RESIZE.equals(cursorEvent) == true || Cursor.NE_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        stage.setHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        stage.setHeight(mouseEventY + startY);
                    }
                }
            }

            if (Cursor.N_RESIZE.equals(cursorEvent) == false && Cursor.S_RESIZE.equals(cursorEvent) == false) {
                double minWidth = stage.getMinWidth() > (border*2) ? stage.getMinWidth() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.W_RESIZE.equals(cursorEvent) == true || Cursor.SW_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        stage.setWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        stage.setWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
源代码15 项目: CustomStage   文件: ResizeHelper.java
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(),
            mouseEventY = mouseEvent.getSceneY(),
            sceneWidth = scene.getWidth(),
            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);
                if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.N_RESIZE.equals(cursorEvent)
                        || Cursor.NE_RESIZE.equals(cursorEvent)) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        setStageHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        setStageHeight(mouseEventY + startY);
                    }
                }
            }

            if (!Cursor.N_RESIZE.equals(cursorEvent) && !Cursor.S_RESIZE.equals(cursorEvent)) {
                double minWidth = stage.getMinWidth() > (border * 2) ? stage.getMinWidth() : (border * 2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) || Cursor.W_RESIZE.equals(cursorEvent)
                        || Cursor.SW_RESIZE.equals(cursorEvent)) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        setStageWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        setStageWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
源代码16 项目: ApkToolPlus   文件: ResizeHelper.java
@Override
public void handle(MouseEvent mouseEvent) {
    EventType<? extends MouseEvent> mouseEventType = mouseEvent.getEventType();
    Scene scene = stage.getScene();

    double mouseEventX = mouseEvent.getSceneX(), 
           mouseEventY = mouseEvent.getSceneY(),
           sceneWidth = scene.getWidth(),
           sceneHeight = scene.getHeight();

    if (MouseEvent.MOUSE_MOVED.equals(mouseEventType) == true) {
        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_PRESSED.equals(mouseEventType) == true) {
        startX = stage.getWidth() - mouseEventX;
        startY = stage.getHeight() - mouseEventY;
    } else if (MouseEvent.MOUSE_DRAGGED.equals(mouseEventType) == true) {
        if (Cursor.DEFAULT.equals(cursorEvent) == false) {
            if (Cursor.W_RESIZE.equals(cursorEvent) == false && Cursor.E_RESIZE.equals(cursorEvent) == false) {
                double minHeight = stage.getMinHeight() > (border*2) ? stage.getMinHeight() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.N_RESIZE.equals(cursorEvent) == true || Cursor.NE_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getHeight() > minHeight || mouseEventY < 0) {
                        stage.setHeight(stage.getY() - mouseEvent.getScreenY() + stage.getHeight());
                        stage.setY(mouseEvent.getScreenY());
                    }
                } else {
                    if (stage.getHeight() > minHeight || mouseEventY + startY - stage.getHeight() > 0) {
                        stage.setHeight(mouseEventY + startY);
                    }
                }
            }

            if (Cursor.N_RESIZE.equals(cursorEvent) == false && Cursor.S_RESIZE.equals(cursorEvent) == false) {
                double minWidth = stage.getMinWidth() > (border*2) ? stage.getMinWidth() : (border*2);
                if (Cursor.NW_RESIZE.equals(cursorEvent) == true || Cursor.W_RESIZE.equals(cursorEvent) == true || Cursor.SW_RESIZE.equals(cursorEvent) == true) {
                    if (stage.getWidth() > minWidth || mouseEventX < 0) {
                        stage.setWidth(stage.getX() - mouseEvent.getScreenX() + stage.getWidth());
                        stage.setX(mouseEvent.getScreenX());
                    }
                } else {
                    if (stage.getWidth() > minWidth || mouseEventX + startX - stage.getWidth() > 0) {
                        stage.setWidth(mouseEventX + startX);
                    }
                }
            }
        }

    }
}
 
源代码17 项目: gef   文件: RotateSelectedOnHandleDragHandler.java
@Override
public void startDrag(MouseEvent e) {
	// do nothing when the user does not press control
	invalidGesture = !isRotate(e);
	if (invalidGesture) {
		return;
	}

	// save pointer location for later angle calculation
	initialPointerLocationInScene = new Point(e.getSceneX(), e.getSceneY());
	targetParts = determineTargetParts();
	if (targetParts == null) {
		targetParts = Collections.emptyList();
	}
	Rectangle bounds = PartUtils.getUnionedVisualBoundsInScene(targetParts);
	if (bounds == null) {
		throw new IllegalStateException(
				"Cannot determine visual bounds (null).");
	}
	pivotInScene = bounds.getCenter();

	// initialize for all target parts
	rotationIndices.clear();
	for (IContentPart<? extends Node> part : getTargetParts()) {
		// transform pivot point to local coordinates
		TransformPolicy transformPolicy = getTransformPolicy(part);
		if (transformPolicy != null) {
			storeAndDisableRefreshVisuals(part);
			init(transformPolicy);
			// transform pivot to parent coordinates
			Point pivotInLocal = FX2Geometry
					.toPoint(getHost().getVisual().getParent()
							.sceneToLocal(pivotInScene.x, pivotInScene.y));
			// create transformations
			int translateIndex = transformPolicy.createPostTransform();
			int rotateIndex = transformPolicy.createPostTransform();
			int translateBackIndex = transformPolicy.createPostTransform();
			// set translation transforms
			transformPolicy.setPostTranslate(translateIndex,
					-pivotInLocal.x, -pivotInLocal.y);
			transformPolicy.setPostTranslate(translateBackIndex,
					pivotInLocal.x, pivotInLocal.y);
			// save rotation index for later adjustment
			rotationIndices.put(part, rotateIndex);
		}
	}
}
 
@Override
public void drag(MouseEvent e, Dimension delta) {
	// guard against uninitialized access
	if (invalidGesture) {
		return;
	}

	// compute end point
	Node visual = getTargetPart().getVisual();
	Point newEndScene = new Point(e.getSceneX(), e.getSceneY());

	// compute delta in scene
	Point deltaInScene = new Point(newEndScene.x - initialPointerLocation.x,
			newEndScene.y - initialPointerLocation.y);

	// apply delta to the moved vertex
	Point newVertex = initialVertex.getTranslated(deltaInScene);

	// snap the moved vertex (unless isPrecise(e))
	Point snappedVertex = newVertex;
	if (snapToSupport != null) {
		if (!isPrecise(e)) {
			snappedVertex.translate(snapToSupport
					.snap(new Dimension(deltaInScene.x, deltaInScene.y)));
		} else {
			snapToSupport.clearSnappingFeedback();
		}
	}

	// compute delta between initial and snapped vertex
	Point2D startLocal = visual.sceneToLocal(initialVertex.x,
			initialVertex.y);
	Point2D endLocal = visual.sceneToLocal(snappedVertex.x,
			snappedVertex.y);

	// compute delta in local coordinates
	double deltaX = endLocal.getX() - startLocal.getX();
	double deltaY = endLocal.getY() - startLocal.getY();

	// segment index determines logical position (0 = top left, 1 = top
	// right, 2 = bottom right, 3 = bottom left)
	int segment = getHost().getSegmentIndex();

	// determine resize in local coordinates
	double ldw, ldh;
	if (segment == 1 || segment == 2) {
		// right side
		ldw = deltaX;
	} else {
		// left side
		ldw = -deltaX;
	}
	if (segment == 2 || segment == 3) {
		// bottom side
		ldh = deltaY;
	} else {
		// top side
		ldh = -deltaY;
	}

	// XXX: Resize before querying the applicable delta, so that the minimum
	// size is respected.
	getResizePolicy().resize(ldw, ldh);
	Dimension applicableDelta = new Dimension(
			getResizePolicy().getDeltaWidth(),
			getResizePolicy().getDeltaHeight());

	// Only apply translation if possible, i.e. if the resize cannot be
	// applied in total, the translation can probably not be applied in
	// total as well.
	if (applicableDelta.width != ldw) {
		deltaX = applicableDelta.width;
		if (segment == 0 || segment == 3) {
			deltaX = -deltaX;
		}
	}
	if (applicableDelta.height != ldh) {
		deltaY = applicableDelta.height;
		if (segment == 0 || segment == 1) {
			deltaY = -deltaY;
		}
	}

	// compute (local) translation
	double ldx = segment == 0 || segment == 3 ? deltaX : 0;
	double ldy = segment == 0 || segment == 1 ? deltaY : 0;

	// apply translation
	getTransformPolicy().setPreTranslate(translationIndex, ldx, ldy);
}
 
@Override
public void startDrag(MouseEvent e) {
	setTargetPart(determineTargetPart());
	invalidGesture = !isResizeTranslate(e);
	if (invalidGesture) {
		return;
	}
	ITransformableContentPart<? extends Node> targetPart = getTargetPart();
	storeAndDisableRefreshVisuals(targetPart);
	initialPointerLocation = new Point(e.getSceneX(), e.getSceneY());
	init(getResizePolicy());
	init(getTransformPolicy());
	translationIndex = getTransformPolicy().createPreTransform();
	// determine initial bounds in scene
	Bounds layoutBounds = targetPart.getVisual().getLayoutBounds();
	Bounds initialBoundsInScene = targetPart.getVisual()
			.localToScene(layoutBounds);
	// save moved vertex
	int segment = getHost().getSegmentIndex();
	if (segment == 0) {
		initialVertex = new Point(initialBoundsInScene.getMinX(),
				initialBoundsInScene.getMinY());
	} else if (segment == 1) {
		initialVertex = new Point(initialBoundsInScene.getMaxX(),
				initialBoundsInScene.getMinY());
	} else if (segment == 2) {
		initialVertex = new Point(initialBoundsInScene.getMaxX(),
				initialBoundsInScene.getMaxY());
	} else if (segment == 3) {
		initialVertex = new Point(initialBoundsInScene.getMinX(),
				initialBoundsInScene.getMaxY());
	}

	snapToSupport = targetPart.getViewer().getAdapter(SnapToSupport.class);
	if (snapToSupport != null) {
		SnappingLocation hssl = new SnappingLocation(targetPart,
				Orientation.HORIZONTAL, initialVertex.x);
		SnappingLocation vssl = new SnappingLocation(targetPart,
				Orientation.VERTICAL, initialVertex.y);
		snapToSupport.startSnapping(targetPart, Arrays.asList(hssl, vssl));
	}
}
 
源代码20 项目: gef   文件: RotateSelectedOnHandleDragHandler.java
/**
 * Computes the clock-wise rotation angle based on the initial mouse
 * position and the actual mouse position.
 *
 * @param e
 *            The latest {@link MouseEvent}.
 * @param part
 *            The {@link IVisualPart} that is rotated.
 * @return The clock-wise rotation angle.
 */
protected Angle computeRotationAngleCW(MouseEvent e,
		IVisualPart<? extends Node> part) {
	Vector vStart = new Vector(pivotInScene, initialPointerLocationInScene);
	Vector vEnd = new Vector(pivotInScene,
			new Point(e.getSceneX(), e.getSceneY()));
	Angle angle = vStart.getAngleCW(vEnd);
	return angle;
}