Java Code Examples for javafx.scene.Scene#setOnKeyPressed()

The following examples show how to use javafx.scene.Scene#setOnKeyPressed() . 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: EventHandler.java    From Aidos with GNU General Public License v3.0 8 votes vote down vote up
public static void attachEventHandlers(Scene s){
    keyReleaseHanlder krh = new keyReleaseHanlder();
    keyPressedHandler kph = new keyPressedHandler();
    s.setOnKeyReleased(krh);
    s.setOnKeyPressed(kph);
}
 
Example 2
Source File: Window.java    From mcaselector with MIT License 7 votes vote down vote up
@Override
public void start(Stage primaryStage) {
	try {
		primaryStage.setTitle("MCA Selector " + FileHelper.getManifestAttributes().getValue("Application-Version"));
	} catch (IOException ex) {
		primaryStage.setTitle("MCA Selector - dev");
	}
	primaryStage.getIcons().add(FileHelper.getIconFromResources("img/icon"));

	TileMap tileMap = new TileMap(this, width, height);

	BorderPane pane = new BorderPane();

	//menu bar
	OptionBar optionBar = new OptionBar(tileMap, primaryStage);
	pane.setTop(optionBar);

	//tilemap
	TileMapBox tileMapBox = new TileMapBox(tileMap, primaryStage);
	pane.setCenter(tileMapBox);

	//status bar
	pane.setBottom(new StatusBar(tileMap));

	Scene scene = new Scene(pane, width, height);

	URL cssRes = Window.class.getClassLoader().getResource("style.css");
	if (cssRes != null) {
		String styleSheet = cssRes.toExternalForm();
		scene.getStylesheets().add(styleSheet);
	}

	scene.setOnKeyPressed(e -> pressedKeys.add(e.getCode()));
	scene.setOnKeyReleased(e -> pressedKeys.remove(e.getCode()));

	primaryStage.setOnCloseRequest(e -> System.exit(0));
	primaryStage.setScene(scene);
	primaryStage.show();
}
 
Example 3
Source File: Game2048.java    From util4j with Apache License 2.0 7 votes vote down vote up
private void addKeyHandler(Scene scene) {
    scene.setOnKeyPressed(ke -> {
        KeyCode keyCode = ke.getCode();
        if (keyCode.equals(KeyCode.S)) {
            gameManager.saveSession();
            return;
        }
        if (keyCode.equals(KeyCode.R)) {
            gameManager.restoreSession();
            return;
        }
        if (keyCode.equals(KeyCode.P)) {
            gameManager.pauseGame();
            return;
        }
        if (keyCode.equals(KeyCode.Q) || keyCode.equals(KeyCode.ESCAPE)) {
            gameManager.quitGame();
            return;
        }
        if (keyCode.isArrowKey()) {
            Direction direction = Direction.valueFor(keyCode);
            gameManager.move(direction);
        }
    });
}
 
Example 4
Source File: Main.java    From FXTutorials with MIT License 7 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Scene scene = new Scene(createContent());
    scene.setOnKeyPressed(event -> {
        switch (event.getCode()) {
            case A:
                action = UserAction.LEFT;
                break;
            case D:
                action = UserAction.RIGHT;
                break;
        }
    });

    scene.setOnKeyReleased(event -> {
        switch (event.getCode()) {
            case A:
                action = UserAction.NONE;
                break;
            case D:
                action = UserAction.NONE;
                break;
        }
    });

    primaryStage.setTitle("Tutorial");
    primaryStage.setScene(scene);
    primaryStage.show();
    startGame();
}
 
Example 5
Source File: DisputeSummaryWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void setupKeyHandler(Scene scene) {
    if (!hideCloseButton) {
        scene.setOnKeyPressed(e -> {
            if (e.getCode() == KeyCode.ESCAPE) {
                e.consume();
                doClose();
            }
        });
    }
}
 
Example 6
Source File: ZoneOverlay_Stage.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
public void bindKeyEvent(Scene scene){
    scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent event) {
            if (Preferences_Controller.zones_hotkey_show_hide_key.match(event)) { 
                if(isVisible){
                    hidePanel();
                }else{
                    showPanel();
                }
            }
            
        }
    });
}
 
Example 7
Source File: Tutorial.java    From FXTutorials with MIT License 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Scene scene = new Scene(createContent());

    placeCube(new Point3D(10, 0, 0));
    placeCube(new Point3D(-10, 0, 0));
    placeCube(new Point3D(0, 0, -20));

    scene.setOnKeyPressed(event -> {
        if (event.getCode() == KeyCode.W) {
            translate.setZ(translate.getZ() + 1);
        } else if (event.getCode() == KeyCode.S) {
            translate.setZ(translate.getZ() - 1);
        } else if (event.getCode() == KeyCode.A) {
            //rotate.setAngle(rotate.getAngle() - 5);
            translate.setX(translate.getX() - 1);
        } else if (event.getCode() == KeyCode.D) {
            //rotate.setAngle(rotate.getAngle() + 5);
            translate.setX(translate.getX() + 1);
        }

        if (event.getCode() == KeyCode.UP) {

        } else if (event.getCode() == KeyCode.DOWN) {

        } else if (event.getCode() == KeyCode.LEFT) {
            rotate.setAngle(rotate.getAngle() - 5);
        } else if (event.getCode() == KeyCode.RIGHT) {
            rotate.setAngle(rotate.getAngle() + 5);
        }
    });

    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 8
