Copied remaining files into appropriate package. These need to be refactored and put into the shared package.
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.chart.LineChart;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import seng302.Mock.StreamedRace;
|
||||
import seng302.VisualiserInput;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 15/03/2017.
|
||||
*/
|
||||
public class RaceController extends Controller {
|
||||
private ResizableRaceCanvas raceMap;
|
||||
private ResizableRaceMap raceBoundaries;
|
||||
|
||||
private RaceClock raceClock;
|
||||
private Sparkline sparkline;
|
||||
|
||||
private int legNum;
|
||||
|
||||
@FXML GridPane canvasBase;
|
||||
@FXML Pane arrow;
|
||||
@FXML SplitPane race;
|
||||
@FXML StackPane arrowPane;
|
||||
@FXML Label timer;
|
||||
@FXML Label FPS;
|
||||
@FXML Label timeZone;
|
||||
@FXML CheckBox showFPS;
|
||||
@FXML TableView<Boat> boatInfoTable;
|
||||
@FXML TableColumn<Boat, String> boatPlacingColumn;
|
||||
@FXML TableColumn<Boat, String> boatTeamColumn;
|
||||
@FXML TableColumn<Boat, String> boatMarkColumn;
|
||||
@FXML TableColumn<Boat, String> boatSpeedColumn;
|
||||
@FXML LineChart<Number, Number> sparklineChart;
|
||||
@FXML AnchorPane annotationPane;
|
||||
|
||||
/**
|
||||
* Updates the ResizableRaceCanvas (raceMap) with most recent data
|
||||
*
|
||||
* @param boats boats that are to be displayed in the race
|
||||
* @param boatMarkers Markers for boats
|
||||
* @see ResizableRaceCanvas
|
||||
*/
|
||||
public void updateMap(ObservableList<Boat> boats, ObservableList<Marker> boatMarkers) {
|
||||
raceMap.setBoats(boats);
|
||||
raceMap.setBoatMarkers(boatMarkers);
|
||||
raceMap.update();
|
||||
raceBoundaries.draw();
|
||||
//stop if the visualiser is no longer running
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
|
||||
*
|
||||
* @param race Race to listen to.
|
||||
*/
|
||||
public void setInfoTable(StreamedRace race) {
|
||||
boatInfoTable.setItems(race.getStartingBoats());
|
||||
boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp());
|
||||
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
||||
boatPlacingColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
//listener for fps
|
||||
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (showFPS.isSelected()) {
|
||||
FPS.setVisible(true);
|
||||
} else {
|
||||
FPS.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and sets initial display for Sparkline for race positions.
|
||||
* @param boats boats to display on the sparkline
|
||||
*/
|
||||
public void createSparkLine(ObservableList<Boat> boats){
|
||||
sparkline = new Sparkline(boats, legNum, sparklineChart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the sparkline to display current boat positions.
|
||||
* @param boatsInRace used for current boat positions.
|
||||
*/
|
||||
public void updateSparkline(ObservableList<Boat> boatsInRace){
|
||||
sparkline.updateSparkline(boatsInRace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes and runs the race, based on the user's chosen scale factor
|
||||
* Currently uses an example racecourse
|
||||
*
|
||||
* @param visualiserInput input from network
|
||||
* @param raceClock The RaceClock to use for the race's countdown/elapsed duration + timezone.
|
||||
*/
|
||||
public void startRace(VisualiserInput visualiserInput, RaceClock raceClock) {
|
||||
|
||||
legNum = visualiserInput.getCourse().getLegs().size()-1;
|
||||
|
||||
makeArrow();
|
||||
|
||||
raceMap = new ResizableRaceCanvas(visualiserInput.getCourse());
|
||||
raceMap.setMouseTransparent(true);
|
||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||
raceMap.draw();
|
||||
raceMap.setVisible(true);
|
||||
raceMap.setArrow(arrow.getChildren().get(0));
|
||||
|
||||
canvasBase.getChildren().add(0, raceMap);
|
||||
|
||||
raceBoundaries = new ResizableRaceMap(visualiserInput.getCourse());
|
||||
raceBoundaries.setMouseTransparent(true);
|
||||
raceBoundaries.widthProperty().bind(canvasBase.widthProperty());
|
||||
raceBoundaries.heightProperty().bind(canvasBase.heightProperty());
|
||||
raceBoundaries.draw();
|
||||
raceBoundaries.setVisible(true);
|
||||
|
||||
canvasBase.getChildren().add(0, raceBoundaries);
|
||||
|
||||
race.setVisible(true);
|
||||
|
||||
timeZone.setText(raceClock.getTimeZone());
|
||||
|
||||
//RaceClock.duration isn't necessarily being changed in the javaFX thread, so we need to runlater the update.
|
||||
raceClock.durationProperty().addListener((observable, oldValue, newValue) -> {
|
||||
Platform.runLater(() -> {
|
||||
timer.setText(newValue);
|
||||
});
|
||||
});
|
||||
|
||||
this.raceClock = raceClock;
|
||||
raceMap.setRaceClock(raceClock);
|
||||
|
||||
StreamedRace newRace = new StreamedRace(visualiserInput, this);
|
||||
|
||||
initializeFPS();
|
||||
|
||||
// set up annotation displays
|
||||
new Annotations(annotationPane, raceMap);
|
||||
|
||||
new Thread((newRace)).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish Race View
|
||||
* @param boats boats there are in the race.
|
||||
*/
|
||||
public void finishRace(ObservableList<Boat> boats){
|
||||
race.setVisible(false);
|
||||
parent.enterFinish(boats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for the fps label
|
||||
*
|
||||
* @param fps fps that the label will be updated to
|
||||
*/
|
||||
public void setFrames(String fps) {
|
||||
FPS.setText((fps));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up FPS display at bottom of screen
|
||||
*/
|
||||
private void initializeFPS() {
|
||||
showFPS.setVisible(true);
|
||||
showFPS.selectedProperty().addListener((ov, old_val, new_val) -> {
|
||||
if (showFPS.isSelected()) {
|
||||
FPS.setVisible(true);
|
||||
} else {
|
||||
FPS.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void makeArrow() {
|
||||
arrowPane.getChildren().add(arrow);
|
||||
}
|
||||
|
||||
public RaceClock getRaceClock() {
|
||||
return raceClock;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user