Actually added sub modules this time

#story[778]
This commit is contained in:
Erika Savell
2017-04-20 11:16:19 +12:00
parent 669718d406
commit a584400e24
80 changed files with 9020 additions and 0 deletions
@@ -0,0 +1,33 @@
package seng302.Controllers;
import javafx.fxml.Initializable;
import seng302.App;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller parent for app controllers.
* Created by fwy13 on 15/03/2017.
*/
public abstract class Controller implements Initializable {
protected MainController parent;
/**
* Sets the parent of the application
*
* @param parent controller
*/
public void setParent(MainController parent) {
this.parent = parent;
}
/**
* Initialisation class that is run on start up.
*
* @param location resources location
* @param resources resources bundle
*/
@Override
public abstract void initialize(URL location, ResourceBundle resources);
}
@@ -0,0 +1,42 @@
package seng302.Controllers;
import javafx.fxml.FXML;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import seng302.RaceDataSource;
import seng302.RaceXMLReader;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by fwy13 on 15/03/2017.
*/
public class MainController extends Controller {
@FXML StartController startController;
@FXML RaceController raceController;
public void beginRace(int scaleFactor, RaceDataSource raceData) {
raceController.startRace(scaleFactor, raceData);
}
/**
* Main Controller for the applications will house the menu and the displayed pane.
*
* @param location of resources
* @param resources bundle
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
startController.setParent(this);
raceController.setParent(this);
AnchorPane.setTopAnchor(startController.startWrapper(), 0.0);
AnchorPane.setBottomAnchor(startController.startWrapper(), 0.0);
AnchorPane.setLeftAnchor(startController.startWrapper(), 0.0);
AnchorPane.setRightAnchor(startController.startWrapper(), 0.0);
}
}
@@ -0,0 +1,227 @@
package seng302.Controllers;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import org.xml.sax.SAXException;
import seng302.Model.*;
import seng302.RaceDataSource;
import seng302.RaceXMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;
/**
* Created by fwy13 on 15/03/2017.
*/
public class RaceController extends Controller {
@FXML
GridPane canvasBase;
//user saved data for annotation display
private ArrayList<Boolean> presetAnno;
ResizableRaceCanvas raceMap;
@FXML
SplitPane race;
@FXML
CheckBox showFPS;
@FXML
CheckBox showBoatPath;
@FXML
CheckBox showAnnotations;
@FXML
Label timer;
@FXML
Label FPS;
@FXML
Label timeZone;
@FXML
CheckBox showName;
@FXML
CheckBox showAbbrev;
@FXML
CheckBox showSpeed;
@FXML
Button saveAnno;
@FXML
Button showSetAnno;
@FXML
TableView<BoatInRace> boatInfoTable;
@FXML
TableColumn<BoatInRace, String> boatPlacingColumn;
@FXML
TableColumn<BoatInRace, String> boatTeamColumn;
@FXML
TableColumn<BoatInRace, String> boatMarkColumn;
@FXML
TableColumn<BoatInRace, String> boatSpeedColumn;
/**
* Updates the ResizableRaceCanvas (raceMap) with most recent data
*
* @param boats boats that are to be displayed in the race
* @see ResizableRaceCanvas
*/
public void updateMap(ObservableList<BoatInRace> boats) {
raceMap.setBoats(boats);
raceMap.update();
}
/**
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
*
* @param race Race to listen to.
*/
public void setInfoTable(Race race) {
//boatInfoTable.getItems().clear();
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);
}
});
}
/**
* Initializes and runs the race, based on the user's chosen scale factor
* Currently uses an example racecourse
*
* @param scaleFactor scale value of race
*/
public void startRace(int scaleFactor, RaceDataSource raceData) {
ConstantVelocityRace newRace = new ConstantVelocityRace(raceData, this, scaleFactor);
newRace.initialiseBoats();
raceMap = new ResizableRaceCanvas(raceData);
raceMap.setMouseTransparent(true);
raceMap.widthProperty().bind(canvasBase.widthProperty());
raceMap.heightProperty().bind(canvasBase.heightProperty());
raceMap.setBoats(newRace.getStartingBoats());
raceMap.setRaceBoundaries(raceData.getBoundary());
raceMap.drawRaceMap();
raceMap.setVisible(true);
canvasBase.getChildren().add(raceMap);
race.setVisible(true);
//Initialize save annotation array, fps listener, and annotation listeners
//timezone
RaceClock raceClock = new RaceClock(raceData.getMark());
timeZone.setText(raceClock.getTimeZone());
initializeFPS();
initializeAnnotations();
new Thread((newRace)).start();
}
/**
* Set the value for the race clock label
*
* @param time time that the label will be updated to
*/
public void setTimer(String time) {
timer.setText(time);
}
/**
* 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);
}
});
}
/**
* Set up boat annotations
*/
private void initializeAnnotations() {
presetAnno = new ArrayList<>();
//listener for annotation
showAnnotations.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleAnnotations();
raceMap.update();
});
//listener for show name in annotation
showName.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleAnnoName();
raceMap.update();
});
//listener for show abbreviation for annotation
showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleAnnoAbbrev();
raceMap.update();
});
//listener for show boat path for annotation
showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleBoatPath();
raceMap.update();
});
//listener to show speed for annotation
showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleAnnoSpeed();
raceMap.update();
});
//listener to save currently selected annotation
saveAnno.setOnAction(event -> {
presetAnno.clear();
presetAnno.add(showName.isSelected());
presetAnno.add(showAbbrev.isSelected());
presetAnno.add(showSpeed.isSelected());
presetAnno.add(showBoatPath.isSelected());
});
//listener to show saved annotation
showSetAnno.setOnAction(event -> {
if (presetAnno.size() > 0) {
showName.setSelected(presetAnno.get(0));
showAbbrev.setSelected(presetAnno.get(1));
showSpeed.setSelected(presetAnno.get(2));
showBoatPath.setSelected(presetAnno.get(3));
raceMap.update();
}
});
}
}
@@ -0,0 +1,159 @@
package seng302.Controllers;
import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import org.xml.sax.SAXException;
import seng302.Model.BoatInRace;
import seng302.Model.RaceClock;
import seng302.RaceDataSource;
import seng302.RaceXMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
/**
* Created by esa46 on 6/04/17.
*/
public class StartController extends Controller {
@FXML private GridPane start;
@FXML private AnchorPane startWrapper;
@FXML private TableView<BoatInRace> boatNameTable;
@FXML private TableColumn<BoatInRace, String> boatNameColumn;
@FXML private TableColumn<BoatInRace, String> boatCodeColumn;
@FXML private Label timeZoneTime;
@FXML private Label timer;
@FXML private int PRERACE_TIME = 15000;
@FXML Button oneMinButton;
@FXML Button fiveMinButton;
@FXML Button fifteenMinButton;
private RaceClock raceClock;
private RaceDataSource raceData;
/**
* Begins the race with a scale factor of 15
*/
public void startRace1Min() {
startRace(15);
}
/**
* Begins the race with a scale factor of 3
*/
public void startRace5Min() {
startRace(3);
}
/**
* Begins the race with a scale factor of 1
*/
public void startRaceNoScaling() {
startRace(1);
}
private void startRace(int raceScale){
oneMinButton.setDisable(true);
fiveMinButton.setDisable(true);
fifteenMinButton.setDisable(true);
countdownTimer(raceScale);
}
@Override
public void initialize(URL location, ResourceBundle resources){
raceData = null;
try {
raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
initialiseTables();
}
public AnchorPane startWrapper(){
return startWrapper;
}
private void initialiseTables() {
List<BoatInRace> boats = raceData.getBoats();
ObservableList<BoatInRace> observableBoats = FXCollections.observableArrayList(boats);
boatNameTable.setItems(observableBoats);
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
boatCodeColumn.setCellValueFactory(new PropertyValueFactory<>("abbrev"));
//timezone
raceClock = new RaceClock(raceData.getMark());
timeZoneTime.textProperty().bind(raceClock.timeProperty());
}
/**
* Updates the calculated time to the timer label
*
* @param time The calculated time from calcTimer() method
*/
protected void updateTime(String time) {
Platform.runLater(() -> {
timer.setText(time);
});
}
/**
* Countdown timer until race starts. Use PRERACE_TIME to set countdown duration.
*/
protected void countdownTimer(int scaleFactor) {
new AnimationTimer() {
long currentTime = System.currentTimeMillis();
long startTime = currentTime + (PRERACE_TIME/scaleFactor);
long minutes;
long currentTimeInSeconds;
long remainingSeconds;
long hours;
long timeLeft;
@Override
public void handle(long arg0) {
timeLeft = startTime - currentTime;
if (timeLeft <= 0) {
updateTime("Race is starting...");
stop();
parent.beginRace(scaleFactor, raceData);
startWrapper.setVisible(false);
} else {
currentTimeInSeconds = (timeLeft*scaleFactor) / 1000;
minutes = currentTimeInSeconds / 60;
remainingSeconds = currentTimeInSeconds % 60;
hours = minutes / 60;
minutes = minutes % 60;
updateTime(String.format("Race Clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
raceClock.updateTime();
}
currentTime = System.currentTimeMillis();
}
}.start();
}
}