Java Code Examples for javafx.scene.Node#setOnMouseDragged()
The following examples show how to use
javafx.scene.Node#setOnMouseDragged() .
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: DataViewWindow.java From chart-fx with Apache License 2.0 | 6 votes |
/** * @param content node that put into the BoderPane centre and depending on * {@link #windowDecorationProperty} with or w/o frame */ protected void setLocalCenter(final Node content) { switch (getWindowDecoration()) { case FRAME: if (content == null) { setCenter(null); break; } final Node node = new BorderedTitledPane(getName(), content); node.setOnMousePressed(this::dragStart); node.setOnMouseDragged(this::dragOngoing); node.setOnMouseReleased(this::dragFinish); setCenter(node); break; case BAR: case BAR_WO_CLOSE: case NONE: default: setCenter(content); break; } }
Example 2
Source File: IncDecSlider.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@Override protected Skin<?> createDefaultSkin() { final SliderSkin skin = (SliderSkin) super.createDefaultSkin(); // SliderSkin is accessible, but the more interesting // com.sun.javafx.scene.control.behavior.SliderBehavior // is not. // Work around this by locating 'track'... for (Node node : skin.getChildren()) if (node.getStyleClass().contains("track")) { // Capture mouse clicks, use to inc/dec instead of jumping there node.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> handleTrackClick(node, event)); // Disable mouse drag, which by default also jumps to mouse node.setOnMouseDragged(null); break; } return skin; }
Example 3
Source File: DragResizerUtil.java From chart-fx with Apache License 2.0 | 5 votes |
protected DragResizerUtil(Node node, OnDragResizeEventListener listener) { this.node = node; this.listener = listener != null ? listener : DEFAULT_LISTENER; if (node == null) { throw new IllegalArgumentException("node must not be null"); } node.setOnMousePressed(this::mousePressed); node.setOnMouseDragged(this::mouseDragged); node.setOnMouseMoved(this::mouseOver); node.setOnMouseReleased(this::mouseReleased); node.setOnMouseClicked(this::resetNodeSize); }
Example 4
Source File: PosGraphController.java From Motion_Profile_Generator with MIT License | 5 votes |
private void setOnPointEvent( XYChart.Data data ) { Node node = data.getNode(); node.setOnMouseEntered( event -> { node.setCursor( Cursor.HAND ); }); node.setOnMouseDragged( event -> { // get pixel location Point2D mouseSceneCoords = new Point2D( event.getSceneX(), event.getSceneY() ); double xLocal = axisPosX.sceneToLocal( mouseSceneCoords ).getX(); double yLocal = axisPosY.sceneToLocal( mouseSceneCoords ).getY(); // get location in units (ft, m, in) double raw_x = axisPosX.getValueForDisplay( xLocal ).doubleValue(); double raw_y = axisPosY.getValueForDisplay( yLocal ).doubleValue(); // round location double rnd_x; double rnd_y; // Snap to grid if( vars.getUnit() == Units.FEET ) { rnd_x = Mathf.round( raw_x, 0.5 ); rnd_y = Mathf.round( raw_y, 0.5 ); } else if( vars.getUnit() == Units.METERS ) { rnd_x = Mathf.round( raw_x, 0.25 ); rnd_y = Mathf.round( raw_y, 0.25 ); } else // Inches { rnd_x = Mathf.round( raw_x, 6.0 ); rnd_y = Mathf.round( raw_y, 6.0 ); } if( rnd_x >= axisPosX.getLowerBound() && rnd_x <= axisPosX.getUpperBound() ) { data.setXValue( rnd_x ); } if( rnd_y >= axisPosY.getLowerBound() && rnd_y <= axisPosY.getUpperBound() ) { data.setYValue( rnd_y ); } }); node.setOnMouseReleased( event -> { int index = Integer.parseInt( node.getId() ); Waypoint tmp = backend.getWaypoint( index ); tmp.setX( (Double) data.getXValue() ); tmp.setY( (Double) data.getYValue() ); }); }
Example 5
Source File: ViewUtils.java From ApkToolPlus with Apache License 2.0 | 5 votes |
/** * 注册拖拽事件 * * @param stage * @param root */ public static void registerDragEvent(Stage stage, Node root){ // allow the clock background to be used to drag the clock around. final Delta dragDelta = new Delta(); root.setOnMousePressed(mouseEvent -> { // record a delta distance for the drag and drop operation. dragDelta.x = stage.getX() - mouseEvent.getScreenX(); dragDelta.y = stage.getY() - mouseEvent.getScreenY(); }); root.setOnMouseDragged(mouseEvent -> { stage.setX(mouseEvent.getScreenX() + dragDelta.x); stage.setY(mouseEvent.getScreenY() + dragDelta.y); }); }
Example 6
Source File: ViewUtils.java From ApkToolPlus with Apache License 2.0 | 5 votes |
/** * 注册拖拽事件 * * @param dialog * @param root */ public static void registerDragEvent(Dialog dialog, Node root){ // allow the clock background to be used to drag the clock around. final Delta dragDelta = new Delta(); root.setOnMousePressed(mouseEvent -> { // record a delta distance for the drag and drop operation. dragDelta.x = dialog.getX() - mouseEvent.getScreenX(); dragDelta.y = dialog.getY() - mouseEvent.getScreenY(); }); root.setOnMouseDragged(mouseEvent -> { dialog.setX(mouseEvent.getScreenX() + dragDelta.x); dialog.setY(mouseEvent.getScreenY() + dragDelta.y); }); }
Example 7
Source File: NodeGestures.java From fxgraph with Do What The F*ck You Want To Public License | 4 votes |
public void makeDraggable(final Node node) { node.setOnMousePressed(onMousePressedEventHandler); node.setOnMouseDragged(onMouseDraggedEventHandler); node.setOnMouseReleased(onMouseReleasedEventHandler); }
Example 8
Source File: NodeGestures.java From fxgraph with Do What The F*ck You Want To Public License | 4 votes |
public void makeUndraggable(final Node node) { node.setOnMousePressed(null); node.setOnMouseDragged(null); node.setOnMouseReleased(null); }
Example 9
Source File: CrewEditorFX.java From mars-sim with GNU General Public License v3.0 | 4 votes |
/** * Makes a stage draggable using a given node. * * @param stage * @param byNode */ public void makeDraggable(final Stage stage, final Node byNode) { final Delta dragDelta = new Delta(); byNode.setOnMousePressed(mouseEvent -> { // record a delta distance for the drag and drop operation. dragDelta.x = stage.getX() - mouseEvent.getScreenX(); dragDelta.y = stage.getY() - mouseEvent.getScreenY(); byNode.setCursor(Cursor.MOVE); }); final BooleanProperty inDrag = new SimpleBooleanProperty(false); byNode.setOnMouseReleased(mouseEvent -> { byNode.setCursor(Cursor.HAND); if (inDrag.get()) { stage.hide(); Timeline pause = new Timeline(new KeyFrame(Duration.millis(50), event -> { background.setImage(copyBackground(stage)); layout.getChildren().set(0, background); scenarioConfigEditorFX.getMainMenu().setMonitor(stage); stage.show(); })); pause.play(); } inDrag.set(false); }); byNode.setOnMouseDragged(mouseEvent -> { stage.setX(mouseEvent.getScreenX() + dragDelta.x); stage.setY(mouseEvent.getScreenY() + dragDelta.y); layout.getChildren().set(0, makeSmoke(stage)); inDrag.set(true); }); byNode.setOnMouseEntered(mouseEvent -> { if (!mouseEvent.isPrimaryButtonDown()) { byNode.setCursor(Cursor.HAND); } }); byNode.setOnMouseExited(mouseEvent -> { if (!mouseEvent.isPrimaryButtonDown()) { byNode.setCursor(Cursor.DEFAULT); } }); }
Example 10
Source File: FrostyTech.java From mars-sim with GNU General Public License v3.0 | 4 votes |
public void makeDraggable(final Stage stage, final Node byNode) { final Delta dragDelta = new Delta(); byNode.setOnMousePressed(mouseEvent -> { // record a delta distance for the drag and drop operation. dragDelta.x = stage.getX() - mouseEvent.getScreenX(); dragDelta.y = stage.getY() - mouseEvent.getScreenY(); byNode.setCursor(Cursor.MOVE); }); final BooleanProperty inDrag = new SimpleBooleanProperty(false); byNode.setOnMouseReleased(mouseEvent -> { byNode.setCursor(Cursor.HAND); if (inDrag.get()) { stage.hide(); Timeline pause = new Timeline(new KeyFrame(Duration.millis(50), event -> { background.setImage(copyBackground(stage)); layout.getChildren().set( 0, background ); stage.show(); })); pause.play(); } inDrag.set(false); }); byNode.setOnMouseDragged(mouseEvent -> { stage.setX(mouseEvent.getScreenX() + dragDelta.x); stage.setY(mouseEvent.getScreenY() + dragDelta.y); layout.getChildren().set( 0, makeSmoke(stage) ); inDrag.set(true); }); byNode.setOnMouseEntered(mouseEvent -> { if (!mouseEvent.isPrimaryButtonDown()) { byNode.setCursor(Cursor.HAND); } }); byNode.setOnMouseExited(mouseEvent -> { if (!mouseEvent.isPrimaryButtonDown()) { byNode.setCursor(Cursor.DEFAULT); } }); }