Implemented marker visualisation from XML in ResizableRaceCanvas

- Replaced and deprecated Constants
- Added getMarkers to RaceDataSource interface
- Added boundary testing for source data

#story[782]
This commit is contained in:
Connor Taylor-Brown
2017-04-28 01:58:55 +12:00
parent 073102d1a3
commit 02511db2b9
9 changed files with 78 additions and 28 deletions
@@ -3,6 +3,7 @@ package seng302.Mock;
import seng302.GPSCoordinate;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Marker;
import seng302.Model.RaceClock;
import seng302.RaceDataSource;
@@ -58,6 +59,8 @@ public class StreamedCourse implements RaceDataSource {
return streamedCourseXMLReader.getLegs();
}
public List<Marker> getMarkers() { return streamedCourseXMLReader.getMarkers(); }
public List<GPSCoordinate> getBoundary() {
return streamedCourseXMLReader.getBoundary();
}
@@ -21,12 +21,13 @@ import java.util.*;
* Created by jjg64 on 21/04/17.
*/
public class StreamedCourseXMLReader extends XMLReader {
private static double COORDINATEPADDING = 0.0005;
private static double COORDINATEPADDING = 0.000;
private GPSCoordinate mapTopLeft, mapBottomRight;
private List<GPSCoordinate> boundary = new ArrayList<>();
private Map<Integer,Element> marks = new HashMap<>();
private Map<Integer,Element> compoundMarks = new HashMap<>();
private Map<Integer, StreamedBoat> participants = new HashMap<>();
private List<Leg> legs = new ArrayList<>();
private List<Marker> markers = new ArrayList<>();
Date creationTimeDate;
Date raceStartTime;
int raceID;
@@ -98,14 +99,17 @@ public class StreamedCourseXMLReader extends XMLReader {
}
/**
* Indexes CompoundMark elements by their ID for use in generating the course.
* Indexes CompoundMark elements by their ID for use in generating the course, and populates list of Markers.
* @see seng302.Model.Marker
*/
private void readCompoundMarks() {
private void readCompoundMarks() throws StreamedCourseXMLException {
Element nCourse = (Element) doc.getElementsByTagName("Course").item(0);
for(int i = 0; i < nCourse.getChildNodes().getLength(); i++) {
Node compoundMark = nCourse.getChildNodes().item(i);
if(compoundMark.getNodeName().equals("CompoundMark")) {
marks.put(getCompoundMarkID((Element)compoundMark),(Element)compoundMark);
int compoundMarkID = getCompoundMarkID((Element) compoundMark);
compoundMarks.put(compoundMarkID, (Element)compoundMark);
markers.add(getMarker(compoundMarkID));
}
}
}
@@ -114,11 +118,11 @@ public class StreamedCourseXMLReader extends XMLReader {
* Generates a Marker from the CompoundMark element with given ID.
* @param compoundMarkID index of required CompoundMark element
* @return generated Marker
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of marks
* @throws StreamedCourseXMLException if CompoundMark element contains unhandled number of compoundMarks
* @see seng302.Model.Marker
*/
private Marker getMarker(int compoundMarkID) throws StreamedCourseXMLException {
Element compoundMark = marks.get(compoundMarkID);
Element compoundMark = compoundMarks.get(compoundMarkID);
NodeList nMarks = compoundMark.getElementsByTagName("Mark");
Marker marker;
@@ -152,7 +156,7 @@ public class StreamedCourseXMLReader extends XMLReader {
* @return value of "name" attribute
*/
private String getCompoundMarkName(int compoundMarkID) {
return marks.get(compoundMarkID).getAttribute("Name");
return compoundMarks.get(compoundMarkID).getAttribute("Name");
}
/**
@@ -184,6 +188,7 @@ public class StreamedCourseXMLReader extends XMLReader {
}
}
double maxLatitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
double maxLongitude = boundary.stream().max(Comparator.comparingDouble(GPSCoordinate::getLongitude)).get().getLongitude() + COORDINATEPADDING;
double minLatitude = boundary.stream().min(Comparator.comparingDouble(GPSCoordinate::getLatitude)).get().getLatitude() + COORDINATEPADDING;
@@ -209,6 +214,8 @@ public class StreamedCourseXMLReader extends XMLReader {
return legs;
}
public List<Marker> getMarkers() { return markers; }
public Double getPadding() {
return COORDINATEPADDING;
}