Java Code Examples for javafx.scene.Scene#setOnMousePressed()
The following examples show how to use
javafx.scene.Scene#setOnMousePressed() .
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: JavaFX3D.java From JavaFX-Tutorial-Codes with Apache License 2.0 | 6 votes |
private void initMouseControl(SmartGroup group, Scene scene) { Rotate xRotate; Rotate yRotate; group.getTransforms().addAll( xRotate = new Rotate(0, Rotate.X_AXIS), yRotate = new Rotate(0, Rotate.Y_AXIS) ); xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); scene.setOnMousePressed(event -> { anchorX = event.getSceneX(); anchorY = event.getSceneY(); anchorAngleX = angleX.get(); anchorAngleY = angleY.get(); }); scene.setOnMouseDragged(event -> { angleX.set(anchorAngleX - (anchorY - event.getSceneY())); angleY.set(anchorAngleY + anchorX - event.getSceneX()); }); }
Example 2
Source File: MainNarjillosApplication.java From narjillos with MIT License | 6 votes |
private void registerMouseDragHandlers(final Scene scene) { final double[] mouseX = new double[] { 0 }; final double[] mouseY = new double[] { 0 }; scene.setOnMousePressed(event -> { mouseX[0] = event.getX(); mouseY[0] = event.getY(); }); scene.setOnMouseDragged(event -> { getTracker().stopTracking(); double translateX = event.getX() - mouseX[0]; double translateY = event.getY() - mouseY[0]; getViewport().translateBy(Vector.cartesian(-translateX, -translateY)); mouseX[0] = event.getX(); mouseY[0] = event.getY(); }); }
Example 3
Source File: HistogramTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); histogram = new Histogram(1000, 1, true); sceneRoot.getChildren().addAll(histogram); int size = 30; float[][] arrayY = new float[2 * size][2 * size]; for (int i = -size; i < size; i++) { for (int j = -size; j < size; j++) { //Transcedental Gradient double xterm = (Math.cos(Math.PI * i / size) * Math.cos(Math.PI * i / size)); double yterm = (Math.cos(Math.PI * j / size) * Math.cos(Math.PI * j / size)); arrayY[i + size][j + size] = (float) (10 * ((xterm + yterm) * (xterm + yterm))); } } histogram.setHeightData(arrayY, 1, 4, Color.SKYBLUE, false, true); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if (event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if (keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if (keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if (keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if (keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); histogram.getTransforms().addAll(xRotate, yRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if (event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if (event.isMiddleButtonDown()) { angleZ.set(fixedZAngle - (scenez - event.getSceneY())); } else { angleX.set(fixedXAngle - (scenex - event.getSceneY())); } angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz HistogramTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example 4
Source File: ScatterPlotTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); scatterPlot = new ScatterPlot(1000, 1, true); sceneRoot.getChildren().addAll(scatterPlot); ArrayList<Double> dataX = new ArrayList<>(); ArrayList<Double> dataY = new ArrayList<>(); ArrayList<Double> dataZ = new ArrayList<>(); for(int i=-250;i<250;i++) { dataX.add(new Double(i)); dataY.add(new Double(Math.sin(i)*50)+i); dataZ.add(new Double(Math.cos(i)*50)+i); } scatterPlot.setXYZData(dataX, dataY, dataZ); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); scatterPlot.getTransforms().addAll(xRotate, yRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz ScatterPlotTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example 5
Source File: PolyLine3DTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); ArrayList<Point3D> points = new ArrayList<>(); for(int i=-250;i<250;i++) { points.add(new Point3D( (float) i, (float) Math.sin(i)*50+i, (float) Math.cos(i)*50+i)); } polyLine3D = new PolyLine3D(points,3,Color.STEELBLUE); sceneRoot.getChildren().addAll(polyLine3D); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); polyLine3D.getTransforms().addAll(xRotate, yRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz ScatterPlotTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example 6
Source File: SurfacePlotTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); int size = 10; float [][] arrayY = new float[2*size][2*size]; //The Sombrero for(int i=-size;i<size;i++) { for(int j=-size;j<size;j++) { double R = Math.sqrt((i * i) + (j * j)) + 0.00000000000000001; arrayY[i+size][j+size] = ((float) -(Math.sin(R)/R)) * 100; } } surfacePlot = new SurfacePlot(arrayY, 10, Color.AQUA, false, false); sceneRoot.getChildren().addAll(surfacePlot); PointLight light = new PointLight(Color.WHITE); sceneRoot.getChildren().add(light); light.setTranslateZ(sceneWidth / 2); light.setTranslateY(-sceneHeight + 10); PointLight light2 = new PointLight(Color.WHITE); sceneRoot.getChildren().add(light2); light2.setTranslateZ(-sceneWidth + 10); light2.setTranslateY(-sceneHeight + 10); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); surfacePlot.getTransforms().addAll(xRotate, yRotate, zRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz SurfacePlotTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example 7
Source File: ScatterPlotMeshTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); scatterPlotMesh = new ScatterPlotMesh(1000, 1, true); sceneRoot.getChildren().addAll(scatterPlotMesh); ArrayList<Double> dataX = new ArrayList<>(); ArrayList<Double> dataY = new ArrayList<>(); ArrayList<Double> dataZ = new ArrayList<>(); for(int i=-250;i<250;i++) { dataX.add(new Double(i)); dataY.add(new Double(Math.sin(i)*50)+i); dataZ.add(new Double(Math.cos(i)*50)+i); } scatterPlotMesh.setXYZData(dataX, dataY, dataZ); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); scatterPlotMesh.getTransforms().addAll(xRotate, yRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz ScatterPlotTest"); primaryStage.setScene(scene); primaryStage.show(); }
Example 8
Source File: ScatterPlotColorTest.java From FXyzLib with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage primaryStage) throws Exception { Group sceneRoot = new Group(); Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED); scene.setFill(Color.BLACK); camera = new PerspectiveCamera(true); camera.setNearClip(0.1); camera.setFarClip(10000.0); camera.setTranslateZ(-1000); scene.setCamera(camera); scatterPlot = new ScatterPlot(1000, 1, true); sceneRoot.getChildren().addAll(scatterPlot); List<Double> dataX = new ArrayList<>(); List<Double> dataY = new ArrayList<>(); List<Double> dataZ = new ArrayList<>(); List<Color> colors = new ArrayList<>(); int k = 0; for(int i=-250;i<250;i++) { dataX.add(new Double(i)); dataY.add(Math.sin(i)*50+i); dataZ.add(Math.cos(i)*50+i); colors.add(new Color(Math.abs(i) / 250D, Math.abs(dataY.get(k)) / 300D, Math.abs(dataZ.get(k) / 300D), 0.25)); k++; } scatterPlot.setXYZData(dataX, dataY, dataZ, colors); scene.setOnKeyPressed(event -> { double change = 10.0; //Add shift modifier to simulate "Running Speed" if(event.isShiftDown()) { change = 50.0; } //What key did the user press? KeyCode keycode = event.getCode(); //Step 2c: Add Zoom controls if(keycode == KeyCode.W) { camera.setTranslateZ(camera.getTranslateZ() + change); } if(keycode == KeyCode.S) { camera.setTranslateZ(camera.getTranslateZ() - change); } //Step 2d: Add Strafe controls if(keycode == KeyCode.A) { camera.setTranslateX(camera.getTranslateX() - change); } if(keycode == KeyCode.D) { camera.setTranslateX(camera.getTranslateX() + change); } }); //Add a Mouse Handler for Rotations Rotate xRotate = new Rotate(0, Rotate.X_AXIS); Rotate yRotate = new Rotate(0, Rotate.Y_AXIS); Rotate zRotate = new Rotate(0, Rotate.Z_AXIS); scatterPlot.getTransforms().addAll(xRotate, yRotate); //Use Binding so your rotation doesn't have to be recreated xRotate.angleProperty().bind(angleX); yRotate.angleProperty().bind(angleY); zRotate.angleProperty().bind(angleZ); //Start Tracking mouse movements only when a button is pressed scene.setOnMousePressed(event -> { scenex = event.getSceneX(); sceney = event.getSceneY(); fixedXAngle = angleX.get(); fixedYAngle = angleY.get(); if(event.isMiddleButtonDown()) { scenez = event.getSceneX(); fixedZAngle = angleZ.get(); } }); //Angle calculation will only change when the button has been pressed scene.setOnMouseDragged(event -> { if(event.isMiddleButtonDown()) angleZ.set(fixedZAngle - (scenez - event.getSceneY())); else angleX.set(fixedXAngle - (scenex - event.getSceneY())); angleY.set(fixedYAngle + sceney - event.getSceneX()); }); primaryStage.setTitle("F(X)yz ScatterPlotColorTest"); primaryStage.setScene(scene); primaryStage.show(); }