Linked raceData from new xml formats to current program. Current app now shows the starting list and course boundary. #story[782]

This commit is contained in:
Joseph Gardner
2017-04-25 16:06:24 +12:00
parent cb40302c13
commit c328c4f3bc
9 changed files with 435 additions and 15 deletions
@@ -9,6 +9,7 @@ import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import org.xml.sax.SAXException;
import seng302.Mock.StreamedRace;
import seng302.Model.*;
import seng302.RaceDataSource;
import seng302.RaceXMLReader;
@@ -116,14 +117,14 @@ public class RaceController extends Controller {
* @param scaleFactor scale value of race
*/
public void startRace(int scaleFactor, RaceDataSource raceData) {
ConstantVelocityRace newRace = new ConstantVelocityRace(raceData, this, scaleFactor);
newRace.initialiseBoats();
StreamedRace newRace = new StreamedRace(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.setBoats(newRace.getStartingBoats());
raceMap.setRaceBoundaries(raceData.getBoundary());
raceMap.drawRaceMap();
raceMap.setVisible(true);
@@ -13,6 +13,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import org.xml.sax.SAXException;
import seng302.Mock.*;
import seng302.Model.BoatInRace;
import seng302.Model.RaceClock;
import seng302.RaceDataSource;
@@ -21,6 +22,7 @@ import seng302.RaceXMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.URL;
import java.text.ParseException;
import java.util.List;
import java.util.ResourceBundle;
@@ -81,13 +83,20 @@ public class StartController extends Controller {
public void initialize(URL location, ResourceBundle resources){
raceData = null;
try {
raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
StreamedCourse streamedCourse = new StreamedCourse(new BoatXMLReader("mockXML/boatXML/boatTest.xml"));
streamedCourse.setStreamedCourseXMLReader(new StreamedCourseXMLReader("mockXML/raceXML/raceTest.xml"));
streamedCourse.setRegattaXMLReader(new RegattaXMLReader("mockXML/regattaXML/regattaTest.xml"));
raceData = streamedCourse;
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (StreamedCourseXMLException e) {
e.printStackTrace();
}
initialiseTables();
setRaceClock();
@@ -1,5 +1,7 @@
package seng302.Mock;
import seng302.GPSCoordinate;
/**
* Created by jjg64 on 19/04/17.
*/
@@ -96,4 +98,8 @@ public class Regatta {
public void setMagneticVariation(float magneticVariation) {
this.magneticVariation = magneticVariation;
}
public GPSCoordinate getGPSCoordinate() {
return new GPSCoordinate(centralLatitude, centralLongitude);
}
}
@@ -3,26 +3,55 @@ package seng302.Mock;
import seng302.GPSCoordinate;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.RaceClock;
import seng302.RaceDataSource;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
*/
public class StreamedCourse implements RaceDataSource {
StreamedCourseXMLReader streamedCourseXMLReader;
StreamedCourseXMLReader streamedCourseXMLReader = null;
BoatXMLReader boatXMLReader = null;
RegattaXMLReader regattaXMLReader = null;
List<GPSCoordinate> boundary = new ArrayList<>();
public StreamedCourse(StreamedCourseXMLReader streamedCourseXMLReader) {
this.streamedCourseXMLReader = streamedCourseXMLReader;
}
public StreamedCourse(BoatXMLReader boatXMLReader) {
this.boatXMLReader = boatXMLReader;
}
public void setBoatXMLReader(BoatXMLReader boatXMLReader) {
this.boatXMLReader = boatXMLReader;
if (streamedCourseXMLReader != null) {
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
boatXMLReader.read();
}
}
public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) {
this.streamedCourseXMLReader = streamedCourseXMLReader;
if (streamedCourseXMLReader != null) {
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
boatXMLReader.read();
}
}
public void setRegattaXMLReader(RegattaXMLReader regattaXMLReader) {
this.regattaXMLReader = regattaXMLReader;
}
public RegattaXMLReader getRegattaXMLReader() {
return regattaXMLReader;
}
public List<BoatInRace> getBoats() {
return null;
return new ArrayList<>(boatXMLReader.getStreamedBoatMap().values());
}
public List<Leg> getLegs() {
@@ -34,7 +63,7 @@ public class StreamedCourse implements RaceDataSource {
}
public ZonedDateTime getZonedDateTime() {
return null;
return RaceClock.getCurrentZonedDateTime(regattaXMLReader.getRegatta().getGPSCoordinate());
}
public GPSCoordinate getMapTopLeft() {
@@ -44,7 +73,4 @@ public class StreamedCourse implements RaceDataSource {
public GPSCoordinate getMapBottomRight() {
return streamedCourseXMLReader.getMapBottomRight();
}
}
@@ -25,6 +25,7 @@ public class StreamedCourseXMLReader extends XMLReader {
private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>();
private Map<Integer,Element> marks = new HashMap<>();
private Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Leg> legs = new ArrayList<>();
Date creationTimeDate;
Date raceStartTime;
@@ -77,8 +78,17 @@ public class StreamedCourseXMLReader extends XMLReader {
}
private void readParticipants() {
//TODO Modify BoatInRace to take in a sourceID
//TODO Produce list of BoatInRace
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
for (int i = 0; i < nParticipants.getChildNodes().getLength(); i++) {
int sourceID;
Node yacht = nParticipants.getChildNodes().item(i);
if (yacht.getNodeName().equals("Yacht")) {
if (exists(yacht, "SourceID")) {
sourceID = Integer.parseInt(yacht.getAttributes().getNamedItem("SourceID").getTextContent());
participants.put(sourceID, new StreamedBoat(sourceID));
}
}
}
}
private void readCourse() throws StreamedCourseXMLException {
@@ -222,4 +232,8 @@ public class StreamedCourseXMLReader extends XMLReader {
public boolean isPostpone() {
return postpone;
}
public Map<Integer, StreamedBoat> getParticipants() {
return participants;
}
}
@@ -318,6 +318,8 @@ public class ResizableRaceCanvas extends Canvas {
* Draws boats while race in progress, when leg heading is set.
*/
public void updateBoats() {
// TODO Remove null when boats are ready
boats = null;
if (boats != null) {
for (BoatInRace boat : boats) {
boolean finished = boat.getCurrentLeg().getName().equals("Finish") || boat.getCurrentLeg().getName().equals("DNF");