Merge branch 'Story877' into 'sprint4_master'

Added Important and Partial Annotations and other refactors and documentation.

- Important, Partial, Hidden, Visible are all radiobuttons
- Fixed bug where the Visualiser would end the race before the last boat had finished
- Refactored the visualiser and the mock to use the race finished status message
- Added and Changed many Javadocs
#story[877]

See merge request !5
main
Connor Taylor Brown 9 years ago
commit 37828ef0fe

@ -49,6 +49,16 @@ public class App extends Application {
}
}
/**
* Reads the Initial Race XML files that are necessary to run the mock.
* @param path path of the XML
* @param encoding encoding of the xml
* @return
* @throws IOException No file etc
* @throws ParserConfigurationException Issue with the XML formatting
* @throws SAXException Issue with XML formatting
* @throws TransformerException Issue with the XML format
*/
private String readFile(String path, Charset encoding) throws IOException, ParserConfigurationException, SAXException, TransformerException {
InputSource fXmlFile = new InputSource(getClass().getClassLoader().getResourceAsStream(path));

@ -6,7 +6,7 @@ import seng302.Model.Mark;
import java.util.Map;
/**
* Created by cbt24 on 10/05/17.
* Boats Data
*/
public interface BoatDataSource {
Map<Integer, Boat> getBoats();

@ -14,7 +14,7 @@ import java.util.HashMap;
import java.util.Map;
/**
* Created by cbt24 on 10/05/17.
* Xml Reader class for Boat XML used for the race
*/
public class BoatXMLReader extends XMLReader implements BoatDataSource {
@ -42,12 +42,18 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
read();
}
/**
* Read the XML
*/
public void read() {
readSettings();
readShapes();
readBoats();
}
/**
* Read the Boats
*/
private void readBoats() {
Element nBoats = (Element) doc.getElementsByTagName("Boats").item(0);
for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) {
@ -72,6 +78,11 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
}
/**
* Checks if the node (XMl data node) is a Yacht or not
* @param boatNode Node from the XML
* @return Whether the node is a yacht node or not
*/
private boolean isYachtNode(Node boatNode) {
return boatNode.getAttributes().getNamedItem("Type").getTextContent().toLowerCase().equals("yacht");
}
@ -88,6 +99,12 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
else readMark(boatNode, sourceID, name);
}
/**
* Read a Yacht Node
* @param boatNode Node to be read
* @param sourceID Source ID of the Yacht
* @param name Name of the Boat
*/
private void readYacht(Node boatNode, int sourceID, String name) {
String shortName = boatNode.getAttributes().getNamedItem("ShortName").getTextContent();
if (exists(boatNode, "Country")) {
@ -98,6 +115,12 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
}
}
/**
* Read Marker Boats
* @param boatNode Node to be read
* @param sourceID Source ID of the boat
* @param name Name of the Marker Boat
*/
private void readMark(Node boatNode, int sourceID, String name) {
Node nCoord = ((Element)boatNode).getElementsByTagName("GPSposition").item(0);
double x = Double.parseDouble(nCoord.getAttributes().getNamedItem("X").getTextContent());
@ -106,11 +129,19 @@ public class BoatXMLReader extends XMLReader implements BoatDataSource {
markerMap.put(sourceID, mark);
}
/**
* Get the boats that are going to participate in this race
* @return Dictionary of boats that are to participate in this race indexed by SourceID
*/
@Override
public Map<Integer, Boat> getBoats() {
return boatMap;
}
/**
* Get the marker BOats that are participating in this race
* @return Dictionary of the Markers BOats that are in this race indexed by their Source ID.
*/
@Override
public Map<Integer, Mark> getMarkerBoats() {
return markerMap;

@ -9,7 +9,7 @@ import java.time.ZonedDateTime;
import java.util.List;
/**
* Created by connortaylorbrown on 19/04/17.
* Data Class for a Race
*/
public interface RaceDataSource {
List<Boat> getBoats();

@ -16,7 +16,7 @@ import java.time.format.DateTimeFormatter;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
* XML Reader that reads in the race data required for this race
*/
public class RaceXMLReader extends XMLReader implements RaceDataSource {
private static final double COORDINATEPADDING = 0.000;
@ -103,6 +103,9 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
}
/**
* Reads in the participants for htis race
*/
private void readParticipants() {
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
nParticipants.getChildNodes().getLength();
@ -166,6 +169,11 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
return marker;
}
/**
* Gets a mark from an Element
* @param mark Element the mark is suppose to be part of
* @return a Mark that existed in the element
*/
private Mark getMark(Element mark) {
int sourceID = Integer.parseInt(mark.getAttribute("SourceID"));
return marks.get(sourceID);
@ -209,6 +217,9 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
}
/**
* Reads the boundary limits of the course
*/
private void readCourseLimit() {
Element nCourseLimit = (Element) doc.getElementsByTagName("CourseLimit").item(0);
for(int i = 0; i < nCourseLimit.getChildNodes().getLength(); i++) {

@ -18,7 +18,7 @@ import java.io.StringReader;
import java.io.StringWriter;
/**
* Created by fwy13 on 26/03/2017.
* Base Reader for XML Files
*/
public abstract class XMLReader {
@ -48,6 +48,11 @@ public abstract class XMLReader {
doc.getDocumentElement().normalize();
}
/**
* Alternate constructor
* @param xmlFile
* @param isWholeFile
*/
public XMLReader(String xmlFile, Boolean isWholeFile) {
}
@ -84,6 +89,12 @@ public abstract class XMLReader {
return node.getAttributes().getNamedItem(attribute) != null;
}
/**
* Get the contents of the XML FILe.
* @param document
* @return
* @throws TransformerException
*/
public static String getContents(Document document) throws TransformerException {
DOMSource source = new DOMSource(document);

@ -49,6 +49,7 @@ public class MockOutput implements Runnable
private String regattaXml;
private String boatsXml;
private boolean stop = false; //whether or not hte thread keeps running
/**
* Ctor.
@ -158,18 +159,25 @@ public class MockOutput implements Runnable
this.messagesToSendQueue.add(messagesToSendBuffer);
}
/**
* Sending loop of the Server
*/
public void run() {
try {
while (true){
while (!stop){
System.out.println("Waiting for a connection...");//TEMP DEBUG REMOVE
mockSocket = serverSocket.accept();
outToVisualiser = new DataOutputStream(mockSocket.getOutputStream());
while(boatsXml == null || regattaXml == null || raceXml == null) {
if (boatsXml == null || regattaXml == null || raceXml == null){
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
continue;
}
parseXMLString(raceXml, XMLMessage.XMLTypeRace);
@ -205,18 +213,30 @@ public class MockOutput implements Runnable
}
}
public void stop(){
stop = true;
}
/**
* Sets the Race XML to send
* @param raceXml XML to send to the CLient
*/
public void setRaceXml(String raceXml) {
this.raceXml = raceXml;
}
/**
* Sets the Regatta XMl to send
* @param regattaXml XML to send to CLient
*/
public void setRegattaXml(String regattaXml) {
this.regattaXml = regattaXml;
}
/**
* Sets the Boats XML to send
* @param boatsXml XMl to send to the CLient
*/
public void setBoatsXml(String boatsXml) {
this.boatsXml = boatsXml;
}

@ -5,7 +5,7 @@ import seng302.Networking.Messages.Enums.BoatStatusEnum;
/**
* This class represents a boat during a race.
* Boat Model that is used to store information on the boats that are running in the race.
*/
public class Boat {
/**

@ -14,7 +14,7 @@ import java.time.format.DateTimeFormatter;
/**
* Created by esa46 on 21/04/17.
* A Race Event, this holds all of the race's information as well as handling the connection to its clients.
*/
public class Event {

@ -2,7 +2,7 @@ package seng302.Model;
/**
* Represents a leg of a race.
* Leg of the race, this is what each part of the race is divided into, from mark to mark.
*/
public class Leg {

@ -371,7 +371,7 @@ public class Race implements Runnable {
} else {
//Otherwise, the race is over!
raceFinished.start();
setRaceStatusEnum(RaceStatusEnum.FINISHED);
this.stop();
}
@ -394,6 +394,22 @@ public class Race implements Runnable {
}
};
/**
* Broadcast that the race has finished.
*/
protected AnimationTimer raceFinished = new AnimationTimer(){
int iters = 0;
@Override
public void handle(long now) {
RaceStatus raceStatus = new RaceStatus(System.currentTimeMillis(), raceId, 4, startTime, 0, 2300, 2, null);
mockOutput.parseRaceStatus(raceStatus);
if (iters > 500){
mockOutput.stop();
stop();
}
iters++;
}
};
/**
* Initialise the boats in the race.
@ -614,7 +630,6 @@ public class Race implements Runnable {
}
/**
* Calculates the upper and lower bounds that the boat may have in order to not go outside of the course.
* @param boat The boat to check.

@ -14,7 +14,7 @@ import static junit.framework.TestCase.assertEquals;
*/
public class LegTest {
private CompoundMark ORIGIN_Compound_MARKER = new CompoundMark(new Mark(1, "test mark1", new GPSCoordinate(0, 0)));
private CompoundMark ORIGIN_COMPOUND_MARKER = new CompoundMark(new Mark(1, "test mark1", new GPSCoordinate(0, 0)));
@Test
public void calculateDistanceHandles5nmNorth() {
@ -23,7 +23,7 @@ public class LegTest {
calc.setDirection(0, 5 * Constants.NMToMetersConversion);
CompoundMark endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0);
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, endMarker, 0);
assertEquals(test.getDistanceNauticalMiles(), 5, 1e-8);
}
@ -34,7 +34,7 @@ public class LegTest {
calc.setDirection(90, 12 * Constants.NMToMetersConversion);
CompoundMark endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0);
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, endMarker, 0);
assertEquals(test.getDistanceNauticalMiles(), 12, 1e-8);
}
@ -45,7 +45,7 @@ public class LegTest {
calc.setDirection(180, 0.5 * Constants.NMToMetersConversion);
CompoundMark endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0);
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, endMarker, 0);
assertEquals(test.getDistanceNauticalMiles(), 0.5, 1e-8);
}
@ -56,14 +56,14 @@ public class LegTest {
calc.setDirection(-90, 0.1 * Constants.NMToMetersConversion);
CompoundMark endMarker = getEndMarker(calc.getDestinationGeographicPoint());
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, endMarker, 0);
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, endMarker, 0);
assertEquals(test.getDistanceNauticalMiles(), 0.1, 1e-8);
}
@Test
public void calculateDistanceHandlesZeroDifference() {
Leg test = new Leg("Test", ORIGIN_Compound_MARKER, ORIGIN_Compound_MARKER, 0);
Leg test = new Leg("Test", ORIGIN_COMPOUND_MARKER, ORIGIN_COMPOUND_MARKER, 0);
assertEquals(test.getDistanceNauticalMiles(), 0, 1e-8);
}

@ -20,6 +20,15 @@ public class XMLMessage extends AC35Data {
public static int XMLTypeRace = 6;
public static int XMLTypeBoat = 7;
/**
* Constructor for an XML Message
* @param ackNumber Number for acknowledgement inherited for the AC35Data Packet
* @param timeStamp Time received
* @param xmlMsgSubType Type of XML message
* @param sequenceNumber Order that it has arrived in
* @param xmlMsgLength Length of the xml message
* @param xmlMessage XML message
*/
public XMLMessage(int ackNumber, long timeStamp, int xmlMsgSubType, int sequenceNumber, int xmlMsgLength, InputStream xmlMessage){
super(MessageType.XMLMESSAGE);
this.ackNumber = ackNumber;
@ -30,10 +39,18 @@ public class XMLMessage extends AC35Data {
this.xmlMessage = xmlMessage;
}
/**
* Get the XML Message
* @return the XML message as an input stream
*/
public InputStream getXmlMessage() {
return xmlMessage;
}
/**
* Get the type of message
* @return Gets the type of message the XML message is
*/
public int getXmlMsgSubType() {
return xmlMsgSubType;
}

@ -16,7 +16,7 @@ import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by cbt24 on 3/05/17.
* Controls the connection that the VIsualiser can connect to.
*/
public class ConnectionController extends Controller {
@FXML

@ -14,7 +14,7 @@ import java.util.ResourceBundle;
/**
* Created by zwu18 on 6/05/17.
* Finish Screen for when the race finishs.
*/
public class FinishController extends Controller {
@ -33,10 +33,10 @@ public class FinishController extends Controller {
@FXML
Label raceWinnerLabel;
/**
* Sets up the finish table
* @param boats Boats to display
*/
private void setFinishTable(ObservableList<Boat> boats){
boatInfoTable.setItems(boats);
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
@ -52,6 +52,10 @@ public class FinishController extends Controller {
public void initialize(URL location, ResourceBundle resources){
}
/**
* Display the table
* @param boats boats to display on the table.
*/
public void enterFinish(ObservableList<Boat> boats){
finishWrapper.setVisible(true);
setFinishTable(boats);

@ -12,7 +12,7 @@ import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by fwy13 on 15/03/2017.
* Controller that everything is overlayed onto. This makes it so that changing scenes does not resize your stage.
*/
public class MainController extends Controller {
@FXML private StartController startController;

@ -27,34 +27,57 @@ public class RaceController extends Controller {
//user saved data for annotation display
private ArrayList<Boolean> presetAnno;
private Map<String, Boolean> importantAnno;
private Map<String, Boolean> annoShownBeforeHide;
private int buttonChecked;//button currently checked allows the checkboxes to know whether or not to put it's state in history (if not hidden then store)
private int prevBtnChecked;//button to keep track of previous pressed button incase we want to check a checkbox straight from hidden we do not wish for all previous to come on.
private static String nameCheckAnno = "name";
private static String abbrevCheckAnno = "abbrev";
private static String speedCheckAnno = "speed";
private static String pathCheckAnno = "path";
private static String timeCheckAnno = "time";
private static int noBtn = 0;
private static int hideBtn = 1;
private static int showBtn = 2;
private static int partialBtn = 3;
private static int importantBtn = 4;
private ArrayList<Boat> startBoats;
private Integer sparkLineNumber = 0;
private ResizableRaceCanvas raceMap;
private ResizableRaceMap raceBoundaries;
private ToggleGroup annotationGroup;
private ArrayList<String> colours;
private Map<Integer, String> boatColours = new HashMap<>();
private int legNum;
private RaceClock raceClock;
@FXML Pane arrow;
@FXML SplitPane race;
@FXML StackPane arrowPane;
@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 CheckBox showTime;
@FXML Label timer;
@FXML Label FPS;
@FXML Label timeZone;
@FXML Button saveAnno;
@FXML Button showSetAnno;
@FXML TableView<Boat> boatInfoTable;
@FXML TableColumn<Boat, String> boatPlacingColumn;
@FXML TableColumn<Boat, String> boatTeamColumn;
@FXML TableColumn<Boat, String> boatMarkColumn;
@FXML TableColumn<Boat, String> boatSpeedColumn;
@FXML RadioButton hideAnnoRBTN;
@FXML RadioButton showAnnoRBTN;
@FXML RadioButton partialAnnoRBTN;
@FXML RadioButton importantAnnoRBTN;
@FXML LineChart<Number, Number> sparklineChart;
@FXML NumberAxis xAxis;
@FXML NumberAxis yAxis;
@ -101,6 +124,12 @@ public class RaceController extends Controller {
FPS.setVisible(false);
}
});
//adds all radios buttons for annotations to a group
annotationGroup = new ToggleGroup();
hideAnnoRBTN.setToggleGroup(annotationGroup);
showAnnoRBTN.setToggleGroup(annotationGroup);
partialAnnoRBTN.setToggleGroup(annotationGroup);
importantAnnoRBTN.setToggleGroup(annotationGroup);
}
/**
@ -217,21 +246,15 @@ public class RaceController extends Controller {
new Thread((newRace)).start();
}
/**
* Finish Race View
* @param boats boats there are in the race.
*/
public void finishRace(ObservableList<Boat> boats){
race.setVisible(false);
parent.enterFinish(boats);
}
/**
* 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
*
@ -326,39 +349,123 @@ public class RaceController extends Controller {
}
}
private void storeCurrentAnnotationState(){
annoShownBeforeHide.put(nameCheckAnno, showName.isSelected());
annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected());
annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected());
annoShownBeforeHide.put(speedCheckAnno, showSpeed.isSelected());
annoShownBeforeHide.put(timeCheckAnno, showTime.isSelected());
}
/**
* 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();
});
importantAnno = new HashMap<>();
importantAnno.put(nameCheckAnno, false);
importantAnno.put(abbrevCheckAnno, false);
importantAnno.put(pathCheckAnno, false);
importantAnno.put(speedCheckAnno, false);
importantAnno.put(timeCheckAnno, true);
annoShownBeforeHide = new HashMap<>();
annoShownBeforeHide.put(nameCheckAnno, true);
annoShownBeforeHide.put(abbrevCheckAnno, true);
annoShownBeforeHide.put(pathCheckAnno, true);
annoShownBeforeHide.put(speedCheckAnno, true);
annoShownBeforeHide.put(timeCheckAnno, true);
//listener for show name in annotation
showName.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleAnnoName();
if (old_val != new_val) {
raceMap.toggleAnnoName();
}
if (buttonChecked != hideBtn) {
//if we are checking the box straight out of hide instead of using the radio buttons
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(nameCheckAnno, showName.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
});
//listener for show abbreviation for annotation
showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleAnnoAbbrev();
if (old_val != new_val) {
raceMap.toggleAnnoAbbrev();
}
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(abbrevCheckAnno, showAbbrev.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
});
//listener for show boat path for annotation
showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleBoatPath();
if (old_val != new_val) {
raceMap.toggleBoatPath();
}
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(pathCheckAnno, showBoatPath.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
});
//listener to show speed for annotation
showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleAnnoSpeed();
if (old_val != new_val) {
raceMap.toggleAnnoSpeed();
}
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(speedCheckAnno, showSpeed.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
raceMap.update();
prevBtnChecked = noBtn;
});
showTime.selectedProperty().addListener((ov, old_val, new_val) -> {
raceMap.toggleAnnoTime();
if (old_val != new_val) {
raceMap.toggleAnnoTime();
}
if (buttonChecked != hideBtn) {
if (prevBtnChecked == hideBtn && buttonChecked != showBtn){
storeCurrentAnnotationState();
} else {
annoShownBeforeHide.put(timeCheckAnno, showTime.isSelected());
}
if (buttonChecked == noBtn) {
annotationGroup.selectToggle(showAnnoRBTN);
}
}
prevBtnChecked = noBtn;
raceMap.update();
});
//listener to save currently selected annotation
@ -370,17 +477,61 @@ public class RaceController extends Controller {
presetAnno.add(showBoatPath.isSelected());
presetAnno.add(showTime.isSelected());
});
//listener to show saved annotation
showSetAnno.setOnAction(event -> {
//listener for hiding
hideAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
buttonChecked = hideBtn;
//raceMap.hideAnnotations();
showName.setSelected(false);
showAbbrev.setSelected(false);
showBoatPath.setSelected(false);
showSpeed.setSelected(false);
showTime.setSelected(false);
annotationGroup.selectToggle(hideAnnoRBTN);
raceMap.update();
buttonChecked = noBtn;
prevBtnChecked = hideBtn;
});
//listener for showing all annotations
showAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
buttonChecked = showBtn;
showName.setSelected(annoShownBeforeHide.get(nameCheckAnno));
showAbbrev.setSelected(annoShownBeforeHide.get(abbrevCheckAnno));
showBoatPath.setSelected(annoShownBeforeHide.get(pathCheckAnno));
showSpeed.setSelected(annoShownBeforeHide.get(speedCheckAnno));
showTime.setSelected(annoShownBeforeHide.get(timeCheckAnno));
raceMap.update();
buttonChecked = noBtn;
prevBtnChecked = showBtn;
});
//listener for showing all important
partialAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
buttonChecked = partialBtn;
showName.setSelected(false);
showAbbrev.setSelected(true);
showSpeed.setSelected(true);
showBoatPath.setSelected(false);
showTime.setSelected(false);
annotationGroup.selectToggle(partialAnnoRBTN);
raceMap.update();
buttonChecked = noBtn;
prevBtnChecked = partialBtn;
});
//listener for showing all important
importantAnnoRBTN.selectedProperty().addListener((ov, old_val, new_val) ->{
buttonChecked = importantBtn;
if (presetAnno.size() > 0) {
showName.setSelected(presetAnno.get(0));
showAbbrev.setSelected(presetAnno.get(1));
showSpeed.setSelected(presetAnno.get(2));
showBoatPath.setSelected(presetAnno.get(3));
showTime.setSelected(presetAnno.get(4));
annotationGroup.selectToggle(importantAnnoRBTN);
raceMap.update();
}
buttonChecked = noBtn;
prevBtnChecked = importantBtn;
});
annotationGroup.selectToggle(showAnnoRBTN);
}
private String colourToHex(Color color) {

@ -26,7 +26,7 @@ import java.util.Observer;
import java.util.ResourceBundle;
/**
* Created by esa46 on 6/04/17.
* Controller to for waiting for the race to start
*/
public class StartController extends Controller implements Observer {
@ -76,6 +76,9 @@ public class StartController extends Controller implements Observer {
return startWrapper;
}
/**
* Initiliases the tables that are to be shown on the pane
*/
private void initialiseTables() {
List<Boat> boats = raceData.getBoats();
ObservableList<Boat> observableBoats = FXCollections.observableArrayList(boats);
@ -107,6 +110,9 @@ public class StartController extends Controller implements Observer {
}.start();
}
/**
* Sets the clock that displays the time of at the current race venue.
*/
private void setRaceClock() {
raceClock = new RaceClock(raceData.getZonedDateTime());
@ -120,6 +126,9 @@ public class StartController extends Controller implements Observer {
raceClock.run();
}
/**
* Sets the time that the race is going to start.
*/
private void setStartingTime() {
String dateFormat = "'Starting time:' HH:mm dd/MM/YYYY";
Platform.runLater(()-> {
@ -135,6 +144,9 @@ public class StartController extends Controller implements Observer {
});
}
/**
* set the current time, may be used to update the time on the clock.
*/
private void setCurrentTime() {
Platform.runLater(()->
raceClock.setUTCTime(visualiserInput.getRaceStatus().getCurrentTime())

@ -15,7 +15,7 @@ import java.util.List;
import java.util.Map;
/**
* Created by Joseph on 24/04/2017.
* XML Read that reads the Boats that are goign to participate in the Race
*/
public class BoatXMLReader extends XMLReader {
private final Map<Integer, StreamedBoat> streamedBoatMap = new HashMap<>();
@ -139,6 +139,10 @@ public class BoatXMLReader extends XMLReader {
// TODO Get relative point before implementing. (GPSposition is based off a relative point).
}
/**
* Sets the participants
* @param participants boats participating the race mapped by their source ID's
*/
public void setParticipants(Map<Integer, StreamedBoat> participants) {
this.participants = participants;
}

@ -52,6 +52,13 @@ public class RegattaXMLReader extends XMLReader {
}
}
/**
* Alternate Constructor that takes in an inputstream instead
* @param xmlString Input stream of the XML
* @throws IOException Error with input
* @throws SAXException Error with XML Format
* @throws ParserConfigurationException Error with XMl contents
*/
public RegattaXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException {
super(xmlString);
read();
@ -66,6 +73,10 @@ public class RegattaXMLReader extends XMLReader {
makeRegatta(attributes);
}
/**
* Extracts the information from the attributes
* @param attributes attributes to extract information form.
*/
private void makeRegatta(Element attributes) {
this.regattaID = Integer.parseInt(getTextValueOfNode(attributes, "RegattaID"));
this.regattaName = getTextValueOfNode(attributes, "RegattaName");

@ -3,7 +3,7 @@ package seng302.Mock;
import seng302.Model.Boat;
/**
* Created by Joseph on 24/04/2017.
* Boats that are been received.
*/
public class StreamedBoat extends Boat {
private final int sourceID;
@ -13,6 +13,12 @@ public class StreamedBoat extends Boat {
this.velocity = 0;
}
/**
* COnstructor
* @param sourceID ID of the BOat
* @param name Name of the Boat
* @param abbrev Boat's name shortened.
*/
public StreamedBoat(int sourceID, String name, String abbrev) {
super(name, abbrev);
this.sourceID = sourceID;
@ -20,9 +26,7 @@ public class StreamedBoat extends Boat {
}
public StreamedBoat(int sourceID) {
super("None", "None");
this.sourceID = sourceID;
this.init();
this(sourceID, "None", "None");
}
public int getSourceID() {

@ -11,7 +11,7 @@ import java.util.List;
import java.util.Observable;
/**
* Created by jjg64 on 21/04/17.
* COurse that the is being received.
*/
public class StreamedCourse extends Observable implements RaceDataSource {
private StreamedCourseXMLReader streamedCourseXMLReader = null;
@ -21,6 +21,10 @@ public class StreamedCourse extends Observable implements RaceDataSource {
public StreamedCourse() {}
/**
* Read and set the new XML that has been received.
* @param boatXMLReader new XMl of the boats.
*/
public void setBoatXMLReader(BoatXMLReader boatXMLReader) {
this.boatXMLReader = boatXMLReader;
if (streamedCourseXMLReader != null && boatXMLReader != null) {
@ -36,6 +40,10 @@ public class StreamedCourse extends Observable implements RaceDataSource {
return streamedCourseXMLReader;
}
/**
* Read and sets the new Course that has been received
* @param streamedCourseXMLReader COurse XML that has been received
*/
public void setStreamedCourseXMLReader(StreamedCourseXMLReader streamedCourseXMLReader) {
this.streamedCourseXMLReader = streamedCourseXMLReader;
if (streamedCourseXMLReader != null && boatXMLReader != null) {
@ -44,6 +52,10 @@ public class StreamedCourse extends Observable implements RaceDataSource {
}
}
/**
* Reads and sets the new Regatta that has been received
* @param regattaXMLReader Regatta XMl that has been received.
*/
public void setRegattaXMLReader(RegattaXMLReader regattaXMLReader) {
this.regattaXMLReader = regattaXMLReader;
setChanged();

@ -18,7 +18,7 @@ import java.time.format.DateTimeFormatter;
import java.util.*;
/**
* Created by jjg64 on 21/04/17.
* XML Read for the Course that is being received
*/
public class StreamedCourseXMLReader extends XMLReader {
private static final double COORDINATEPADDING = 0.000;
@ -95,6 +95,9 @@ public class StreamedCourseXMLReader extends XMLReader {
postpone = Boolean.parseBoolean(raceTimeTag.getNamedItem("Postpone").getTextContent());
}
/**
* Reads the participants of the race.
*/
private void readParticipants() {
Element nParticipants = (Element) doc.getElementsByTagName("Participants").item(0);
nParticipants.getChildNodes().getLength();
@ -159,12 +162,22 @@ public class StreamedCourseXMLReader extends XMLReader {
return marker;
}
/**
* Extracts the GPS Coordinates from a XMl Element
* @param mark Element to Extract from
* @return the GPS coordinate that it reflects
*/
private GPSCoordinate getCoordinate(Element mark) {
double lat = Double.parseDouble(mark.getAttribute("TargetLat"));
double lon = Double.parseDouble(mark.getAttribute("TargetLng"));
return new GPSCoordinate(lat,lon);
}
/**
* Extracts the SourceID from a XML ELement
* @param mark Element to Extract from
* @return the Source ID of the Extracted Element.
*/
private int getSourceId(Element mark) {
String sourceId = mark.getAttribute("SourceID");
if (sourceId.isEmpty()){
@ -210,6 +223,9 @@ public class StreamedCourseXMLReader extends XMLReader {
}
}
/**
* Reads the course boundary limitations of the course recieved.
*/
private void readCourseLimit() {
Element nCourseLimit = (Element) doc.getElementsByTagName("CourseLimit").item(0);
for(int i = 0; i < nCourseLimit.getChildNodes().getLength(); i++) {

@ -18,7 +18,7 @@ import seng302.VisualiserInput;
import java.util.List;
/**
* Created by jjg64 on 21/04/17.
* The Class used to view the race streamed.
*/
public class StreamedRace implements Runnable {
private final VisualiserInput visualiserInput;
@ -196,28 +196,21 @@ public class StreamedRace implements Runnable {
@Override
public void handle(long arg0) {
if (boatsFinished < startingBoats.size()) {
boatsFinished = 0;
//controller.updateSparkline(startingBoats);
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
for (Boat boat : startingBoats) {
if (boat != null && !boat.isFinished()) {
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
checkPosition(boat, totalTimeElapsed);
}
if (boat.isFinished()){
boatsFinished++;
}
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
for (Boat boat : startingBoats) {
if (boat != null && !boat.isFinished()) {
updatePosition(boat, Math.round(1000 / lastFPS) > 20 ? 15 : Math.round(1000 / lastFPS));
checkPosition(boat, totalTimeElapsed);
}
for (Marker mark: boatMarkers){
if (mark != null){
updateMarker(mark);
}
}
for (Marker mark: boatMarkers){
if (mark != null){
updateMarker(mark);
}
//System.out.println(boatsFinished + ":" + startingBoats.size());
} else {
}
//System.out.println(boatsFinished + ":" + startingBoats.size());
if (visualiserInput.getRaceStatus().isFinished()){
controller.finishRace(startingBoats);
stop();
}

@ -27,7 +27,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
private RaceMap map;
private List<Boat> boats;
private List<Marker> boatMarkers;
private boolean raceAnno = true;
private boolean annoName = true;
private boolean annoAbbrev = true;
private boolean annoSpeed = true;
@ -263,12 +262,6 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
}
/**
* Toggle the raceAnno value
*/
public void toggleAnnotations() {
raceAnno = !raceAnno;
}
/**
* Toggle name display in annotation
@ -324,14 +317,12 @@ public class ResizableRaceCanvas extends ResizableCanvas {
displayBoat(boat, 0, boatColours.get(sourceID));
}
if (raceAnno) {
if (Duration.between(boat.getTimeSinceLastMark(), raceClock.getTime()).getSeconds() < 0) {
boat.setTimeSinceLastMark(raceClock.getTime());
}
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()), boat.getTimeSinceLastMark());
//TODO this needs to be fixed.
drawTrack(boat, boatColours.get(sourceID));
if (Duration.between(boat.getTimeSinceLastMark(), raceClock.getTime()).getSeconds() < 0) {
boat.setTimeSinceLastMark(raceClock.getTime());
}
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()), boat.getTimeSinceLastMark());
//TODO this needs to be fixed.
drawTrack(boat, boatColours.get(sourceID));
}
}
}
@ -343,7 +334,7 @@ public class ResizableRaceCanvas extends ResizableCanvas {
* @see seng302.Model.TrackPoint
*/
private void drawTrack(Boat boat, Color colour) {
if (annoPath && raceAnno) {
if (annoPath) {
for (TrackPoint point : boat.getTrack()) {
GraphCoordinate scaledCoordinate = this.map.convertGPS(point.getCoordinate());
gc.setFill(new Color(colour.getRed(), colour.getGreen(), colour.getBlue(), point.getAlpha()));
@ -352,6 +343,9 @@ public class ResizableRaceCanvas extends ResizableCanvas {
}
}
/**
* makes colours
*/
private void makeColours() {
colours = new ArrayList<>(Arrays.asList(
Color.BLUEVIOLET,

@ -17,6 +17,10 @@ public class ResizableRaceMap extends ResizableCanvas {
private double[] xpoints = {};
private double[] ypoints = {};
/**
* Constructor
* @param raceData Race which it is taking its information to be displayed from
*/
public ResizableRaceMap(RaceDataSource raceData){
super();
raceBoundaries = raceData.getBoundary();
@ -29,9 +33,14 @@ public class ResizableRaceMap extends ResizableCanvas {
//draw();
}
/**
* Sets the map race that it is auppost to be viewing.
* @param map
*/
private void setMap(RaceMap map) {
this.map = map;
}
/**
* Draw boundary of the race.
*/
@ -46,6 +55,9 @@ public class ResizableRaceMap extends ResizableCanvas {
gc.fillPolygon(xpoints, ypoints, xpoints.length);
}
/**
* Sets the coordinately of the race boundaries
*/
private void setRaceBoundCoordinates() {
xpoints = new double[this.raceBoundaries.size()];
ypoints = new double[this.raceBoundaries.size()];
@ -56,6 +68,9 @@ public class ResizableRaceMap extends ResizableCanvas {
}
}
/**
* Draw update for the canvas
*/
public void draw(){
double width = getWidth();

@ -26,16 +26,20 @@
<panes>
<TitledPane animated="false" text="Annotation Control">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="240.0" prefWidth="200.0">
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<CheckBox fx:id="showBoatPath" mnemonicParsing="false" selected="true" text="Show Boat Paths" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="104.0" />
<CheckBox fx:id="showAnnotations" layoutX="-2.0" layoutY="14.0" mnemonicParsing="false" selected="true" text="Show Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<CheckBox fx:id="showName" layoutY="39.0" mnemonicParsing="false" selected="true" text="Show Boat Name" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="26.0" />
<CheckBox fx:id="showAbbrev" layoutY="61.0" mnemonicParsing="false" selected="true" text="Show Boat Abbreviation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="52.0" />
<CheckBox fx:id="showSpeed" layoutY="90.0" mnemonicParsing="false" selected="true" text="Show Boat Speed" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="78.0" />
<CheckBox fx:id="showTime" mnemonicParsing="false" selected="true" text="Show Boat Leg Time" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="130.0" />
<Button fx:id="saveAnno" layoutX="11.0" layoutY="106.0" maxWidth="154.0" mnemonicParsing="false" prefWidth="154.0" text="Save Annotation" AnchorPane.topAnchor="160.0" />
<Button fx:id="showSetAnno" layoutX="11.0" layoutY="139.0" mnemonicParsing="false" text="Show Set Annotation" AnchorPane.topAnchor="190.0" />
<CheckBox fx:id="showName" layoutY="39.0" mnemonicParsing="false" selected="true" text="Show Boat Name" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<CheckBox fx:id="showAbbrev" layoutY="61.0" mnemonicParsing="false" selected="true" text="Show Boat Abbreviation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="25.0" />
<CheckBox fx:id="showSpeed" layoutY="90.0" mnemonicParsing="false" selected="true" text="Show Boat Speed" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="50.0" />
<CheckBox fx:id="showBoatPath" mnemonicParsing="false" selected="true" text="Show Boat Paths" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="75.0" />
<CheckBox fx:id="showTime" mnemonicParsing="false" selected="true" text="Show Boat Leg Time" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="100.0" />
<Separator prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="125.0" />
<Label text="Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="130.0" />
<RadioButton fx:id="hideAnnoRBTN" mnemonicParsing="false" text="Hidden" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="155.0" />
<RadioButton fx:id="showAnnoRBTN" mnemonicParsing="false" text="Visible" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="180.0" />
<RadioButton fx:id="partialAnnoRBTN" mnemonicParsing="false" text="Partial" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="205.0" />
<RadioButton fx:id="importantAnnoRBTN" mnemonicParsing="false" text="Important" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="230.0" />
<Button fx:id="saveAnno" layoutX="11.0" layoutY="106.0" maxWidth="154.0" mnemonicParsing="false" prefWidth="154.0" text="Save Important Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="255.0" />
</children>
</AnchorPane>
</content>

Loading…
Cancel
Save