Refactoring
#story[24]
This commit is contained in:
@@ -18,6 +18,7 @@ public class App extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point for running the programme
|
* Entry point for running the programme
|
||||||
|
*
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -26,6 +27,7 @@ public class App extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and sets up the GUI elements
|
* Loads and sets up the GUI elements
|
||||||
|
*
|
||||||
* @param primaryStage
|
* @param primaryStage
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@@ -55,6 +57,7 @@ public class App extends Application {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads panes for use in the GUI
|
* Loads panes for use in the GUI
|
||||||
|
*
|
||||||
* @param fxmlName
|
* @param fxmlName
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,27 +5,16 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
|
|||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.EventHandler;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
|
||||||
import javafx.scene.input.MouseEvent;
|
|
||||||
import javafx.scene.layout.AnchorPane;
|
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import javafx.scene.layout.StackPane;
|
|
||||||
import javafx.scene.paint.Color;
|
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
|
||||||
import seng302.Constants;
|
|
||||||
import seng302.GPSCoordinate;
|
|
||||||
import seng302.Model.*;
|
import seng302.Model.*;
|
||||||
import seng302.RaceXMLReader;
|
import seng302.RaceXMLReader;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -33,7 +22,7 @@ import java.util.ResourceBundle;
|
|||||||
/**
|
/**
|
||||||
* Created by fwy13 on 15/03/2017.
|
* Created by fwy13 on 15/03/2017.
|
||||||
*/
|
*/
|
||||||
public class RaceController extends Controller{
|
public class RaceController extends Controller {
|
||||||
@FXML
|
@FXML
|
||||||
GridPane canvasBase;
|
GridPane canvasBase;
|
||||||
|
|
||||||
@@ -43,16 +32,12 @@ public class RaceController extends Controller{
|
|||||||
GridPane startScreen;
|
GridPane startScreen;
|
||||||
@FXML
|
@FXML
|
||||||
SplitPane ongoingRacePane;
|
SplitPane ongoingRacePane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
CheckBox showFPS;
|
CheckBox showFPS;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
CheckBox showAnno;
|
CheckBox showAnnotations;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
Label timer;
|
Label timer;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
Label FPS;
|
Label FPS;
|
||||||
|
|
||||||
@@ -123,12 +108,10 @@ public class RaceController extends Controller{
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
//listener for fps
|
//listener for fps
|
||||||
/*Tooltip tp = new Tooltip("");
|
|
||||||
tp.install(timer, tp);*/
|
|
||||||
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
public void changed(ObservableValue<? extends Boolean> ov,
|
public void changed(ObservableValue<? extends Boolean> ov,
|
||||||
Boolean old_val, Boolean new_val) {
|
Boolean old_val, Boolean new_val) {
|
||||||
if (showFPS.isSelected()){
|
if (showFPS.isSelected()) {
|
||||||
FPS.setVisible(true);
|
FPS.setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
FPS.setVisible(false);
|
FPS.setVisible(false);
|
||||||
@@ -154,9 +137,9 @@ public class RaceController extends Controller{
|
|||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()];
|
BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()];
|
||||||
boats = raceXMLReader.getBoats().toArray(boats);
|
boats = raceXMLReader.getBoats().toArray(boats);
|
||||||
//BoatInRace[] boats = generateAC35Competitors();
|
|
||||||
double lat1 = raceXMLReader.getMapTopLeft().getLatitude();
|
double lat1 = raceXMLReader.getMapTopLeft().getLatitude();
|
||||||
double long1 = raceXMLReader.getMapTopLeft().getLongitude();
|
double long1 = raceXMLReader.getMapTopLeft().getLongitude();
|
||||||
double lat2 = raceXMLReader.getMapBottomRight().getLatitude();
|
double lat2 = raceXMLReader.getMapBottomRight().getLatitude();
|
||||||
@@ -174,14 +157,12 @@ public class RaceController extends Controller{
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
raceMap = new ResizableRaceCanvas(lat1, long1, lat2, long2);
|
raceMap = new ResizableRaceCanvas(lat1, long1, lat2, long2);
|
||||||
raceMap.setMouseTransparent(true);
|
raceMap.setMouseTransparent(true);
|
||||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||||
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
||||||
raceMap.setBoats(startingBoats);
|
raceMap.setBoats(startingBoats);
|
||||||
raceMap.setRaceBoundaries(raceXMLReader.getBoundary());
|
raceMap.setRaceBoundaries(raceXMLReader.getBoundary());
|
||||||
//raceMap.drawBoats();
|
|
||||||
raceMap.drawRaceMap();
|
raceMap.drawRaceMap();
|
||||||
raceMap.setVisible(true);
|
raceMap.setVisible(true);
|
||||||
|
|
||||||
@@ -190,27 +171,8 @@ public class RaceController extends Controller{
|
|||||||
ongoingRacePane.setVisible(true);
|
ongoingRacePane.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
|
initializeFPS();
|
||||||
showFPS.setVisible(true);
|
initializeAnnotations();
|
||||||
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
|
||||||
public void changed(ObservableValue<? extends Boolean> ov,
|
|
||||||
Boolean old_val, Boolean new_val) {
|
|
||||||
if (showFPS.isSelected()){
|
|
||||||
FPS.setVisible(true);
|
|
||||||
} else {
|
|
||||||
FPS.setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//listener for annotation
|
|
||||||
showAnno.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
|
||||||
public void changed(ObservableValue<? extends Boolean> ov,
|
|
||||||
Boolean old_val, Boolean new_val) {
|
|
||||||
raceMap.toggleAnno();
|
|
||||||
raceMap.update();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
new Thread((race)).start();
|
new Thread((race)).start();
|
||||||
}
|
}
|
||||||
@@ -218,6 +180,7 @@ public class RaceController extends Controller{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value for the race clock label
|
* Set the value for the race clock label
|
||||||
|
*
|
||||||
* @param time time that the label will be updated to
|
* @param time time that the label will be updated to
|
||||||
*/
|
*/
|
||||||
public void setTimer(String time) {
|
public void setTimer(String time) {
|
||||||
@@ -226,8 +189,42 @@ public class RaceController extends Controller{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value for the fps label
|
* Set the value for the fps label
|
||||||
|
*
|
||||||
* @param fps fps that the label will be updated to
|
* @param fps fps that the label will be updated to
|
||||||
*/
|
*/
|
||||||
public void setFrames(String fps) { FPS.setText((fps)); }
|
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(new ChangeListener<Boolean>() {
|
||||||
|
public void changed(ObservableValue<? extends Boolean> ov,
|
||||||
|
Boolean old_val, Boolean new_val) {
|
||||||
|
if (showFPS.isSelected()) {
|
||||||
|
FPS.setVisible(true);
|
||||||
|
} else {
|
||||||
|
FPS.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up boat annotations
|
||||||
|
*/
|
||||||
|
private void initializeAnnotations() {
|
||||||
|
//listener for annotation
|
||||||
|
showAnnotations.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
|
public void changed(ObservableValue<? extends Boolean> ov,
|
||||||
|
Boolean old_val, Boolean new_val) {
|
||||||
|
raceMap.toggleAnnotations();
|
||||||
|
raceMap.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class Boat {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the boat name
|
* Sets the boat name
|
||||||
|
*
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
@@ -50,6 +51,7 @@ public class Boat {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the speed of the boat in knots.
|
* Sets the speed of the boat in knots.
|
||||||
|
*
|
||||||
* @param velocity speed in knots
|
* @param velocity speed in knots
|
||||||
*/
|
*/
|
||||||
public void setVelocity(double velocity) {
|
public void setVelocity(double velocity) {
|
||||||
@@ -59,6 +61,7 @@ public class Boat {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Print method prints the name of the boat
|
* Print method prints the name of the boat
|
||||||
|
*
|
||||||
* @return Name of the boat.
|
* @return Name of the boat.
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ public class BoatInRace extends Boat {
|
|||||||
* Returns the position of the end of the boat's wake, which is 180 degrees
|
* Returns the position of the end of the boat's wake, which is 180 degrees
|
||||||
* from the boat's heading, and whose length is proportional to the boat's
|
* from the boat's heading, and whose length is proportional to the boat's
|
||||||
* speed.
|
* speed.
|
||||||
|
*
|
||||||
* @return GPSCoordinate of wake endpoint.
|
* @return GPSCoordinate of wake endpoint.
|
||||||
*/
|
*/
|
||||||
public GPSCoordinate getWake() {
|
public GPSCoordinate getWake() {
|
||||||
@@ -107,6 +108,7 @@ public class BoatInRace extends Boat {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the boat's scaled velocity
|
* Sets the boat's scaled velocity
|
||||||
|
*
|
||||||
* @param velocity
|
* @param velocity
|
||||||
*/
|
*/
|
||||||
public void setScaledVelocity(double velocity) {
|
public void setScaledVelocity(double velocity) {
|
||||||
@@ -219,6 +221,7 @@ public class BoatInRace extends Boat {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether boat is finished or not
|
* Sets whether boat is finished or not
|
||||||
|
*
|
||||||
* @param bool
|
* @param bool
|
||||||
*/
|
*/
|
||||||
public void setFinished(boolean bool) {
|
public void setFinished(boolean bool) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class ConstantVelocityRace extends Race {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the distance a boat has travelled and updates its current position according to this value.
|
* Calculates the distance a boat has travelled and updates its current position according to this value.
|
||||||
|
*
|
||||||
* @param boat
|
* @param boat
|
||||||
* @param millisecondsElapsed
|
* @param millisecondsElapsed
|
||||||
*/
|
*/
|
||||||
@@ -44,12 +45,13 @@ public class ConstantVelocityRace extends Race {
|
|||||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||||
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
||||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
||||||
totalDistanceTravelled, boat.calculateAzimuth()));
|
totalDistanceTravelled, boat.calculateAzimuth()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the boats next GPS position based on its distance travelled and heading
|
* Calculates the boats next GPS position based on its distance travelled and heading
|
||||||
|
*
|
||||||
* @param oldCoordinates GPS coordinates of the boat's starting position
|
* @param oldCoordinates GPS coordinates of the boat's starting position
|
||||||
* @param distanceTravelled distance in nautical miles
|
* @param distanceTravelled distance in nautical miles
|
||||||
* @param azimuth boat's current direction. Value between -180 and 180
|
* @param azimuth boat's current direction. Value between -180 and 180
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
import com.oracle.xmlns.internal.webservices.jaxws_databinding.SoapBindingUse;
|
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
import seng302.Constants;
|
import seng302.Constants;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
@@ -102,5 +101,4 @@ public class Leg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package seng302.Model;
|
|||||||
|
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import sun.java2d.loops.GeneralRenderer;
|
|
||||||
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ package seng302.Model;
|
|||||||
|
|
||||||
import javafx.animation.AnimationTimer;
|
import javafx.animation.AnimationTimer;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.StringProperty;
|
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableArray;
|
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
import seng302.Controllers.RaceController;
|
import seng302.Controllers.RaceController;
|
||||||
@@ -38,8 +36,9 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initailiser for Race
|
* Initailiser for Race
|
||||||
|
*
|
||||||
* @param boats Takes in an array of boats that are participating in the 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 legs Number of marks in order that the boats pass in order to complete the race.
|
||||||
*/
|
*/
|
||||||
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller, int scaleFactor) {
|
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller, int scaleFactor) {
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ public abstract class Race implements Runnable {
|
|||||||
this.legs.add(new Leg("Finish", this.legs.size()));
|
this.legs.add(new Leg("Finish", this.legs.size()));
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
this.scaleFactor = scaleFactor;
|
this.scaleFactor = scaleFactor;
|
||||||
if (startingBoats != null && startingBoats.size() > 0){
|
if (startingBoats != null && startingBoats.size() > 0) {
|
||||||
initialiseBoats();
|
initialiseBoats();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +82,7 @@ public abstract class Race implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
setControllerListeners();
|
setControllerListeners();
|
||||||
initialiseBoats();
|
initialiseBoats();
|
||||||
if(timerEnabled) countdownTimer();
|
if (timerEnabled) countdownTimer();
|
||||||
simulateRace();
|
simulateRace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +133,7 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes total time elapsed and format to hour:minute:second
|
* Takes total time elapsed and format to hour:minute:second
|
||||||
|
*
|
||||||
* @return Formatted time as string
|
* @return Formatted time as string
|
||||||
*/
|
*/
|
||||||
protected String calcTimer() {
|
protected String calcTimer() {
|
||||||
@@ -142,7 +142,7 @@ public abstract class Race implements Runnable {
|
|||||||
long remainingSeconds;
|
long remainingSeconds;
|
||||||
long hours;
|
long hours;
|
||||||
|
|
||||||
currentTimeInSeconds = (totalTimeElapsed * scaleFactor)/ 1000;
|
currentTimeInSeconds = (totalTimeElapsed * scaleFactor) / 1000;
|
||||||
minutes = currentTimeInSeconds / 60;
|
minutes = currentTimeInSeconds / 60;
|
||||||
remainingSeconds = currentTimeInSeconds % 60;
|
remainingSeconds = currentTimeInSeconds % 60;
|
||||||
hours = minutes / 60;
|
hours = minutes / 60;
|
||||||
@@ -152,18 +152,24 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the calculated time to the timer label
|
* Updates the calculated time to the timer label
|
||||||
|
*
|
||||||
* @param time The calculated time from calcTimer() method
|
* @param time The calculated time from calcTimer() method
|
||||||
*/
|
*/
|
||||||
protected void updateTime(String time){
|
protected void updateTime(String time) {
|
||||||
Platform.runLater(() -> {controller.setTimer(time);});
|
Platform.runLater(() -> {
|
||||||
|
controller.setTimer(time);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the calculated fps to the fps label
|
* Update the calculated fps to the fps label
|
||||||
|
*
|
||||||
* @param fps The new calculated fps value
|
* @param fps The new calculated fps value
|
||||||
*/
|
*/
|
||||||
private void updateFPS(int fps) {
|
private void updateFPS(int fps) {
|
||||||
Platform.runLater(() -> {controller.setFrames("FPS: " + fps);});
|
Platform.runLater(() -> {
|
||||||
|
controller.setFrames("FPS: " + fps);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doNotFinish() {
|
private boolean doNotFinish() {
|
||||||
@@ -179,7 +185,7 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
System.setProperty("javafx.animation.fullspeed", "true");
|
System.setProperty("javafx.animation.fullspeed", "true");
|
||||||
|
|
||||||
for (BoatInRace boat: startingBoats){
|
for (BoatInRace boat : startingBoats) {
|
||||||
boat.setStarted(true);
|
boat.setStarted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,16 +198,12 @@ public abstract class Race implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(long arg0) {
|
public void handle(long arg0) {
|
||||||
|
|
||||||
/*long timeLoopStarted;
|
|
||||||
long timeLoopEnded;
|
|
||||||
int fps = 0;*/
|
|
||||||
if (boatsFinished < startingBoats.size()) {
|
if (boatsFinished < startingBoats.size()) {
|
||||||
//timeLoopStarted = System.currentTimeMillis();
|
|
||||||
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
|
||||||
|
|
||||||
for (BoatInRace boat : startingBoats) {
|
for (BoatInRace boat : startingBoats) {
|
||||||
if (boat != null && !boat.isFinished()) {
|
if (boat != null && !boat.isFinished()) {
|
||||||
updatePosition(boat, Math.round(1000/lastFPS) > 20 ? 15 : Math.round(1000/lastFPS));
|
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
|
||||||
checkPosition(boat, totalTimeElapsed);
|
checkPosition(boat, totalTimeElapsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,7 +218,7 @@ public abstract class Race implements Runnable {
|
|||||||
stop(); //exit animation timer
|
stop(); //exit animation timer
|
||||||
}
|
}
|
||||||
fps++;
|
fps++;
|
||||||
if ((System.currentTimeMillis()-timeCurrent) > 1000){
|
if ((System.currentTimeMillis() - timeCurrent) > 1000) {
|
||||||
updateFPS(fps);
|
updateFPS(fps);
|
||||||
lastFPS = fps;
|
lastFPS = fps;
|
||||||
fps = 0;
|
fps = 0;
|
||||||
@@ -230,22 +232,23 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the position of the boat, this updates the boats current position.
|
* Checks the position of the boat, this updates the boats current position.
|
||||||
* @param boat Boat that the postion is to be updated for.
|
*
|
||||||
|
* @param boat Boat that the postion is to be updated for.
|
||||||
* @param timeElapsed Time that has elapse since the start of the the race.
|
* @param timeElapsed Time that has elapse since the start of the the race.
|
||||||
* @see BoatInRace
|
* @see BoatInRace
|
||||||
*/
|
*/
|
||||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) {
|
||||||
//boat has passed onto new leg
|
//boat has passed onto new leg
|
||||||
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
||||||
//boat has finished
|
//boat has finished
|
||||||
boatsFinished++;
|
boatsFinished++;
|
||||||
boat.setFinished(true);
|
boat.setFinished(true);
|
||||||
boat.setTimeFinished(timeElapsed);
|
boat.setTimeFinished(timeElapsed);
|
||||||
} else if(doNotFinish()) {
|
} else if (doNotFinish()) {
|
||||||
boatsFinished++;
|
boatsFinished++;
|
||||||
boat.setFinished(true);
|
boat.setFinished(true);
|
||||||
boat.setCurrentLeg(new Leg("DNF",-1));
|
boat.setCurrentLeg(new Leg("DNF", -1));
|
||||||
boat.setVelocity(0);
|
boat.setVelocity(0);
|
||||||
boat.setScaledVelocity(0);
|
boat.setScaledVelocity(0);
|
||||||
} else {
|
} else {
|
||||||
@@ -267,11 +270,12 @@ public abstract class Race implements Runnable {
|
|||||||
* Update call for the controller.
|
* Update call for the controller.
|
||||||
*/
|
*/
|
||||||
protected void setControllerListeners() {
|
protected void setControllerListeners() {
|
||||||
if(controller != null) controller.setInfoTable(this);
|
if (controller != null) controller.setInfoTable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the boats that have started the race.
|
* Returns the boats that have started the race.
|
||||||
|
*
|
||||||
* @return ObservableList of BoatInRace class that participated in the race.
|
* @return ObservableList of BoatInRace class that participated in the race.
|
||||||
* @see ObservableList
|
* @see ObservableList
|
||||||
* @see BoatInRace
|
* @see BoatInRace
|
||||||
@@ -282,6 +286,7 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the boat's gps coordinates depending on time elapsed
|
* Updates the boat's gps coordinates depending on time elapsed
|
||||||
|
*
|
||||||
* @param boat
|
* @param boat
|
||||||
* @param millisecondsElapsed
|
* @param millisecondsElapsed
|
||||||
*/
|
*/
|
||||||
@@ -289,7 +294,8 @@ public abstract class Race implements Runnable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
|
* Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
|
||||||
* @return
|
*
|
||||||
|
* @return list of starting positions
|
||||||
*/
|
*/
|
||||||
public ArrayList<Marker> getSpreadStartingPositions() {
|
public ArrayList<Marker> getSpreadStartingPositions() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
|
||||||
import com.sun.corba.se.impl.orbutil.graph.Graph;
|
|
||||||
import javafx.application.Platform;
|
|
||||||
import javafx.beans.property.StringProperty;
|
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -15,11 +12,7 @@ import seng302.GPSCoordinate;
|
|||||||
import seng302.GraphCoordinate;
|
import seng302.GraphCoordinate;
|
||||||
import seng302.RaceMap;
|
import seng302.RaceMap;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This creates a JavaFX Canvas that is fills it's parent.
|
* This creates a JavaFX Canvas that is fills it's parent.
|
||||||
@@ -61,7 +54,7 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
setMap(new RaceMap(32.278, -64.863, 32.320989, -64.821, (int) getWidth(), (int) getHeight()));
|
setMap(new RaceMap(32.278, -64.863, 32.320989, -64.821, (int) getWidth(), (int) getHeight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResizableRaceCanvas(double lat1, double long1, double lat2, double long2){
|
public ResizableRaceCanvas(double lat1, double long1, double lat2, double long2) {
|
||||||
this(null);
|
this(null);
|
||||||
setMap(new RaceMap(lat1, long1, lat2, long2, (int) getWidth(), (int) getHeight()));
|
setMap(new RaceMap(lat1, long1, lat2, long2, (int) getWidth(), (int) getHeight()));
|
||||||
}
|
}
|
||||||
@@ -77,16 +70,17 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the mark of a race as a circle.
|
* Displays the mark of a race as a circle.
|
||||||
|
*
|
||||||
* @param graphCoordinate Latitude and Logintude in GraphCoordinate that it is to be displayed as.
|
* @param graphCoordinate Latitude and Logintude in GraphCoordinate that it is to be displayed as.
|
||||||
* @param paint Colour the mark is to be coloured.
|
* @param paint Colour the mark is to be coloured.
|
||||||
* @see GraphCoordinate
|
* @see GraphCoordinate
|
||||||
* @see Color
|
* @see Color
|
||||||
* @see Paint
|
* @see Paint
|
||||||
*/
|
*/
|
||||||
public void displayMark(GraphCoordinate graphCoordinate, Paint paint){
|
public void displayMark(GraphCoordinate graphCoordinate, Paint paint) {
|
||||||
double d = 25;
|
double d = 25;
|
||||||
gc.setFill(paint);
|
gc.setFill(paint);
|
||||||
gc.fillOval(graphCoordinate.getX() - (d/2), graphCoordinate.getY() - (d/2), d, d);
|
gc.fillOval(graphCoordinate.getX() - (d / 2), graphCoordinate.getY() - (d / 2), d, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayBoat(BoatInRace boat, double angle) {
|
public void displayBoat(BoatInRace boat, double angle) {
|
||||||
@@ -105,9 +99,10 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a line on the map with rectangles on the starting and ending point of the line.
|
* 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 graphCoordinateA Starting Point of the line in GraphCoordinate.
|
||||||
* @param graphCoordinateB End Point of the line in GraphCoordinate.
|
* @param graphCoordinateB End Point of the line in GraphCoordinate.
|
||||||
* @param paint Colour the line is to coloured.
|
* @param paint Colour the line is to coloured.
|
||||||
* @see GraphCoordinate
|
* @see GraphCoordinate
|
||||||
* @see Color
|
* @see Color
|
||||||
* @see Paint
|
* @see Paint
|
||||||
@@ -122,8 +117,9 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a point on the Canvas
|
* Display a point on the Canvas
|
||||||
|
*
|
||||||
* @param graphCoordinate Coordinate that the point is to be displayed at.
|
* @param graphCoordinate Coordinate that the point is to be displayed at.
|
||||||
* @param paint Colour that the boat is to be coloured.
|
* @param paint Colour that the boat is to be coloured.
|
||||||
* @see GraphCoordinate
|
* @see GraphCoordinate
|
||||||
* @see Paint
|
* @see Paint
|
||||||
* @see Color
|
* @see Color
|
||||||
@@ -136,8 +132,9 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays an arrow on the Canvas
|
* Displays an arrow on the Canvas
|
||||||
|
*
|
||||||
* @param coordinate Coordinate that the arrow is to be displayed at.
|
* @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).
|
* @param angle Angle that the arrow is to be facing in degrees 0 degrees = North (Up).
|
||||||
* @see GraphCoordinate
|
* @see GraphCoordinate
|
||||||
*/
|
*/
|
||||||
private void displayArrow(GraphCoordinate coordinate, int angle) {
|
private void displayArrow(GraphCoordinate coordinate, int angle) {
|
||||||
@@ -152,9 +149,10 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotates things on the canvas Note: this must be called in between gc.save() and gc.restore() else they will rotate everything
|
* 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 angle Bearing angle to rotate at in degrees
|
||||||
* @param px Pivot point x of rotation.
|
* @param px Pivot point x of rotation.
|
||||||
* @param py Pivot point y of rotation.
|
* @param py Pivot point y of rotation.
|
||||||
*/
|
*/
|
||||||
private void rotate(double angle, double px, double py) {
|
private void rotate(double angle, double px, double py) {
|
||||||
Rotate r = new Rotate(angle, px, py);
|
Rotate r = new Rotate(angle, px, py);
|
||||||
@@ -163,18 +161,19 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Display given name and speed of boat at a graph coordinate
|
* Display given name and speed of boat at a graph coordinate
|
||||||
* @param name name of the boat
|
*
|
||||||
* @param speed speed of the boat
|
* @param name name of the boat
|
||||||
|
* @param speed speed of the boat
|
||||||
* @param coordinate coordinate the text appears
|
* @param coordinate coordinate the text appears
|
||||||
*/
|
*/
|
||||||
private void displayText(String name, double speed, GraphCoordinate coordinate){
|
private void displayText(String name, double speed, GraphCoordinate coordinate) {
|
||||||
String text = String.format("%s, %2$.2fkn", name, speed);
|
String text = String.format("%s, %2$.2fkn", name, speed);
|
||||||
long xCoord = coordinate.getX()+20;
|
long xCoord = coordinate.getX() + 20;
|
||||||
long yCoord = coordinate.getY();
|
long yCoord = coordinate.getY();
|
||||||
if (xCoord+(text.length()*7) >= getWidth()){
|
if (xCoord + (text.length() * 7) >= getWidth()) {
|
||||||
xCoord -= text.length()*7;
|
xCoord -= text.length() * 7;
|
||||||
}
|
}
|
||||||
if (yCoord-(text.length()*2) <= 0){
|
if (yCoord - (text.length() * 2) <= 0) {
|
||||||
yCoord += 30;
|
yCoord += 30;
|
||||||
}
|
}
|
||||||
gc.fillText(text, xCoord, yCoord);
|
gc.fillText(text, xCoord, yCoord);
|
||||||
@@ -188,8 +187,8 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
this.updateBoats();
|
this.updateBoats();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawBoundaries(){
|
public void drawBoundaries() {
|
||||||
if (this.raceBoundaries == null){
|
if (this.raceBoundaries == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gc.setFill(Color.AQUA);
|
gc.setFill(Color.AQUA);
|
||||||
@@ -210,8 +209,8 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
if (map == null) {
|
if (map == null) {
|
||||||
return;//TODO this should return a exception in the future
|
return;//TODO this should return a exception in the future
|
||||||
}
|
}
|
||||||
this.map.setHeight((int)height);
|
this.map.setHeight((int) height);
|
||||||
this.map.setWidth((int)width);
|
this.map.setWidth((int) width);
|
||||||
|
|
||||||
//finish line
|
//finish line
|
||||||
gc.setLineWidth(2);
|
gc.setLineWidth(2);
|
||||||
@@ -237,12 +236,13 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
updateBoats();
|
updateBoats();
|
||||||
|
|
||||||
//display wind direction arrow - specify origin point and angle - angle now set to random angle
|
//display wind direction arrow - specify origin point and angle - angle now set to random angle
|
||||||
displayArrow(new GraphCoordinate((int)getWidth()-40, 40), 150);
|
displayArrow(new GraphCoordinate((int) getWidth() - 40, 40), 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a boat at a certain GPSCoordinate
|
* Draws a boat at a certain GPSCoordinate
|
||||||
* @param colour Colour to colour boat.
|
*
|
||||||
|
* @param colour Colour to colour boat.
|
||||||
* @param gpsCoordinates GPScoordinate that the boat is to be drawn at.
|
* @param gpsCoordinates GPScoordinate that the boat is to be drawn at.
|
||||||
* @see GPSCoordinate
|
* @see GPSCoordinate
|
||||||
* @see Color
|
* @see Color
|
||||||
@@ -255,8 +255,8 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
/**
|
/**
|
||||||
* Toggle the raceAnno value
|
* Toggle the raceAnno value
|
||||||
*/
|
*/
|
||||||
public void toggleAnno(){
|
public void toggleAnnotations() {
|
||||||
if (raceAnno){
|
if (raceAnno) {
|
||||||
raceAnno = false;
|
raceAnno = false;
|
||||||
} else {
|
} else {
|
||||||
raceAnno = true;
|
raceAnno = true;
|
||||||
@@ -276,29 +276,30 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition());
|
GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition());
|
||||||
GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake());
|
GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake());
|
||||||
displayLine(wakeFrom, wakeTo, boat.getColour());
|
displayLine(wakeFrom, wakeTo, boat.getColour());
|
||||||
} else if (!isStart){
|
} else if (!isStart) {
|
||||||
displayBoat(boat, boat.calculateHeading());
|
displayBoat(boat, boat.calculateHeading());
|
||||||
} else {
|
} else {
|
||||||
displayBoat(boat, 0);
|
displayBoat(boat, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raceAnno) displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
if (raceAnno)
|
||||||
|
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRaceBoundaries(ArrayList<GPSCoordinate> boundaries) {
|
public void setRaceBoundaries(ArrayList<GPSCoordinate> boundaries) {
|
||||||
this.raceBoundaries = new ArrayList<>();
|
this.raceBoundaries = new ArrayList<>();
|
||||||
for (GPSCoordinate bound: boundaries){
|
for (GPSCoordinate bound : boundaries) {
|
||||||
raceBoundaries.add(bound);
|
raceBoundaries.add(bound);
|
||||||
}
|
}
|
||||||
setRaceBoundCoordinates();
|
setRaceBoundCoordinates();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRaceBoundCoordinates(){
|
public void setRaceBoundCoordinates() {
|
||||||
xpoints = new double[this.raceBoundaries.size()];
|
xpoints = new double[this.raceBoundaries.size()];
|
||||||
ypoints = new double[this.raceBoundaries.size()];
|
ypoints = new double[this.raceBoundaries.size()];
|
||||||
for (int i = 0; i < raceBoundaries.size(); i++){
|
for (int i = 0; i < raceBoundaries.size(); i++) {
|
||||||
GraphCoordinate coord = map.convertGPS(raceBoundaries.get(i));
|
GraphCoordinate coord = map.convertGPS(raceBoundaries.get(i));
|
||||||
xpoints[i] = coord.getX();
|
xpoints[i] = coord.getX();
|
||||||
ypoints[i] = coord.getY();
|
ypoints[i] = coord.getY();
|
||||||
@@ -337,17 +338,4 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
return getHeight();
|
return getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws boats during race setup, when leg heading is not set.
|
|
||||||
*/
|
|
||||||
public void drawBoats() {
|
|
||||||
if (boats != null) {
|
|
||||||
for (BoatInRace boat : boats) {
|
|
||||||
if (boat != null) {
|
|
||||||
displayBoat(boat, 0);
|
|
||||||
if (raceAnno) displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,11 +37,11 @@ public class RaceMap {
|
|||||||
public GraphCoordinate convertGPS(double lat, double lon) {
|
public GraphCoordinate convertGPS(double lat, double lon) {
|
||||||
int difference = Math.abs(width - height);
|
int difference = Math.abs(width - height);
|
||||||
int size = width;
|
int size = width;
|
||||||
if (width > height){
|
if (width > height) {
|
||||||
size = height;
|
size = height;
|
||||||
return new GraphCoordinate((int) ((size * (lon - x1) / (x2 - x1)) + difference/2), (int) (size - (size * (lat - y1) / (y2 - y1))));
|
return new GraphCoordinate((int) ((size * (lon - x1) / (x2 - x1)) + difference / 2), (int) (size - (size * (lat - y1) / (y2 - y1))));
|
||||||
}else{
|
} else {
|
||||||
return new GraphCoordinate((int) (size * (lon - x1) / (x2 - x1)), (int) ((size - (size * (lat - y1) / (y2 - y1))) + difference/2));
|
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))));
|
//return new GraphCoordinate((int) (width * (lon - x1) / (x2 - x1)), (int) (height - (height * (lat - y1) / (y2 - y1))));
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import org.w3c.dom.*;
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import seng302.Model.Boat;
|
|
||||||
import seng302.Model.BoatInRace;
|
import seng302.Model.BoatInRace;
|
||||||
import seng302.Model.Leg;
|
import seng302.Model.Leg;
|
||||||
import seng302.Model.Marker;
|
import seng302.Model.Marker;
|
||||||
@@ -15,7 +15,7 @@ import java.util.ArrayList;
|
|||||||
/**
|
/**
|
||||||
* Created by fwy13 on 26/03/2017.
|
* Created by fwy13 on 26/03/2017.
|
||||||
*/
|
*/
|
||||||
public class RaceXMLReader extends XMLReader{
|
public class RaceXMLReader extends XMLReader {
|
||||||
private ArrayList<BoatInRace> boats = new ArrayList<>();
|
private ArrayList<BoatInRace> boats = new ArrayList<>();
|
||||||
private Color[] colors = {Color.BLUEVIOLET, Color.BLACK, Color.RED, Color.ORANGE, Color.DARKOLIVEGREEN, Color.LIMEGREEN};//TODO make this established in xml or come up with a better system.
|
private Color[] colors = {Color.BLUEVIOLET, Color.BLACK, Color.RED, Color.ORANGE, Color.DARKOLIVEGREEN, Color.LIMEGREEN};//TODO make this established in xml or come up with a better system.
|
||||||
private ArrayList<Leg> legs = new ArrayList<>();
|
private ArrayList<Leg> legs = new ArrayList<>();
|
||||||
@@ -36,34 +36,34 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void read(){
|
private void read() {
|
||||||
readCourse();
|
readCourse();
|
||||||
readLegs();
|
readLegs();
|
||||||
readBoats();
|
readBoats();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readBoats(){
|
public void readBoats() {
|
||||||
//get all boats
|
//get all boats
|
||||||
NodeList nBoats = doc.getElementsByTagName("boat");
|
NodeList nBoats = doc.getElementsByTagName("boat");
|
||||||
|
|
||||||
for (int i = 0; i < nBoats.getLength(); i++){
|
for (int i = 0; i < nBoats.getLength(); i++) {
|
||||||
String name = getTextValueOfNode((Element) nBoats.item(i), "name");
|
String name = getTextValueOfNode((Element) nBoats.item(i), "name");
|
||||||
String abbrev = getTextValueOfNode((Element) nBoats.item(i), "abbr");
|
String abbrev = getTextValueOfNode((Element) nBoats.item(i), "abbr");
|
||||||
double velo = Double.parseDouble(getTextValueOfNode((Element) nBoats.item(i), "speed"));
|
double velo = Double.parseDouble(getTextValueOfNode((Element) nBoats.item(i), "speed"));
|
||||||
BoatInRace boat = new BoatInRace(name, velo, colors[i], abbrev);
|
BoatInRace boat = new BoatInRace(name, velo, colors[i], abbrev);
|
||||||
boat.setCurrentPosition(startPt1);
|
boat.setCurrentPosition(startPt1);
|
||||||
if (legs.size() > 0){
|
if (legs.size() > 0) {
|
||||||
boat.setCurrentLeg(legs.get(0));
|
boat.setCurrentLeg(legs.get(0));
|
||||||
}
|
}
|
||||||
boats.add(boat);
|
boats.add(boat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readLegs(){
|
public void readLegs() {
|
||||||
//get all legs
|
//get all legs
|
||||||
NodeList nLegs = doc.getElementsByTagName("leg");
|
NodeList nLegs = doc.getElementsByTagName("leg");
|
||||||
|
|
||||||
for (int i = 0; i < nLegs.getLength(); i++){
|
for (int i = 0; i < nLegs.getLength(); i++) {
|
||||||
String label = getTextValueOfNode((Element) nLegs.item(i), "name");
|
String label = getTextValueOfNode((Element) nLegs.item(i), "name");
|
||||||
NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start");
|
NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start");
|
||||||
Marker startMarker = getMarker(start);
|
Marker startMarker = getMarker(start);
|
||||||
@@ -73,10 +73,10 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readCourse(){
|
public void readCourse() {
|
||||||
NodeList nCourse = doc.getElementsByTagName("course");
|
NodeList nCourse = doc.getElementsByTagName("course");
|
||||||
|
|
||||||
NodeList nBounds = ((Element)nCourse.item(0)).getElementsByTagName("boundaries");
|
NodeList nBounds = ((Element) nCourse.item(0)).getElementsByTagName("boundaries");
|
||||||
nBounds = ((Element) nBounds.item(0)).getElementsByTagName("coordinate");
|
nBounds = ((Element) nBounds.item(0)).getElementsByTagName("coordinate");
|
||||||
int maxLatitudeIndex = 0;
|
int maxLatitudeIndex = 0;
|
||||||
double maxLatitude = -Double.MIN_VALUE;
|
double maxLatitude = -Double.MIN_VALUE;
|
||||||
@@ -86,21 +86,21 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
double minLatitude = Double.MAX_VALUE;
|
double minLatitude = Double.MAX_VALUE;
|
||||||
int minLongitudeIndex = 0;
|
int minLongitudeIndex = 0;
|
||||||
double minLongitude = Double.MAX_VALUE;
|
double minLongitude = Double.MAX_VALUE;
|
||||||
for (int i = 0; i < nBounds.getLength(); i++){
|
for (int i = 0; i < nBounds.getLength(); i++) {
|
||||||
boundary.add(getCoordinates((Element) nBounds.item(i)));
|
boundary.add(getCoordinates((Element) nBounds.item(i)));
|
||||||
if (boundary.get(i).getLatitude() > maxLatitude){
|
if (boundary.get(i).getLatitude() > maxLatitude) {
|
||||||
maxLatitudeIndex = i;
|
maxLatitudeIndex = i;
|
||||||
maxLatitude = boundary.get(i).getLatitude();
|
maxLatitude = boundary.get(i).getLatitude();
|
||||||
}
|
}
|
||||||
if (boundary.get(i).getLatitude() < minLatitude){
|
if (boundary.get(i).getLatitude() < minLatitude) {
|
||||||
minLatitudeIndex = i;
|
minLatitudeIndex = i;
|
||||||
minLatitude = boundary.get(i).getLatitude();
|
minLatitude = boundary.get(i).getLatitude();
|
||||||
}
|
}
|
||||||
if (boundary.get(i).getLongitude() > maxLongitude){
|
if (boundary.get(i).getLongitude() > maxLongitude) {
|
||||||
maxLongitudeIndex = i;
|
maxLongitudeIndex = i;
|
||||||
maxLongitude = boundary.get(i).getLongitude();
|
maxLongitude = boundary.get(i).getLongitude();
|
||||||
}
|
}
|
||||||
if (boundary.get(i).getLongitude() < minLongitude){
|
if (boundary.get(i).getLongitude() < minLongitude) {
|
||||||
minLongitudeIndex = i;
|
minLongitudeIndex = i;
|
||||||
minLongitude = boundary.get(i).getLongitude();
|
minLongitude = boundary.get(i).getLongitude();
|
||||||
}
|
}
|
||||||
@@ -109,14 +109,14 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
double difference = 0;//this will hold the largest difference so we can make the map square.
|
double difference = 0;//this will hold the largest difference so we can make the map square.
|
||||||
double latitudeDiff = Math.abs(Math.abs(boundary.get(maxLatitudeIndex).getLatitude()) - Math.abs(boundary.get(minLatitudeIndex).getLatitude()));
|
double latitudeDiff = Math.abs(Math.abs(boundary.get(maxLatitudeIndex).getLatitude()) - Math.abs(boundary.get(minLatitudeIndex).getLatitude()));
|
||||||
double longitudeDiff = Math.abs(Math.abs(boundary.get(maxLongitudeIndex).getLongitude()) - Math.abs(boundary.get(minLongitudeIndex).getLongitude()));
|
double longitudeDiff = Math.abs(Math.abs(boundary.get(maxLongitudeIndex).getLongitude()) - Math.abs(boundary.get(minLongitudeIndex).getLongitude()));
|
||||||
if (latitudeDiff >= longitudeDiff){
|
if (latitudeDiff >= longitudeDiff) {
|
||||||
difference = latitudeDiff - longitudeDiff;
|
difference = latitudeDiff - longitudeDiff;
|
||||||
maxLongitude += difference/2;
|
maxLongitude += difference / 2;
|
||||||
minLongitude -= difference/2;
|
minLongitude -= difference / 2;
|
||||||
}else{
|
} else {
|
||||||
difference = longitudeDiff - latitudeDiff;
|
difference = longitudeDiff - latitudeDiff;
|
||||||
maxLatitude += difference/2;
|
maxLatitude += difference / 2;
|
||||||
minLatitude -= difference/2;
|
minLatitude -= difference / 2;
|
||||||
}
|
}
|
||||||
maxLatitude += COORDINATEPADDING;
|
maxLatitude += COORDINATEPADDING;
|
||||||
minLatitude -= COORDINATEPADDING;
|
minLatitude -= COORDINATEPADDING;
|
||||||
@@ -128,7 +128,7 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
mapTopLeft = new GPSCoordinate(minLatitude, minLongitude);
|
mapTopLeft = new GPSCoordinate(minLatitude, minLongitude);
|
||||||
mapBottomRight = new GPSCoordinate(maxLatitude, maxLongitude);
|
mapBottomRight = new GPSCoordinate(maxLatitude, maxLongitude);
|
||||||
|
|
||||||
NodeList nMarks = ((Element)nCourse.item(0)).getElementsByTagName("marker");
|
NodeList nMarks = ((Element) nCourse.item(0)).getElementsByTagName("marker");
|
||||||
startPt1 = getCoordinates(nMarks, 0);
|
startPt1 = getCoordinates(nMarks, 0);
|
||||||
startPt2 = getCoordinates(nMarks, 0, 1);
|
startPt2 = getCoordinates(nMarks, 0, 1);
|
||||||
mark = getCoordinates(nMarks, 1);
|
mark = getCoordinates(nMarks, 1);
|
||||||
@@ -140,7 +140,9 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
finishPt2 = getCoordinates(nMarks, 4, 1);
|
finishPt2 = getCoordinates(nMarks, 4, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Marker getMarker(NodeList start) { return getMarker(start, 0); }
|
private Marker getMarker(NodeList start) {
|
||||||
|
return getMarker(start, 0);
|
||||||
|
}
|
||||||
|
|
||||||
private Marker getMarker(NodeList start, int startIndex) {
|
private Marker getMarker(NodeList start, int startIndex) {
|
||||||
return getMarker(start, startIndex, 0);
|
return getMarker(start, startIndex, 0);
|
||||||
@@ -156,7 +158,7 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
|
|
||||||
NodeList nCoordinates = markerNode.getElementsByTagName("coordinate");
|
NodeList nCoordinates = markerNode.getElementsByTagName("coordinate");
|
||||||
|
|
||||||
GPSCoordinate side1 = getCoordinates((Element) nCoordinates.item(0));
|
GPSCoordinate side1 = getCoordinates((Element) nCoordinates.item(0));
|
||||||
GPSCoordinate side2;
|
GPSCoordinate side2;
|
||||||
if (nCoordinates.getLength() > 1) {
|
if (nCoordinates.getLength() > 1) {
|
||||||
side2 = getCoordinates((Element) nCoordinates.item(1));
|
side2 = getCoordinates((Element) nCoordinates.item(1));
|
||||||
@@ -167,15 +169,15 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private GPSCoordinate getCoordinates(NodeList start){
|
private GPSCoordinate getCoordinates(NodeList start) {
|
||||||
return getCoordinates(start, 0);
|
return getCoordinates(start, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GPSCoordinate getCoordinates(NodeList start, int startIndex){
|
private GPSCoordinate getCoordinates(NodeList start, int startIndex) {
|
||||||
return getCoordinates(start, startIndex, 0);
|
return getCoordinates(start, startIndex, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GPSCoordinate getCoordinates(NodeList start, int startIndex, int nodeIndex){
|
private GPSCoordinate getCoordinates(NodeList start, int startIndex, int nodeIndex) {
|
||||||
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("coordinate");
|
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("coordinate");
|
||||||
Element coord = (Element) nodeList.item(nodeIndex);
|
Element coord = (Element) nodeList.item(nodeIndex);
|
||||||
return getCoordinates(coord);
|
return getCoordinates(coord);
|
||||||
@@ -183,10 +185,11 @@ public class RaceXMLReader extends XMLReader{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the coordinate TODO raise exception that runs when the XML is formatted wrongly.
|
* Returns the coordinate TODO raise exception that runs when the XML is formatted wrongly.
|
||||||
|
*
|
||||||
* @param coordNode
|
* @param coordNode
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private GPSCoordinate getCoordinates(Element coordNode){
|
private GPSCoordinate getCoordinates(Element coordNode) {
|
||||||
|
|
||||||
double startLat = Double.parseDouble(getTextValueOfNode(coordNode, "latitude"));
|
double startLat = Double.parseDouble(getTextValueOfNode(coordNode, "latitude"));
|
||||||
double startLong = Double.parseDouble(getTextValueOfNode(coordNode, "longitude"));
|
double startLong = Double.parseDouble(getTextValueOfNode(coordNode, "longitude"));
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
import org.w3c.dom.*;
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import javax.xml.parsers.*;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import java.io.*;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by fwy13 on 26/03/2017.
|
* Created by fwy13 on 26/03/2017.
|
||||||
@@ -21,7 +25,7 @@ public abstract class XMLReader {
|
|||||||
doc.getDocumentElement().normalize();
|
doc.getDocumentElement().normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Document getDocument(){
|
public Document getDocument() {
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +33,7 @@ public abstract class XMLReader {
|
|||||||
return n.getElementsByTagName(tagName).item(0).getTextContent();
|
return n.getElementsByTagName(tagName).item(0).getTextContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAttribute(Element n, String attr){
|
public String getAttribute(Element n, String attr) {
|
||||||
return n.getAttribute(attr);
|
return n.getAttribute(attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@
|
|||||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="77.0" prefWidth="200.0">
|
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="77.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||||
<CheckBox fx:id="showAnno" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" />
|
<CheckBox fx:id="showAnnotations" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
|
|||||||
Reference in New Issue
Block a user