diff --git a/mock/src/main/java/seng302/App.java b/mock/src/main/java/seng302/App.java index 3f1dd06d..2b0f31a3 100644 --- a/mock/src/main/java/seng302/App.java +++ b/mock/src/main/java/seng302/App.java @@ -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)); diff --git a/mock/src/main/java/seng302/DataInput/BoatDataSource.java b/mock/src/main/java/seng302/DataInput/BoatDataSource.java index d8ecfaf2..5b9eb411 100644 --- a/mock/src/main/java/seng302/DataInput/BoatDataSource.java +++ b/mock/src/main/java/seng302/DataInput/BoatDataSource.java @@ -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 getBoats(); diff --git a/mock/src/main/java/seng302/DataInput/BoatXMLReader.java b/mock/src/main/java/seng302/DataInput/BoatXMLReader.java index ab87967c..f3494f55 100644 --- a/mock/src/main/java/seng302/DataInput/BoatXMLReader.java +++ b/mock/src/main/java/seng302/DataInput/BoatXMLReader.java @@ -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 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 getMarkerBoats() { return markerMap; diff --git a/mock/src/main/java/seng302/DataInput/RaceDataSource.java b/mock/src/main/java/seng302/DataInput/RaceDataSource.java index f82b4e63..4de386f9 100644 --- a/mock/src/main/java/seng302/DataInput/RaceDataSource.java +++ b/mock/src/main/java/seng302/DataInput/RaceDataSource.java @@ -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 getBoats(); diff --git a/mock/src/main/java/seng302/DataInput/RaceXMLReader.java b/mock/src/main/java/seng302/DataInput/RaceXMLReader.java index 1488988c..7e7a0546 100644 --- a/mock/src/main/java/seng302/DataInput/RaceXMLReader.java +++ b/mock/src/main/java/seng302/DataInput/RaceXMLReader.java @@ -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++) { diff --git a/mock/src/main/java/seng302/DataInput/XMLReader.java b/mock/src/main/java/seng302/DataInput/XMLReader.java index 1e860cec..c01891e3 100644 --- a/mock/src/main/java/seng302/DataInput/XMLReader.java +++ b/mock/src/main/java/seng302/DataInput/XMLReader.java @@ -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); diff --git a/mock/src/main/java/seng302/MockOutput.java b/mock/src/main/java/seng302/MockOutput.java index cf48cdbd..4bb23af1 100644 --- a/mock/src/main/java/seng302/MockOutput.java +++ b/mock/src/main/java/seng302/MockOutput.java @@ -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; } diff --git a/mock/src/main/java/seng302/Model/Boat.java b/mock/src/main/java/seng302/Model/Boat.java index 9c3eb895..7e9fc9b6 100644 --- a/mock/src/main/java/seng302/Model/Boat.java +++ b/mock/src/main/java/seng302/Model/Boat.java @@ -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 { /** diff --git a/mock/src/main/java/seng302/Model/Event.java b/mock/src/main/java/seng302/Model/Event.java index cce144ee..27f8b1a9 100644 --- a/mock/src/main/java/seng302/Model/Event.java +++ b/mock/src/main/java/seng302/Model/Event.java @@ -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 { diff --git a/mock/src/main/java/seng302/Model/Leg.java b/mock/src/main/java/seng302/Model/Leg.java index 8e784164..10034efe 100644 --- a/mock/src/main/java/seng302/Model/Leg.java +++ b/mock/src/main/java/seng302/Model/Leg.java @@ -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 { diff --git a/mock/src/main/java/seng302/Model/Marker.java b/mock/src/main/java/seng302/Model/Marker.java new file mode 100644 index 00000000..e69de29b diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index ed6c5a4d..6f7e86fa 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -379,7 +379,7 @@ public class Race implements Runnable { } else { //Otherwise, the race is over! - + raceFinished.start(); setRaceStatusEnum(RaceStatusEnum.FINISHED); this.stop(); } @@ -402,6 +402,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. @@ -621,7 +637,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. diff --git a/mock/src/test/java/seng302/Model/LegTest.java b/mock/src/test/java/seng302/Model/LegTest.java index 06ac325b..cb8d70d4 100644 --- a/mock/src/test/java/seng302/Model/LegTest.java +++ b/mock/src/test/java/seng302/Model/LegTest.java @@ -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); } diff --git a/network/src/main/java/seng302/Networking/Messages/XMLMessage.java b/network/src/main/java/seng302/Networking/Messages/XMLMessage.java index b2d9b36b..856d4bc3 100644 --- a/network/src/main/java/seng302/Networking/Messages/XMLMessage.java +++ b/network/src/main/java/seng302/Networking/Messages/XMLMessage.java @@ -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; } diff --git a/visualiser/src/main/java/seng302/Controllers/ConnectionController.java b/visualiser/src/main/java/seng302/Controllers/ConnectionController.java index aed1806d..40437318 100644 --- a/visualiser/src/main/java/seng302/Controllers/ConnectionController.java +++ b/visualiser/src/main/java/seng302/Controllers/ConnectionController.java @@ -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 diff --git a/visualiser/src/main/java/seng302/Controllers/FinishController.java b/visualiser/src/main/java/seng302/Controllers/FinishController.java index e610827d..a5c32eee 100644 --- a/visualiser/src/main/java/seng302/Controllers/FinishController.java +++ b/visualiser/src/main/java/seng302/Controllers/FinishController.java @@ -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 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 boats){ finishWrapper.setVisible(true); setFinishTable(boats); diff --git a/visualiser/src/main/java/seng302/Controllers/MainController.java b/visualiser/src/main/java/seng302/Controllers/MainController.java index 3e29086b..2b908e45 100644 --- a/visualiser/src/main/java/seng302/Controllers/MainController.java +++ b/visualiser/src/main/java/seng302/Controllers/MainController.java @@ -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; diff --git a/visualiser/src/main/java/seng302/Controllers/RaceController.java b/visualiser/src/main/java/seng302/Controllers/RaceController.java index 43d12f64..3082b325 100644 --- a/visualiser/src/main/java/seng302/Controllers/RaceController.java +++ b/visualiser/src/main/java/seng302/Controllers/RaceController.java @@ -7,23 +7,17 @@ import javafx.fxml.FXML; import javafx.scene.chart.LineChart; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; -import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.layout.GridPane; -import javafx.scene.paint.Color; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; -import javafx.scene.paint.Paint; import seng302.Mock.StreamedRace; import seng302.Model.*; import seng302.VisualiserInput; import java.net.URL; import java.util.*; -import java.util.ArrayList; -import java.util.Locale; -import java.util.ResourceBundle; /** * Created by fwy13 on 15/03/2017. @@ -33,34 +27,57 @@ public class RaceController extends Controller { //user saved data for annotation display private ArrayList presetAnno; + private Map importantAnno; + private Map 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 startBoats; private Integer sparkLineNumber = 0; + private ResizableRaceCanvas raceMap; private ResizableRaceMap raceBoundaries; + private ToggleGroup annotationGroup; + private ArrayList colours; private Map 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 boatInfoTable; @FXML TableColumn boatPlacingColumn; @FXML TableColumn boatTeamColumn; @FXML TableColumn boatMarkColumn; @FXML TableColumn boatSpeedColumn; + @FXML RadioButton hideAnnoRBTN; + @FXML RadioButton showAnnoRBTN; + @FXML RadioButton partialAnnoRBTN; + @FXML RadioButton importantAnnoRBTN; @FXML LineChart sparklineChart; @FXML NumberAxis xAxis; @FXML NumberAxis yAxis; @@ -107,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); } /** @@ -223,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 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 * @@ -332,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 @@ -374,17 +475,63 @@ public class RaceController extends Controller { presetAnno.add(showAbbrev.isSelected()); presetAnno.add(showSpeed.isSelected()); presetAnno.add(showBoatPath.isSelected()); + presetAnno.add(showTime.isSelected()); + }); + //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 to show saved annotation - showSetAnno.setOnAction(event -> { + //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) { diff --git a/visualiser/src/main/java/seng302/Controllers/StartController.java b/visualiser/src/main/java/seng302/Controllers/StartController.java index 3004ab6c..87996f76 100644 --- a/visualiser/src/main/java/seng302/Controllers/StartController.java +++ b/visualiser/src/main/java/seng302/Controllers/StartController.java @@ -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 boats = raceData.getBoats(); ObservableList 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()) diff --git a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java index 7dc4a220..b7778c8e 100644 --- a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java @@ -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 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 participants) { this.participants = participants; } diff --git a/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java b/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java index bb52f148..76de49ad 100644 --- a/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/RegattaXMLReader.java @@ -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"); diff --git a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java index d5134cc0..3b2b2ee0 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedBoat.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedBoat.java @@ -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() { diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java index bcb4a90c..83c3d89f 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourse.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourse.java @@ -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(); diff --git a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java index 08124d3e..3e2f03f4 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedCourseXMLReader.java @@ -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++) { diff --git a/visualiser/src/main/java/seng302/Mock/StreamedRace.java b/visualiser/src/main/java/seng302/Mock/StreamedRace.java index 3b4d5f60..0b867f4d 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedRace.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedRace.java @@ -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(); } diff --git a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java index f3ba5262..5c26b293 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -27,7 +27,6 @@ public class ResizableRaceCanvas extends ResizableCanvas { private RaceMap map; private List boats; private List 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, diff --git a/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java b/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java index 7db9b132..4a2bed6f 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java +++ b/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java @@ -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(); diff --git a/visualiser/src/main/resources/scenes/race.fxml b/visualiser/src/main/resources/scenes/race.fxml index e21436f4..900b731d 100644 --- a/visualiser/src/main/resources/scenes/race.fxml +++ b/visualiser/src/main/resources/scenes/race.fxml @@ -26,16 +26,20 @@ - + - - - - - - -