javafx.scene.input.MouseDragEvent Java Examples
The following examples show how to use
javafx.scene.input.MouseDragEvent.
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: ConnectorDragManager.java From graph-editor with Eclipse Public License 1.0 | 6 votes |
/** * Removes any previously existing mouse-drag event handlers from the connector's root JavaFX node that were added * by this class. * * @param connector the {@link GConnector} whose old handlers should be removed */ private void removeOldMouseDragHandlers(final GConnector connector) { final Node root = skinLookup.lookupConnector(connector).getRoot(); if (dragDetectedHandlers.get(connector) != null) { root.removeEventHandler(MouseEvent.DRAG_DETECTED, dragDetectedHandlers.get(connector)); } if (mouseDraggedHandlers.get(connector) != null) { root.removeEventHandler(MouseEvent.MOUSE_DRAGGED, mouseDraggedHandlers.get(connector)); } if (mouseDragEnteredHandlers.get(connector) != null) { root.removeEventHandler(MouseDragEvent.MOUSE_DRAG_ENTERED, mouseDragEnteredHandlers.get(connector)); } if (mouseDragExitedHandlers.get(connector) != null) { root.removeEventHandler(MouseDragEvent.MOUSE_DRAG_EXITED, mouseDragExitedHandlers.get(connector)); } if (mouseDragReleasedHandlers.get(connector) != null) { root.removeEventHandler(MouseDragEvent.MOUSE_DRAG_RELEASED, mouseDragReleasedHandlers.get(connector)); } }
Example #2
Source File: BasicView.java From gluon-samples with BSD 3-Clause "New" or "Revised" License | 5 votes |
BaseShape( BasicView view, Supplier<Shape> buildRootShape) { this.view = view; rootShape = buildRootShape.get(); view.select(rootShape); // select shape on click Disposable disposable = JavaFxObservable.eventsOf(rootShape, MouseEvent.MOUSE_CLICKED) .subscribe( e -> { view.select(rootShape); e.consume(); }); // dispose "listeners" when shape is removed from the scene JavaFxObservable.changesOf(rootShape.sceneProperty()) .filter( scene -> scene == null ) .subscribe( s -> disposable.dispose()); // calculate delta between shape location and initial mouse position on mouse pressed JavaFxObservable .eventsOf( rootShape, MouseEvent.MOUSE_PRESSED ) .map( e -> new Point2D( e.getSceneX(), e.getSceneY())) .subscribe( p -> { view.select(rootShape); Bounds bounds = rootShape.localToScene(rootShape.getLayoutBounds()); delta = p.subtract( new Point2D(bounds.getMinX(), bounds.getMinY()) ); }); // User current mouse position and delta to recalculate and set new shape location on mouse dragged JavaFxObservable .eventsOf( rootShape, MouseDragEvent.MOUSE_DRAGGED ) .map( e -> rootShape.sceneToLocal(e.getSceneX() - delta.getX(), e.getSceneY() - delta.getY())) .map( p -> rootShape.localToParent(p)) .subscribe( p -> rootShape.relocate( p.getX(), p.getY())); }
Example #3
Source File: ConnectorDragManager.java From graph-editor with Eclipse Public License 1.0 | 5 votes |
/** * Adds mouse-drag handlers to a particular connector. * * @param connector the {@link GConnector} to which mouse-drag handlers should be added */ private void addMouseDragHandlers(final GConnector connector) { final EventHandler<MouseEvent> newDragDetectedHandler = event -> handleDragDetected(event, connector); final EventHandler<MouseEvent> newMouseDraggedHandler = event -> handleMouseDragged(event, connector); final EventHandler<MouseDragEvent> newMouseDragEnteredHandler = event -> handleDragEntered(event, connector); final EventHandler<MouseDragEvent> newMouseDragExitedHandler = event -> handleDragExited(event, connector); final EventHandler<MouseDragEvent> newMouseDragReleasedHandler = event -> handleDragReleased(event, connector); final Node root = skinLookup.lookupConnector(connector).getRoot(); root.addEventHandler(MouseEvent.DRAG_DETECTED, newDragDetectedHandler); root.addEventHandler(MouseEvent.MOUSE_DRAGGED, newMouseDraggedHandler); root.addEventHandler(MouseDragEvent.MOUSE_DRAG_ENTERED, newMouseDragEnteredHandler); root.addEventHandler(MouseDragEvent.MOUSE_DRAG_EXITED, newMouseDragExitedHandler); root.addEventHandler(MouseDragEvent.MOUSE_DRAG_RELEASED, newMouseDragReleasedHandler); }
Example #4
Source File: EditDataSet.java From chart-fx with Apache License 2.0 | 4 votes |
SelectedDataPoint(final Axis xAxis, final Axis yAxis, final EditableDataSet dataSet, final int index) { super(); getStyleClass().add(STYLE_CLASS_SELECT_PATH); // this.setPickOnBounds(true); // setManaged(false); final EditConstraints constraints = dataSet.getEditConstraints(); if (constraints == null) { pseudoClassStateChanged(NOEDIT_PSEUDO_CLASS, false); } else { final boolean canChange = constraints.canChange(index); if (!canChange) { pseudoClassStateChanged(NOEDIT_PSEUDO_CLASS, true); } } this.xAxis = xAxis; this.yAxis = yAxis; this.dataSet = dataSet; this.xValue = dataSet.get(DataSet.DIM_X, index); this.yValue = dataSet.get(DataSet.DIM_Y, index); this.setCenterX(getX()); // NOPMD by rstein on 13/06/19 14:14 this.setCenterY(getY()); // NOPMD by rstein on 13/06/19 14:14 this.setRadius(DEFAULT_MARKER_RADIUS); final EventHandler<? super InputEvent> dragOver = e -> { // finished drag isPointDragActive = false; setCursor(Cursor.DEFAULT); }; setOnMouseEntered(e -> setCursor(Cursor.OPEN_HAND)); addEventFilter(MouseDragEvent.MOUSE_DRAG_OVER, dragOver); setOnMousePressed(startDragHandler(this)); // setOnMouseDragged(dragHandler(this)); setOnMouseReleased(dragOver); setOnMouseDragOver(dragOver); // this.setOnMouseExited(dragOver); xAxis.addListener(evt -> FXUtils.runFX(() -> this.setCenterX(getX()))); yAxis.addListener(evt -> FXUtils.runFX(() -> this.setCenterY(getY()))); dataSet.addListener(e -> FXUtils.runFX(this::update)); }