Source File: MainNarjillosApplication.java    From narjillos with MIT License 5 votes vote down vote up
private void registerKeyboardHandlers(final Scene scene) {
	scene.setOnKeyPressed(new EventHandler<KeyEvent>() {

		public void handle(final KeyEvent keyEvent) {
			if (keyEvent.getCode() == KeyCode.RIGHT)
				panViewport(PAN_SPEED, 0, keyEvent);
			else if (keyEvent.getCode() == KeyCode.LEFT)
				panViewport(-PAN_SPEED, 0, keyEvent);
			else if (keyEvent.getCode() == KeyCode.UP)
				panViewport(0, -PAN_SPEED, keyEvent);
			else if (keyEvent.getCode() == KeyCode.DOWN)
				panViewport(0, PAN_SPEED, keyEvent);
			else if (keyEvent.getCode() == KeyCode.P)
				state.speedUp();
			else if (keyEvent.getCode() == KeyCode.O)
				state.speedDown();
			else if (keyEvent.getCode() == KeyCode.L)
				state.toggleLight();
			else if (keyEvent.getCode() == KeyCode.I)
				state.toggleInfrared();
			else if (keyEvent.getCode() == KeyCode.E && keyEvent.isControlDown())
				state.toggleEffects();
			else if (keyEvent.getCode() == KeyCode.D && keyEvent.isControlDown())
				getTracker().toggleDemoMode();
		}

		private void panViewport(long velocityX, long velocityY, KeyEvent event) {
			getTracker().stopTracking();
			getViewport().moveBy(Vector.cartesian(velocityX, velocityY));
			event.consume();
		}
	});
}
 
Example 9
Source File: DisplayUpdateDownloadWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void setupKeyHandler(Scene scene) {
    if (!hideCloseButton) {
        scene.setOnKeyPressed(e -> {
            if (e.getCode() == KeyCode.ESCAPE || e.getCode() == KeyCode.ENTER) {
                e.consume();
                cleanup();
                hide();
                actionHandlerOptional.ifPresent(Runnable::run);
            }
        });
    }
}
 
Example 10
Source File: FeeOptionWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void setupKeyHandler(Scene scene) {
    if (!hideCloseButton) {
        scene.setOnKeyPressed(e -> {
            if (e.getCode() == KeyCode.ESCAPE) {
                e.consume();
                doClose();
            }
        });
    }
}
 
Example 11
Source File: TorNetworkSettingsWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void setupKeyHandler(Scene scene) {
    if (!hideCloseButton) {
        scene.setOnKeyPressed(e -> {
            if (e.getCode() == KeyCode.ESCAPE) {
                e.consume();
                doClose();
            } else if (e.getCode() == KeyCode.ENTER) {
                e.consume();
                saveAndShutDown();
            }
        });
    }
}
 
Example 12
Source File: OldScoresApplication2.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

    if( logger.isDebugEnabled() ) {
        logger.debug("[START]");
    }

    Injector injector = Guice.createInjector(new OldScoresModule());

    FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml2/MainView.fxml"),
                                       null,
                                       injector.getInstance(BuilderFactory.class),
                                       injector.getInstance(GuiceControllerFactory.class));

    Parent p = loader.load();
    MainViewController mv = loader.getController();

    Scene scene = new Scene( p );

    scene.setOnKeyPressed(evt -> {

        if( evt.getCode().equals(KeyCode.F1) ) {
            try {
                if( logger.isDebugEnabled() ) {
                    logger.debug("[OPEN HELP]");
                }
                mv.openHelpDialog();
            } catch (IOException exc) {
                String msg = "error showing help dialog";
                logger.error(msg);
                Alert alert = new Alert(Alert.AlertType.ERROR, msg);
                alert.showAndWait();
            }
        }
    });

    primaryStage.setTitle("Old Scores");
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 13
Source File: ProposalResultsWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setupCloseKeyHandler(Scene scene) {
    scene.setOnKeyPressed(e -> {
        if (e.getCode() == KeyCode.ESCAPE || e.getCode() == KeyCode.ENTER) {
            e.consume();
            doClose();
        }
    });
}
 
Example 14
Source File: ManualPayoutTxWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void setupKeyHandler(Scene scene) {
    if (!hideCloseButton) {
        scene.setOnKeyPressed(e -> {
            if (e.getCode() == KeyCode.ESCAPE) {
                e.consume();
                doClose();
            }
        });
    }
}
 
Example 15
Source File: BsqEmptyWalletWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void setupKeyHandler(Scene scene) {
    if (!hideCloseButton) {
        scene.setOnKeyPressed(e -> {
            if (e.getCode() == KeyCode.ESCAPE) {
                e.consume();
                doClose();
            }
        });
    }
}
 
Example 16
Source File: BtcEmptyWalletWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void setupKeyHandler(Scene scene) {
    if (!hideCloseButton) {
        scene.setOnKeyPressed(e -> {
            if (e.getCode() == KeyCode.ESCAPE) {
                e.consume();
                doClose();
            }
        });
    }
}
 
Example 17
Source File: SurfacePlotTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@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 18
Source File: HistogramTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@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 19
Source File: ScatterPlotTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@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 20
Source File: ScatterPlotMeshTest.java    From FXyzLib with GNU General Public License v3.0 4 votes vote down vote up
@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();        
}