Added keyboard handling to RaceController
- Capture each KeyEvent with EventFilter over SplitPane race container #story[1010]
This commit is contained in:
@@ -97,7 +97,6 @@ public class ConnectionController extends Controller {
|
|||||||
}catch(NumberFormatException e){
|
}catch(NumberFormatException e){
|
||||||
System.err.println("Port number entered is not a number");
|
System.err.println("Port number entered is not a number");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import javafx.animation.AnimationTimer;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.chart.LineChart;
|
import javafx.scene.chart.LineChart;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
@@ -16,8 +19,11 @@ import javafx.util.Callback;
|
|||||||
import network.Messages.Enums.RaceStatusEnum;
|
import network.Messages.Enums.RaceStatusEnum;
|
||||||
import shared.model.Leg;
|
import shared.model.Leg;
|
||||||
import visualiser.app.VisualiserInput;
|
import visualiser.app.VisualiserInput;
|
||||||
|
import visualiser.gameController.Keys.ControlKey;
|
||||||
|
import visualiser.gameController.Keys.KeyFactory;
|
||||||
import visualiser.model.*;
|
import visualiser.model.*;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -79,6 +85,14 @@ public class RaceController extends Controller {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
// Initialise keyboard handler
|
||||||
|
race.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
||||||
|
String codeString = event.getCode().toString();
|
||||||
|
ControlKey controlKey = KeyFactory.getKey(codeString);
|
||||||
|
if(controlKey != null) {
|
||||||
|
System.out.println(controlKey.toString() + " is Pressed.");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -278,8 +292,6 @@ public class RaceController extends Controller {
|
|||||||
|
|
||||||
//Add to scene.
|
//Add to scene.
|
||||||
canvasBase.getChildren().add(0, raceCanvas);
|
canvasBase.getChildren().add(0, raceCanvas);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -345,7 +357,6 @@ public class RaceController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timer which monitors the race.
|
* Timer which monitors the race.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user