From 3326da4f5d71a796c94d6aabaced9dcdde294da7 Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Thu, 20 Apr 2017 15:09:55 +1200 Subject: [PATCH] Started removing fx component from mock module. - Stuck on animation timer not running #story[778] --- mock/src/main/java/seng302/App.java | 88 +--- .../java/seng302/Controllers/Controller.java | 33 -- .../seng302/Controllers/MainController.java | 42 -- .../seng302/Controllers/RaceController.java | 227 ---------- .../seng302/Controllers/StartController.java | 159 ------- .../main/java/seng302/GraphCoordinate.java | 40 -- .../main/java/seng302/Model/BoatInRace.java | 1 - .../seng302/Model/ConstantVelocityRace.java | 18 +- mock/src/main/java/seng302/Model/Race.java | 105 ++--- .../seng302/Model/ResizableRaceCanvas.java | 410 ------------------ mock/src/main/java/seng302/RaceMap.java | 69 --- mock/src/main/resources/scenes/main.fxml | 16 - mock/src/main/resources/scenes/race.fxml | 85 ---- mock/src/main/resources/scenes/start.fxml | 58 --- 14 files changed, 55 insertions(+), 1296 deletions(-) delete mode 100644 mock/src/main/java/seng302/Controllers/Controller.java delete mode 100644 mock/src/main/java/seng302/Controllers/MainController.java delete mode 100644 mock/src/main/java/seng302/Controllers/RaceController.java delete mode 100644 mock/src/main/java/seng302/Controllers/StartController.java delete mode 100644 mock/src/main/java/seng302/GraphCoordinate.java delete mode 100644 mock/src/main/java/seng302/Model/ResizableRaceCanvas.java delete mode 100644 mock/src/main/java/seng302/RaceMap.java delete mode 100644 mock/src/main/resources/scenes/main.fxml delete mode 100644 mock/src/main/resources/scenes/race.fxml delete mode 100644 mock/src/main/resources/scenes/start.fxml diff --git a/mock/src/main/java/seng302/App.java b/mock/src/main/java/seng302/App.java index cf9d3ed2..ab4b29c1 100644 --- a/mock/src/main/java/seng302/App.java +++ b/mock/src/main/java/seng302/App.java @@ -1,16 +1,14 @@ package seng302; -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.layout.BorderPane; -import javafx.stage.Stage; -public class App extends Application { - Stage primaryStage; - BorderPane mainContainer; - Scene mainScene; +import org.xml.sax.SAXException; +import seng302.Model.ConstantVelocityRace; +import seng302.Model.Race; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; + +public class App{ /** * Entry point for running the programme @@ -18,65 +16,19 @@ public class App extends Application { * @param args for starting the programme */ public static void main(String[] args) { - launch(args); - } + try { + RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml"); + ConstantVelocityRace newRace = new ConstantVelocityRace(raceData, 15); + System.out.println(newRace.getStartingBoats()); + new Thread((newRace)).start(); + } catch (IOException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } - public void start(Stage stage) throws Exception { - FXMLLoader loader = new FXMLLoader(getClass().getResource("/scenes/main.fxml")); - Parent root = loader.load(); - Scene scene = new Scene(root, 1200, 800); - stage.setScene(scene); - stage.show(); } -// /** -// * Loads and sets up the GUI elements -// * -// * @param primaryStage Base for all scenes -// * @throws Exception Error in initialising programme -// */ -// @Override -// public void start(Stage primaryStage) throws Exception { -// this.primaryStage = primaryStage; -// primaryStage.minHeightProperty().setValue(600); -// primaryStage.minWidthProperty().setValue(780); -// //load the first container -// try { -// FXMLLoader loader = new FXMLLoader(); -// InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/main.fxml"); -// mainContainer = (BorderPane) loader.load(in); -// mainScene = new Scene(mainContainer, 1200, 800); -// primaryStage.setScene(mainScene); -// primaryStage.sizeToScene(); -// MainController mainController = (MainController) loader.getController(); -// mainController.setParent(this); -// in.close(); -// //add the center -// loadPane("race.fxml"); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// primaryStage.show(); -// } -// -// /** -// * Loads panes for use in the GUI -// * -// * @param fxmlName name of resource fxml file -// * @throws Exception critical error in loading file -// */ -// public void loadPane(String fxmlName) throws Exception { -// FXMLLoader loader = new FXMLLoader(); -// InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/" + fxmlName); -// Parent page; -// try { -// page = (Parent) loader.load(in); -// } finally { -// in.close(); -// } -// mainContainer.getChildren().remove(mainContainer.getCenter()); -// mainContainer.setCenter(page); -// Controller controller = (Controller) loader.getController(); -// controller.setParent(this); -// } } diff --git a/mock/src/main/java/seng302/Controllers/Controller.java b/mock/src/main/java/seng302/Controllers/Controller.java deleted file mode 100644 index c5d160e7..00000000 --- a/mock/src/main/java/seng302/Controllers/Controller.java +++ /dev/null @@ -1,33 +0,0 @@ -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); -} diff --git a/mock/src/main/java/seng302/Controllers/MainController.java b/mock/src/main/java/seng302/Controllers/MainController.java deleted file mode 100644 index 796c47b4..00000000 --- a/mock/src/main/java/seng302/Controllers/MainController.java +++ /dev/null @@ -1,42 +0,0 @@ -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); - } -} diff --git a/mock/src/main/java/seng302/Controllers/RaceController.java b/mock/src/main/java/seng302/Controllers/RaceController.java deleted file mode 100644 index 6d4bdf8e..00000000 --- a/mock/src/main/java/seng302/Controllers/RaceController.java +++ /dev/null @@ -1,227 +0,0 @@ -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 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 boatInfoTable; - @FXML - TableColumn boatPlacingColumn; - @FXML - TableColumn boatTeamColumn; - @FXML - TableColumn boatMarkColumn; - @FXML - TableColumn 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 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(); - } - }); - } -} \ No newline at end of file diff --git a/mock/src/main/java/seng302/Controllers/StartController.java b/mock/src/main/java/seng302/Controllers/StartController.java deleted file mode 100644 index f62fb6ea..00000000 --- a/mock/src/main/java/seng302/Controllers/StartController.java +++ /dev/null @@ -1,159 +0,0 @@ -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 boatNameTable; - @FXML private TableColumn boatNameColumn; - @FXML private TableColumn 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 boats = raceData.getBoats(); - ObservableList 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(); - } - -} diff --git a/mock/src/main/java/seng302/GraphCoordinate.java b/mock/src/main/java/seng302/GraphCoordinate.java deleted file mode 100644 index 050931c2..00000000 --- a/mock/src/main/java/seng302/GraphCoordinate.java +++ /dev/null @@ -1,40 +0,0 @@ -package seng302; - -/** - * Graph Coordinate that is to be displayed on the Canvas - * Created by cbt24 on 15/03/17. - */ -public class GraphCoordinate { - private int x; - private int y; - - /** - * Constructor method. - * - * @param x X coordinate. - * @param y Y coordinate. - */ - public GraphCoordinate(int x, int y) { - this.x = x; - this.y = y; - } - - /** - * Returns the X coordinate. - * - * @return x axis Coordinate. - */ - public int getX() { - return x; - } - - /** - * Returns the Y coordinate. - * - * @return y axis Coordinate. - */ - public int getY() { - return y; - } - -} diff --git a/mock/src/main/java/seng302/Model/BoatInRace.java b/mock/src/main/java/seng302/Model/BoatInRace.java index 520e7b06..644cba4f 100644 --- a/mock/src/main/java/seng302/Model/BoatInRace.java +++ b/mock/src/main/java/seng302/Model/BoatInRace.java @@ -182,7 +182,6 @@ public class BoatInRace extends Boat { * Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas. * * @param colour Colour that the boat is to be set to. - * @see ResizableRaceCanvas */ public void setColour(Color colour) { this.colour = colour; diff --git a/mock/src/main/java/seng302/Model/ConstantVelocityRace.java b/mock/src/main/java/seng302/Model/ConstantVelocityRace.java index 84fdab19..b9ed2ba6 100644 --- a/mock/src/main/java/seng302/Model/ConstantVelocityRace.java +++ b/mock/src/main/java/seng302/Model/ConstantVelocityRace.java @@ -2,7 +2,6 @@ package seng302.Model; import org.geotools.referencing.GeodeticCalculator; import seng302.Constants; -import seng302.Controllers.RaceController; import seng302.GPSCoordinate; import seng302.RaceDataSource; @@ -15,7 +14,6 @@ import java.util.Random; /** * Created by cbt24 on 6/03/17. * - * @deprecated */ public class ConstantVelocityRace extends Race { @@ -26,11 +24,10 @@ public class ConstantVelocityRace extends Race { * * @param startingBoats in race * @param legs in race - * @param controller for graphics * @param scaleFactor of timer */ - public ConstantVelocityRace(List startingBoats, List legs, RaceController controller, int scaleFactor) { - super(startingBoats, legs, controller, scaleFactor); + public ConstantVelocityRace(List startingBoats, List legs, int scaleFactor) { + super(startingBoats, legs, scaleFactor); } /** @@ -38,23 +35,20 @@ public class ConstantVelocityRace extends Race { * * @param startingBoats in race * @param legs in race - * @param controller for graphics * @param scaleFactor of timer * - * @deprecated Please use {@link #ConstantVelocityRace(List, List, RaceController, int) } for future tests. */ - public ConstantVelocityRace(BoatInRace[] startingBoats, List legs, RaceController controller, int scaleFactor) { - super(Arrays.asList(startingBoats), legs, controller, scaleFactor); + public ConstantVelocityRace(BoatInRace[] startingBoats, List legs, int scaleFactor) { + super(Arrays.asList(startingBoats), legs, scaleFactor); } /** * Initialiser for constant velocity race with standard data source * @param raceData for race - * @param controller for graphics * @param scaleFactor of timer */ - public ConstantVelocityRace(RaceDataSource raceData, RaceController controller, int scaleFactor) { - super(raceData, controller, scaleFactor); + public ConstantVelocityRace(RaceDataSource raceData, int scaleFactor) { + super(raceData, scaleFactor); } public void initialiseBoats() { diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index bfc1d518..5b7c8bab 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -1,20 +1,18 @@ package seng302.Model; +import com.sun.org.apache.xpath.internal.SourceTree; import javafx.animation.AnimationTimer; -import javafx.application.Platform; + import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import org.geotools.referencing.GeodeticCalculator; -import seng302.Controllers.RaceController; -import seng302.GPSCoordinate; + import seng302.RaceDataSource; -import java.awt.geom.Point2D; -import java.util.ArrayList; + import java.util.Arrays; import java.util.List; -import java.util.Random; + /** * Parent class for races @@ -24,7 +22,6 @@ public abstract class Race implements Runnable { //protected BoatInRace[] startingBoats; protected ObservableList startingBoats; protected List legs; - protected RaceController controller; protected int boatsFinished = 0; protected long totalTimeElapsed; private int lastFPS = 20; @@ -32,34 +29,31 @@ public abstract class Race implements Runnable { protected int scaleFactor; protected int PRERACE_TIME = 120000; //time in milliseconds to pause during pre-race - private boolean timerEnabled = true; //boolean to determine if timer is ran /** * Initailiser for Race * * @param boats Takes in an array of boats that are participating in the race. * @param legs Number of marks in order that the boats pass in order to complete the race. - * @param controller race controller * @param scaleFactor for race */ - public Race(List boats, List legs, RaceController controller, int scaleFactor) { + public Race(List boats, List legs, int scaleFactor) { this.startingBoats = FXCollections.observableArrayList(boats); this.legs = legs; this.legs.add(new Leg("Finish", this.legs.size())); - this.controller = controller; this.scaleFactor = scaleFactor; if (startingBoats != null && startingBoats.size() > 0) { initialiseBoats(); } } - public Race(BoatInRace[] startingBoats, List legs, RaceController controller, int scaleFactor) { - this(Arrays.asList(startingBoats), legs, controller, scaleFactor); + public Race(BoatInRace[] startingBoats, List legs, int scaleFactor) { + this(Arrays.asList(startingBoats), legs, scaleFactor); } - public Race(RaceDataSource raceData, RaceController controller, int scaleFactor) { - this(raceData.getBoats(), raceData.getLegs(), controller, scaleFactor); + public Race(RaceDataSource raceData, int scaleFactor) { + this(raceData.getBoats(), raceData.getLegs(), scaleFactor); } public abstract void initialiseBoats(); @@ -91,24 +85,16 @@ public abstract class Race implements Runnable { * Runnable for the thread. */ public void run() { - setControllerListeners(); initialiseBoats(); - if (timerEnabled) countdownTimer(); - //simulateRace(); + System.out.println("Running race"); + simulateRace(); } - /** - * Disable the timer - */ - public void disableTimer() { - timerEnabled = false; - } - - /** * Countdown timer until race starts. Use PRERACE_TIME to set countdown duration. */ protected void countdownTimer() { + System.out.println("Running countdown timer"); new AnimationTimer() { long currentTime = System.currentTimeMillis(); long startTime = currentTime + (PRERACE_TIME/scaleFactor); @@ -120,24 +106,23 @@ public abstract class Race implements Runnable { @Override public void handle(long arg0) { - timeLeft = startTime - currentTime; - if (timeLeft <= 0 && controller != null) { - updateTime("Race is starting..."); - stop(); - simulateRace(); - } else { - currentTimeInSeconds = (timeLeft*scaleFactor) / 1000; - minutes = currentTimeInSeconds / 60; - remainingSeconds = currentTimeInSeconds % 60; - hours = minutes / 60; - minutes = minutes % 60; - if (controller != null) { - updateTime(String.format("Race clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds)); - } - } - currentTime = System.currentTimeMillis(); + System.out.println("Starting timer"); + timeLeft = startTime - currentTime; + System.out.println(timeLeft); + if (timeLeft <= 0) { + stop(); + simulateRace(); + } else { + currentTimeInSeconds = (timeLeft*scaleFactor) / 1000; + minutes = currentTimeInSeconds / 60; + remainingSeconds = currentTimeInSeconds % 60; + hours = minutes / 60; + minutes = minutes % 60; + } + currentTime = System.currentTimeMillis(); } }.start(); + System.out.println("Running countdown timer"); } /** @@ -159,28 +144,6 @@ public abstract class Race implements Runnable { return String.format("Race clock: %02d:%02d:%02d", hours, minutes, remainingSeconds); } - /** - * Updates the calculated time to the timer label - * - * @param time The calculated time from calcTimer() method - */ - protected void updateTime(String time) { - Platform.runLater(() -> { - controller.setTimer(time); - }); - } - - /** - * Update the calculated fps to the fps label - * - * @param fps The new calculated fps value - */ - private void updateFPS(int fps) { - Platform.runLater(() -> { - controller.setFrames("FPS: " + fps); - }); - } - /** * Starts the Race Simulation, playing the race start to finish with the timescale. * This prints the boats participating, the order that the events occur in time order, and the respective information of the events. @@ -201,6 +164,7 @@ public abstract class Race implements Runnable { @Override public void handle(long arg0) { + System.out.println(); if (boatsFinished < startingBoats.size()) { totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted; @@ -212,13 +176,9 @@ public abstract class Race implements Runnable { checkPosition(boat, totalTimeElapsed); } } - if (timerEnabled) - updateTime(calcTimer()); } - controller.updateMap(startingBoats); fps++; if ((System.currentTimeMillis() - timeCurrent) > 1000) { - updateFPS(fps); lastFPS = fps; fps = 0; timeCurrent = System.currentTimeMillis(); @@ -243,13 +203,6 @@ public abstract class Race implements Runnable { } } - /** - * Update call for the controller. - */ - protected void setControllerListeners() { - if (controller != null) controller.setInfoTable(this); - } - /** * Returns the boats that have started the race. * diff --git a/mock/src/main/java/seng302/Model/ResizableRaceCanvas.java b/mock/src/main/java/seng302/Model/ResizableRaceCanvas.java deleted file mode 100644 index da83b5f1..00000000 --- a/mock/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ /dev/null @@ -1,410 +0,0 @@ -package seng302.Model; - - -import javafx.scene.canvas.Canvas; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; -import javafx.scene.paint.Paint; -import javafx.scene.transform.Rotate; -import seng302.*; -import seng302.Controllers.RaceController; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * This creates a JavaFX Canvas that is fills it's parent. - * Cannot be downsized. - * Created by fwy13 on 17/03/17. - */ -public class ResizableRaceCanvas extends Canvas { - private GraphicsContext gc; - private RaceMap map; - private List boats; - private boolean raceAnno = true; - private boolean annoName = true; - private boolean annoAbbrev = true; - private boolean annoSpeed = true; - private boolean annoPath = true; - private ArrayList raceBoundaries; - double[] xpoints = {}, ypoints = {}; - - public ResizableRaceCanvas(RaceDataSource raceData) { - gc = this.getGraphicsContext2D(); - // Redraw canvas when size changes. - widthProperty().addListener(evt -> drawRaceMap()); - heightProperty().addListener(evt -> drawRaceMap()); - - double lat1 = raceData.getMapTopLeft().getLatitude(); - double long1 = raceData.getMapTopLeft().getLongitude(); - double lat2 = raceData.getMapBottomRight().getLatitude(); - double long2 = raceData.getMapBottomRight().getLongitude(); - setMap(new RaceMap(lat1, long1, lat2, long2, (int) getWidth(), (int) getHeight())); - } - - /** - * Sets the boats that are to be displayed in this race. - * - * @param boats in race - */ - public void setBoats(List boats) { - this.boats = boats; - } - - /** - * Sets the RaceMap that the RaceCanvas is to be displaying for. - * - * @param map race map - */ - public void setMap(RaceMap map) { - this.map = map; - } - - /** - * Displays the mark of a race as a circle. - * - * @param graphCoordinate Latitude and Logintude in GraphCoordinate that it is to be displayed as. - * @param paint Colour the mark is to be coloured. - * @see GraphCoordinate - * @see Color - * @see Paint - */ - public void displayMark(GraphCoordinate graphCoordinate, Paint paint) { - double d = 25; - gc.setFill(paint); - gc.fillOval(graphCoordinate.getX() - (d / 2), graphCoordinate.getY() - (d / 2), d, d); - } - - public void displayBoat(BoatInRace boat, double angle) { - GraphCoordinate pos = this.map.convertGPS(boat.getCurrentPosition()); - Paint paint = boat.getColour(); - - double[] x = {pos.getX() - 6, pos.getX(), pos.getX() + 6}; - double[] y = {pos.getY() + 12, pos.getY() - 12, pos.getY() + 12}; - gc.setFill(paint); - - gc.save(); - rotate(angle, pos.getX(), pos.getY()); - gc.fillPolygon(x, y, 3); - gc.restore(); - } - - /** - * Displays a line on the map with rectangles on the starting and ending point of the line. - * - * @param graphCoordinateA Starting Point of the line in GraphCoordinate. - * @param graphCoordinateB End Point of the line in GraphCoordinate. - * @param paint Colour the line is to coloured. - * @see GraphCoordinate - * @see Color - * @see Paint - */ - private void displayLine(GraphCoordinate graphCoordinateA, GraphCoordinate graphCoordinateB, Paint paint) { - gc.setStroke(paint); - gc.setFill(paint); - gc.fillOval(graphCoordinateA.getX() - 3, graphCoordinateA.getY() - 3, 6, 6); - gc.fillOval(graphCoordinateB.getX() - 3, graphCoordinateB.getY() - 3, 6, 6); - gc.strokeLine(graphCoordinateA.getX(), graphCoordinateA.getY(), graphCoordinateB.getX(), graphCoordinateB.getY()); - } - - /** - * Display a point on the Canvas - * - * @param graphCoordinate Coordinate that the point is to be displayed at. - * @param paint Colour that the boat is to be coloured. - * @see GraphCoordinate - * @see Paint - * @see Color - */ - private void displayPoint(GraphCoordinate graphCoordinate, Paint paint) { - gc.setFill(paint); - gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10); - } - - - /** - * Displays an arrow on the Canvas - * - * @param coordinate Coordinate that the arrow is to be displayed at. - * @param angle Angle that the arrow is to be facing in degrees 0 degrees = North (Up). - * @see GraphCoordinate - */ - private void displayArrow(GraphCoordinate coordinate, int angle) { - gc.save(); - rotate(angle, coordinate.getX(), coordinate.getY()); - gc.setFill(Color.BLACK); - gc.fillPolygon(new double[]{coordinate.getX() - 12, coordinate.getX() - 6, coordinate.getX(), coordinate.getX() - 4, coordinate.getX() - 4, coordinate.getX() - 8, coordinate.getX() - 8}, - new double[]{coordinate.getY() - 5, coordinate.getY() - 20, coordinate.getY() - 5, coordinate.getY() - 5, coordinate.getY() + 20, coordinate.getY() + 20, coordinate.getY() - 5}, - 7); - gc.restore(); - } - - /** - * Rotates things on the canvas Note: this must be called in between gc.save() and gc.restore() else they will rotate everything - * - * @param angle Bearing angle to rotate at in degrees - * @param px Pivot point x of rotation. - * @param py Pivot point y of rotation. - */ - private void rotate(double angle, double px, double py) { - Rotate r = new Rotate(angle, px, py); - gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy()); - } - - /** - * Display given name and speed of boat at a graph coordinate - * - * @param name name of the boat - * @param abbrev abbreviation of the boat name - * @param speed speed of the boat - * @param coordinate coordinate the text appears - */ - private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate) { - String text = ""; - //Check name toggle value - if (annoName){ - text += String.format("%s ", name); - } - //Check abbreviation toggle value - if (annoAbbrev){ - text += String.format("%s ", abbrev); - } - //Check speed toggle value - if (annoSpeed){ - text += String.format("%.2fkn", speed); - } - //String text = String.format("%s, %2$.2fkn", name, speed); - long xCoord = coordinate.getX() + 20; - long yCoord = coordinate.getY(); - if (xCoord + (text.length() * 7) >= getWidth()) { - xCoord -= text.length() * 7; - } - if (yCoord - (text.length() * 2) <= 0) { - yCoord += 30; - } - gc.fillText(text, xCoord, yCoord); - } - - /** - * Draws race map with up to date data. - */ - public void update() { - this.drawRaceMap(); - this.updateBoats(); - } - - /** - * Draw boundary of the race. - */ - public void drawBoundaries() { - if (this.raceBoundaries == null) { - return; - } - gc.setFill(Color.AQUA); - setRaceBoundCoordinates(); - gc.fillPolygon(xpoints, ypoints, xpoints.length); - } - - /** - * Draws the Race Map - */ - public void drawRaceMap() { - - double width = getWidth(); - double height = getHeight(); - - gc.clearRect(0, 0, width, height); - - if (map == null) { - return;//TODO this should return a exception in the future - } - this.map.setHeight((int) height); - this.map.setWidth((int) width); - - //finish line - gc.setLineWidth(2); - drawBoundaries(); - GraphCoordinate finishLineCoord1 = this.map.convertGPS(Constants.finishLineMarker1); - GraphCoordinate finishLineCoord2 = this.map.convertGPS(Constants.finishLineMarker2); - displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED); - //marks - GraphCoordinate markCoord = this.map.convertGPS(Constants.mark1); - GraphCoordinate windwardGate1 = this.map.convertGPS(Constants.windwardGate1); - GraphCoordinate windwardGate2 = this.map.convertGPS(Constants.windwardGate2); - GraphCoordinate leewardGate1 = this.map.convertGPS(Constants.leewardGate1); - GraphCoordinate leewardGate2 = this.map.convertGPS(Constants.leewardGate2); - displayMark(markCoord, Color.GOLD); - displayLine(windwardGate1, windwardGate2, Color.DARKCYAN); - displayLine(leewardGate1, leewardGate2, Color.DARKVIOLET); - //start line - GraphCoordinate startline1 = this.map.convertGPS(Constants.startLineMarker1); - GraphCoordinate startline2 = this.map.convertGPS(Constants.startLineMarker2); - - displayLine(startline1, startline2, Color.GREEN); - - updateBoats(); - - //display wind direction arrow - specify origin point and angle - angle now set to random angle - displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150); - } - - /** - * Draws a boat at a certain GPSCoordinate - * - * @param colour Colour to colour boat. - * @param gpsCoordinates GPScoordinate that the boat is to be drawn at. - * @see GPSCoordinate - * @see Color - */ - public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) { - GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates); - displayPoint(graphCoordinate, colour); - } - - /** - * Toggle the raceAnno value - */ - public void toggleAnnotations() { - if (raceAnno) { - raceAnno = false; - } else { - raceAnno = true; - } - } - - /** - * Toggle name display in annotation - */ - public void toggleAnnoName() { - if (annoName) { - annoName = false; - } else { - annoName = true; - } - } - - public void toggleBoatPath() { - if (annoPath) { - annoPath = false; - } else { - annoPath = true; - } - } - - /** - * Toggle abbreviation display in annotation - */ - public void toggleAnnoAbbrev() { - if (annoAbbrev) { - annoAbbrev = false; - } else { - annoAbbrev = true; - } - } - - /** - * Toggle speed display in annotation - */ - public void toggleAnnoSpeed() { - if (annoSpeed) { - annoSpeed = false; - } else { - annoSpeed = true; - } - } - - /** - * Draws boats while race in progress, when leg heading is set. - */ - public void updateBoats() { - if (boats != null) { - for (BoatInRace boat : boats) { - boolean finished = boat.getCurrentLeg().getName().equals("Finish") || boat.getCurrentLeg().getName().equals("DNF"); - boolean isStart = boat.isStarted(); - if (!finished && isStart) { - displayBoat(boat, boat.getHeading()); - GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition()); - GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake()); - displayLine(wakeFrom, wakeTo, boat.getColour()); - } else if (!isStart) { - displayBoat(boat, boat.getHeading()); - } else { - displayBoat(boat, 0); - } - - if (raceAnno) - displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); - - if(boat.isTrackVisible()) drawTrack(boat); - } - } - } - - /** - * Draws all track points for a given boat. Colour is set by boat, opacity by track point. - * @param boat whose track is displayed - * @see seng302.Model.TrackPoint - */ - private void drawTrack(BoatInRace boat) { - if (annoPath && raceAnno) { - for (TrackPoint point : boat.getTrack()) { - GraphCoordinate scaledCoordinate = this.map.convertGPS(point.getCoordinate()); - Color boatColour = boat.getColour(); - gc.setFill(new Color(boatColour.getRed(), boatColour.getGreen(), boatColour.getBlue(), point.getAlpha())); - gc.fillOval(scaledCoordinate.getX(), scaledCoordinate.getY(), 5, 5); - } - } - } - - public void setRaceBoundaries(List boundaries) { - this.raceBoundaries = new ArrayList<>(); - for (GPSCoordinate bound : boundaries) { - raceBoundaries.add(bound); - } - setRaceBoundCoordinates(); - } - - public void setRaceBoundCoordinates() { - xpoints = new double[this.raceBoundaries.size()]; - ypoints = new double[this.raceBoundaries.size()]; - for (int i = 0; i < raceBoundaries.size(); i++) { - GraphCoordinate coord = map.convertGPS(raceBoundaries.get(i)); - xpoints[i] = coord.getX(); - ypoints[i] = coord.getY(); - } - } - - /** - * Set the Canvas to resizable. - * - * @return That the Canvas is resizable. - */ - @Override - public boolean isResizable() { - return true; - } - - /** - * Returns the preferred width of the Canvas - * - * @param width of canvas - * @return Returns the width of the Canvas - */ - @Override - public double prefWidth(double width) { - return getWidth(); - } - - /** - * Returns the preferred height of the Canvas - * - * @param height of canvas - * @return Returns the height of the Canvas - */ - @Override - public double prefHeight(double height) { - return getHeight(); - } - -} diff --git a/mock/src/main/java/seng302/RaceMap.java b/mock/src/main/java/seng302/RaceMap.java deleted file mode 100644 index 0ccf9a6d..00000000 --- a/mock/src/main/java/seng302/RaceMap.java +++ /dev/null @@ -1,69 +0,0 @@ -package seng302; - -/** - * Created by cbt24 on 15/03/17. - */ -public class RaceMap { - private double x1, x2, y1, y2; - private int width, height; - - /** - * Constructor Method. - * - * @param x1 Longitude of the top left point. - * @param y1 Latitude of the top left point. - * @param x2 Longitude of the top right point. - * @param y2 Latitude of the top right point. - * @param width width that the Canvas the race is to be drawn on is. - * @param height height that the Canvas the race is to be drawn on is. - */ - public RaceMap(double y1, double x1, double y2, double x2, int height, int width) { - this.x1 = x1; - this.x2 = x2; - this.y1 = y1; - this.y2 = y2; - this.width = width; - this.height = height; - } - - /** - * Converts GPS coordinates to coordinates for container - * - * @param lat GPS latitude - * @param lon GPS longitude - * @return GraphCoordinate (pair of doubles) - * @see GraphCoordinate - */ - public GraphCoordinate convertGPS(double lat, double lon) { - int difference = Math.abs(width - height); - int size = width; - if (width > height) { - size = height; - return new GraphCoordinate((int) ((size * (lon - x1) / (x2 - x1)) + difference / 2), (int) (size - (size * (lat - y1) / (y2 - y1)))); - } else { - return new GraphCoordinate((int) (size * (lon - x1) / (x2 - x1)), (int) ((size - (size * (lat - y1) / (y2 - y1))) + difference / 2)); - } - - //return new GraphCoordinate((int) (width * (lon - x1) / (x2 - x1)), (int) (height - (height * (lat - y1) / (y2 - y1)))); - } - - /** - * Converts the GPS Coordinate to GraphCoordinates - * - * @param coordinate GPSCoordinate representation of Latitude and Longitude. - * @return GraphCoordinate that the GPS is coordinates are to be displayed on the map. - * @see GraphCoordinate - * @see GPSCoordinate - */ - public GraphCoordinate convertGPS(GPSCoordinate coordinate) { - return convertGPS(coordinate.getLatitude(), coordinate.getLongitude()); - } - - public void setWidth(int width) { - this.width = width; - } - - public void setHeight(int height) { - this.height = height; - } -} diff --git a/mock/src/main/resources/scenes/main.fxml b/mock/src/main/resources/scenes/main.fxml deleted file mode 100644 index d94c8b59..00000000 --- a/mock/src/main/resources/scenes/main.fxml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mock/src/main/resources/scenes/race.fxml b/mock/src/main/resources/scenes/race.fxml deleted file mode 100644 index 56aed929..00000000 --- a/mock/src/main/resources/scenes/race.fxml +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -