Java Code Examples for javafx.scene.shape.Rectangle#setOnMouseDragged()
The following examples show how to use
javafx.scene.shape.Rectangle#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: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final ReadOnlyDoubleProperty widthProperty = region.prefWidthProperty(); final DoubleBinding halfWidthProperty = widthProperty.divide(2); final Rectangle resizeHandleN = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleN.xProperty().bind(xProperty.add(halfWidthProperty).subtract(handleRadius / 2)); resizeHandleN.yProperty().bind(yProperty.subtract(handleRadius / 2)); setUpDragging(resizeHandleN, mouseLocation, Cursor.N_RESIZE); resizeHandleN.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragNorth(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleN; }
Example 2
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final ReadOnlyDoubleProperty widthProperty = region.prefWidthProperty(); final Rectangle resizeHandleNE = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleNE.xProperty().bind(xProperty.add(widthProperty).subtract(handleRadius / 2)); resizeHandleNE.yProperty().bind(yProperty.subtract(handleRadius / 2)); setUpDragging(resizeHandleNE, mouseLocation, Cursor.NE_RESIZE); resizeHandleNE.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragNorth(event, mouseLocation, region, handleRadius); dragEast(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleNE; }
Example 3
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final ReadOnlyDoubleProperty widthProperty = region.prefWidthProperty(); final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty(); final DoubleBinding halfHeightProperty = heightProperty.divide(2); final Rectangle resizeHandleE = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleE.xProperty().bind(xProperty.add(widthProperty).subtract(handleRadius / 2)); resizeHandleE.yProperty().bind(yProperty.add(halfHeightProperty).subtract(handleRadius / 2)); setUpDragging(resizeHandleE, mouseLocation, Cursor.E_RESIZE); resizeHandleE.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragEast(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleE; }
Example 4
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final ReadOnlyDoubleProperty widthProperty = region.prefWidthProperty(); final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty(); final Rectangle resizeHandleSE = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleSE.xProperty().bind(xProperty.add(widthProperty).subtract(handleRadius / 2)); resizeHandleSE.yProperty().bind(yProperty.add(heightProperty).subtract(handleRadius / 2)); setUpDragging(resizeHandleSE, mouseLocation, Cursor.SE_RESIZE); resizeHandleSE.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragSouth(event, mouseLocation, region, handleRadius); dragEast(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleSE; }
Example 5
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final ReadOnlyDoubleProperty widthProperty = region.prefWidthProperty(); final DoubleBinding halfWidthProperty = widthProperty.divide(2); final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty(); final Rectangle resizeHandleS = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleS.xProperty().bind(xProperty.add(halfWidthProperty).subtract(handleRadius / 2)); resizeHandleS.yProperty().bind(yProperty.add(heightProperty).subtract(handleRadius / 2)); setUpDragging(resizeHandleS, mouseLocation, Cursor.S_RESIZE); resizeHandleS.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragSouth(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleS; }
Example 6
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty(); final Rectangle resizeHandleSW = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleSW.xProperty().bind(xProperty.subtract(handleRadius / 2)); resizeHandleSW.yProperty().bind(yProperty.add(heightProperty).subtract(handleRadius / 2)); setUpDragging(resizeHandleSW, mouseLocation, Cursor.SW_RESIZE); resizeHandleSW.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragSouth(event, mouseLocation, region, handleRadius); dragWest(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleSW; }
Example 7
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final ReadOnlyDoubleProperty heightProperty = region.prefHeightProperty(); final DoubleBinding halfHeightProperty = heightProperty.divide(2); final Rectangle resizeHandleW = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleW.xProperty().bind(xProperty.subtract(handleRadius / 2)); resizeHandleW.yProperty().bind(yProperty.add(halfHeightProperty).subtract(handleRadius / 2)); setUpDragging(resizeHandleW, mouseLocation, Cursor.W_RESIZE); resizeHandleW.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragWest(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleW; }
Example 8
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final Rectangle resizeHandleNW = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleNW.xProperty().bind(xProperty.subtract(handleRadius / 2)); resizeHandleNW.yProperty().bind(yProperty.subtract(handleRadius / 2)); setUpDragging(resizeHandleNW, mouseLocation, Cursor.NW_RESIZE); resizeHandleNW.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragNorth(event, mouseLocation, region, handleRadius); dragWest(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleNW; }
Example 9
Source File: SeaBattle.java From games_oop_javafx with Apache License 2.0 | 6 votes |
private void buildShip(Group board, int desk, int startX, int startY) { Rectangle rect = new Rectangle(); rect.setX(startX); rect.setY(startY); rect.setHeight(25); rect.setWidth(desk * 25); rect.setFill(Color.BLACK); rect.setOnMouseDragged( event -> { rect.setX(event.getX()); rect.setY(event.getY()); } ); rect.setOnMouseReleased( event -> { rect.setX((((int) event.getX() / 25) * 25)); rect.setY(((int) event.getY() / 25) * 25); } ); rect.setOnMouseClicked( event -> { if (event.getButton() != MouseButton.PRIMARY) { Rectangle momento = new Rectangle(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); rect.setWidth(momento.getHeight()); rect.setHeight(momento.getWidth()); } } ); board.getChildren().add(rect); }
Example 10
Source File: SliderGlitchDemo.java From phoebus with Eclipse Public License 1.0 | 6 votes |
private Rectangle createRect(double y) { Rectangle rect = new Rectangle(10, y, startWidth, startHeight); rect.setOnMousePressed((event)-> { startDragX = event.getX(); startDragY = event.getY(); startWidth = rect.getWidth(); startHeight = rect.getHeight(); }); rect.setOnMouseDragged((event)-> { double deltaX = event.getX() - startDragX; double deltaY = event.getY() - startDragY; rect.setWidth(Math.max(startWidth+deltaX, 1)); rect.setHeight(Math.max(startHeight+deltaY, 1)); }); return rect; }
Example 11
Source File: OverviewPanel.java From constellation with Apache License 2.0 | 5 votes |
/** * Helper method that creates and styles a POV object. * * The POV object is a styled rectangle that is used to indicate the * currently observed time range (aka time extent) on the timeline. It can * also be used to quickly interact with the time extent. * * @return A formatted POV object. */ private Rectangle createPOV() { final Rectangle rect = new Rectangle(135, 25, 60, 1); // Bind the height of the POV to the Height of the histogram: rect.yProperty().bind(histogram.heightProperty()); rect.heightProperty().bind(innerPane.prefHeightProperty()); rect.setManaged(true); // Style the rectangle: rect.setStroke(Color.DODGERBLUE); rect.setStrokeWidth(2d); final LinearGradient gradient = new LinearGradient(0.0, 0.0, 0.0, 0.5, true, CycleMethod.NO_CYCLE, new Stop[]{ new Stop(0, Color.LIGHTBLUE.darker()), new Stop(1, Color.TRANSPARENT) }); rect.setFill(gradient); rect.setSmooth(true); // Round the edges of the rectangle: rect.setArcWidth(5.0); rect.setArcHeight(5.0); // Set the POV mouse event handlers: final POVMouseEventHandler handler = new POVMouseEventHandler(rect); rect.setOnMouseMoved(handler); rect.setOnMousePressed(handler); rect.setOnMouseDragged(handler); rect.setOnMouseReleased(handler); // Make the POV object the top-most object on this panel: rect.toFront(); return rect; }
Example 12
Source File: Puzzle.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private Rectangle buildFigure(int x, int y, int size, String image) { Rectangle rect = new Rectangle(); rect.setX(x); rect.setY(y); rect.setHeight(size); rect.setWidth(size); Image img = new Image(this.getClass().getClassLoader().getResource(image).toString()); rect.setFill(new ImagePattern(img)); final Rectangle momento = new Rectangle(x, y); rect.setOnDragDetected( event -> { momento.setX(event.getX()); momento.setY(event.getY()); } ); rect.setOnMouseDragged( event -> { rect.setX(event.getX() - size / 2); rect.setY(event.getY() - size / 2); } ); rect.setOnMouseReleased( event -> { if (logic.move(this.extract(momento.getX(), momento.getY()), this.extract(event.getX(), event.getY()))) { rect.setX(((int) event.getX() / 40) * 40 + 5); rect.setY(((int) event.getY() / 40) * 40 + 5); checkWinner(); } else { rect.setX(((int) momento.getX() / 40) * 40 + 5); rect.setY(((int) momento.getY() / 40) * 40 + 5); } } ); return rect; }
Example 13
Source File: Chess.java From games_oop_javafx with Apache License 2.0 | 5 votes |
private Rectangle buildFigure(int x, int y, int size, String image) { Rectangle rect = new Rectangle(); rect.setX(x); rect.setY(y); rect.setHeight(size); rect.setWidth(size); Image img = new Image(this.getClass().getClassLoader().getResource(image).toString()); rect.setFill(new ImagePattern(img)); final Rectangle momento = new Rectangle(x, y); rect.setOnDragDetected( event -> { momento.setX(event.getX()); momento.setY(event.getY()); } ); rect.setOnMouseDragged( event -> { rect.setX(event.getX() - size / 2); rect.setY(event.getY() - size / 2); } ); rect.setOnMouseReleased( event -> { try { logic.move( this.findBy(momento.getX(), momento.getY()), this.findBy(event.getX(), event.getY())); rect.setX(((int) event.getX() / 40) * 40 + 5); rect.setY(((int) event.getY() / 40) * 40 + 5); } catch (Exception e) { Alert info = new Alert(Alert.AlertType.ERROR); info.setContentText(e.getClass().getName() + " " + e.getMessage()); info.show(); rect.setX(((int) momento.getX() / 40) * 40 + 5); rect.setY(((int) momento.getY() / 40) * 40 + 5); } } ); return rect; }