diff --git a/mock/src/main/java/seng302/DataInput/PolarParser.java b/mock/src/main/java/seng302/DataInput/PolarParser.java index 59878edd..222cdbbf 100644 --- a/mock/src/main/java/seng302/DataInput/PolarParser.java +++ b/mock/src/main/java/seng302/DataInput/PolarParser.java @@ -1,9 +1,5 @@ package seng302.DataInput; -/** - * Created by hba56 on 10/05/17. - */ - import seng302.Exceptions.InvalidPolarFileException; import seng302.Model.Bearing; import seng302.Model.Polars; diff --git a/mock/src/main/java/seng302/DataInput/XMLReader.java b/mock/src/main/java/seng302/DataInput/XMLReader.java index a44b4183..d539539a 100644 --- a/mock/src/main/java/seng302/DataInput/XMLReader.java +++ b/mock/src/main/java/seng302/DataInput/XMLReader.java @@ -13,7 +13,6 @@ import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.IOException; -import java.io.InputStream; import java.io.StringReader; import java.io.StringWriter; diff --git a/mock/src/main/java/seng302/Exceptions/InvalidBoatDataException.java b/mock/src/main/java/seng302/Exceptions/InvalidBoatDataException.java index 98250e2a..693103b7 100644 --- a/mock/src/main/java/seng302/Exceptions/InvalidBoatDataException.java +++ b/mock/src/main/java/seng302/Exceptions/InvalidBoatDataException.java @@ -1,9 +1,5 @@ package seng302.Exceptions; -/** - * Created by f123 on 25-Apr-17. - */ - /** * An exception thrown when we cannot generate Boats.xml and send an XML message. */ diff --git a/mock/src/main/java/seng302/Exceptions/InvalidPolarFileException.java b/mock/src/main/java/seng302/Exceptions/InvalidPolarFileException.java index cc997c67..d2e302e7 100644 --- a/mock/src/main/java/seng302/Exceptions/InvalidPolarFileException.java +++ b/mock/src/main/java/seng302/Exceptions/InvalidPolarFileException.java @@ -1,9 +1,5 @@ package seng302.Exceptions; -/** - * Created by f123 on 10-May-17. - */ - /** * An exception thrown when we cannot parse a polar data file. */ diff --git a/mock/src/main/java/seng302/Exceptions/InvalidRaceDataException.java b/mock/src/main/java/seng302/Exceptions/InvalidRaceDataException.java index 11e4fcfc..2b99a549 100644 --- a/mock/src/main/java/seng302/Exceptions/InvalidRaceDataException.java +++ b/mock/src/main/java/seng302/Exceptions/InvalidRaceDataException.java @@ -1,9 +1,5 @@ package seng302.Exceptions; -/** - * Created by f123 on 25-Apr-17. - */ - /** * Exception thrown when we cannot generate Race.xml data, and send an XML message. */ diff --git a/mock/src/main/java/seng302/Model/GPSCoordinate.java b/mock/src/main/java/seng302/Model/GPSCoordinate.java index a185b865..2b80eb65 100644 --- a/mock/src/main/java/seng302/Model/GPSCoordinate.java +++ b/mock/src/main/java/seng302/Model/GPSCoordinate.java @@ -2,12 +2,10 @@ package seng302.Model; import javafx.util.Pair; import org.geotools.referencing.GeodeticCalculator; -import org.opengis.geometry.DirectPosition; import seng302.Constants; import java.awt.geom.Point2D; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; /** @@ -94,7 +92,7 @@ public class GPSCoordinate { /** * Calculates min and max values and passed it to calculate if coordinate is in the boundary * @param coordinate coordinate of interest - * @param boundary List of points which make a boundry + * @param boundary List of points which make a boundary * @return true if coordinate is in the boundary */ public static boolean isInsideBoundary(GPSCoordinate coordinate, List boundary) { @@ -141,7 +139,7 @@ public class GPSCoordinate { /** * Helper function to find if a point is in a boundary * @param boundaryA The first coordinate of the boundary. - * @param boundaryB The second coordinate of the bounary. + * @param boundaryB The second coordinate of the boundary. * @param coordinate The coordinate to test. * @return true if a line from the point intersects the two boundary points */ @@ -309,7 +307,7 @@ public class GPSCoordinate { List> shrunkEdges = new ArrayList<>(); - //We need to invert some of our opertations depending if the boundary is clockwise or anti-clockwise. + //We need to invert some of our operations depending if the boundary is clockwise or anti-clockwise. boolean isClockwise = GPSCoordinate.isClockwisePolygon(boundary); double clockwiseScaleFactor = 0; @@ -320,8 +318,8 @@ public class GPSCoordinate { } - /** - * Starting at a vertex, face anti-clockwise along an adjacent edge. + /* + Starting at a vertex, face anti-clockwise along an adjacent edge. Replace the edge with a new, parallel edge placed at distance d to the "left" of the old one. Repeat for all edges. Find the intersections of the new edges to get the new vertices. @@ -339,11 +337,11 @@ public class GPSCoordinate { Bearing bearing = GPSCoordinate.calculateBearing(firstPoint, secondPoint); //Calculate angle perpendicular to bearing. - Bearing perpindicularBearing = Bearing.fromDegrees(bearing.degrees() + (90d * clockwiseScaleFactor)); + Bearing perpendicularBearing = Bearing.fromDegrees(bearing.degrees() + (90d * clockwiseScaleFactor)); //Translate both first and second point by 50m, using this bearing. These form our inwards shifted edge. - GPSCoordinate firstPointTranslated = GPSCoordinate.calculateNewPosition(firstPoint, shrinkDistance, Azimuth.fromBearing(perpindicularBearing)); - GPSCoordinate secondPointTranslated = GPSCoordinate.calculateNewPosition(secondPoint, shrinkDistance, Azimuth.fromBearing(perpindicularBearing)); + GPSCoordinate firstPointTranslated = GPSCoordinate.calculateNewPosition(firstPoint, shrinkDistance, Azimuth.fromBearing(perpendicularBearing)); + GPSCoordinate secondPointTranslated = GPSCoordinate.calculateNewPosition(secondPoint, shrinkDistance, Azimuth.fromBearing(perpendicularBearing)); //Add edge to list. shrunkEdges.add(new Pair<>(firstPointTranslated, secondPointTranslated)); @@ -359,11 +357,11 @@ public class GPSCoordinate { Bearing bearing = GPSCoordinate.calculateBearing(firstPoint, secondPoint); //Calculate angle perpendicular to bearing. - Bearing perpindicularBearing = Bearing.fromDegrees(bearing.degrees() + (90d * clockwiseScaleFactor)); + Bearing perpendicularBearing = Bearing.fromDegrees(bearing.degrees() + (90d * clockwiseScaleFactor)); //Translate both first and second point by 50m, using this bearing. These form our inwards shifted edge. - GPSCoordinate firstPointTranslated = GPSCoordinate.calculateNewPosition(firstPoint, shrinkDistance, Azimuth.fromBearing(perpindicularBearing)); - GPSCoordinate secondPointTranslated = GPSCoordinate.calculateNewPosition(secondPoint, shrinkDistance, Azimuth.fromBearing(perpindicularBearing)); + GPSCoordinate firstPointTranslated = GPSCoordinate.calculateNewPosition(firstPoint, shrinkDistance, Azimuth.fromBearing(perpendicularBearing)); + GPSCoordinate secondPointTranslated = GPSCoordinate.calculateNewPosition(secondPoint, shrinkDistance, Azimuth.fromBearing(perpendicularBearing)); //Add edge to list. shrunkEdges.add(new Pair<>(firstPointTranslated, secondPointTranslated)); @@ -462,13 +460,13 @@ public class GPSCoordinate { /** * Determines if a list of coordinates describes a boundary polygon in clockwise or anti-clockwise order. - * @param boundary The list of coodinates. + * @param boundary The list of coordinates. * @return True if clockwise, false if anti-clockwise. */ public static boolean isClockwisePolygon(List boundary) { - /** From https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order - * sum all pairs (x2 − x1)(y2 + y1) + /* From https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order + sum all pairs (x2 − x1)(y2 + y1) point[0] = (5,0) edge[0]: (6-5)(4+0) = 4 point[1] = (6,4) edge[1]: (4-6)(5+4) = -18 point[2] = (4,5) edge[2]: (1-4)(5+5) = -30 diff --git a/mock/src/main/java/seng302/Model/Polars.java b/mock/src/main/java/seng302/Model/Polars.java index cf7d448d..dc770e8d 100644 --- a/mock/src/main/java/seng302/Model/Polars.java +++ b/mock/src/main/java/seng302/Model/Polars.java @@ -4,10 +4,6 @@ import javafx.util.Pair; import java.util.*; -/** - * Created by hba56 on 10/05/17. - */ - /** * Encapsulates an entire polar table. Has a function to calculate VMG. */ diff --git a/mock/src/main/java/seng302/Model/Race.java b/mock/src/main/java/seng302/Model/Race.java index 45bf2868..b42608a7 100644 --- a/mock/src/main/java/seng302/Model/Race.java +++ b/mock/src/main/java/seng302/Model/Race.java @@ -6,7 +6,6 @@ import javafx.collections.ObservableList; import seng302.Constants; import seng302.DataInput.RaceDataSource; import seng302.MockOutput; -import seng302.Networking.Messages.BoatLocation; import seng302.Networking.Messages.BoatStatus; import seng302.Networking.Messages.Enums.BoatStatusEnum; import seng302.Networking.Messages.Enums.RaceStatusEnum; diff --git a/mock/src/main/java/seng302/Model/VMG.java b/mock/src/main/java/seng302/Model/VMG.java index 67bc5297..b431ae06 100644 --- a/mock/src/main/java/seng302/Model/VMG.java +++ b/mock/src/main/java/seng302/Model/VMG.java @@ -1,9 +1,5 @@ package seng302.Model; -/** - * Created by f123 on 10-May-17. - */ - /** * This class encapsulates VMG - that is, velocity made good. It has a speed component and a bearing component. */ diff --git a/mock/src/test/java/seng302/DataInput/PolarParserTest.java b/mock/src/test/java/seng302/DataInput/PolarParserTest.java index 2974c1ad..b10adece 100644 --- a/mock/src/test/java/seng302/DataInput/PolarParserTest.java +++ b/mock/src/test/java/seng302/DataInput/PolarParserTest.java @@ -5,8 +5,6 @@ import org.testng.annotations.Test; import seng302.Exceptions.InvalidPolarFileException; import seng302.Model.Polars; -import java.io.File; - import static org.testng.Assert.*; /** @@ -15,8 +13,8 @@ import static org.testng.Assert.*; public class PolarParserTest { @Test - /** - * Tests if we can parse a polar data file (stored in a string), and create a polar table. + /* + Tests if we can parse a polar data file (stored in a string), and create a polar table. */ public void testParse() throws Exception { diff --git a/mock/src/test/java/seng302/Model/RaceTest.java b/mock/src/test/java/seng302/Model/RaceTest.java index f1bf440f..3151c2ea 100644 --- a/mock/src/test/java/seng302/Model/RaceTest.java +++ b/mock/src/test/java/seng302/Model/RaceTest.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import static org.junit.Assert.*; -import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; /** diff --git a/network/src/main/java/seng302/Networking/BinaryMessageDecoder.java b/network/src/main/java/seng302/Networking/BinaryMessageDecoder.java index 0e7eb8f6..1564bcd0 100644 --- a/network/src/main/java/seng302/Networking/BinaryMessageDecoder.java +++ b/network/src/main/java/seng302/Networking/BinaryMessageDecoder.java @@ -10,10 +10,6 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.zip.CRC32; -/** - * Created by hba56 on 21/04/17. - */ - /** * This class can be used to decode/convert a byte array into a messageBody object, descended from AC35Data. */ @@ -187,7 +183,7 @@ public class BinaryMessageDecoder { return mrDecoder.getMarkRounding(); case COURSEWIND: - //System.out.println("Couse Wind Message!"); + //System.out.println("Course Wind Message!"); CourseWindDecoder cwDecoder = new CourseWindDecoder(messageBody); return new CourseWinds(cwDecoder.getMessageVersionNumber(), cwDecoder.getByteWindID(), cwDecoder.getLoopMessages()); diff --git a/network/src/main/java/seng302/Networking/BinaryMessageEncoder.java b/network/src/main/java/seng302/Networking/BinaryMessageEncoder.java index 8a8d3db6..e0de7184 100644 --- a/network/src/main/java/seng302/Networking/BinaryMessageEncoder.java +++ b/network/src/main/java/seng302/Networking/BinaryMessageEncoder.java @@ -10,10 +10,6 @@ import static seng302.Networking.Utils.ByteConverter.intToBytes; import static seng302.Networking.Utils.ByteConverter.longToBytes; import static seng302.Networking.Utils.ByteConverter.shortToBytes; -/** - * Created by hba56 on 21/04/17. - */ - /** * This class can be used to encode/convert a byte array message body, plus header data into a byte array containing the entire message, ready to send. */ diff --git a/network/src/main/java/seng302/Networking/Exceptions/InvalidMessageException.java b/network/src/main/java/seng302/Networking/Exceptions/InvalidMessageException.java index 3296067e..0eb9e8f9 100644 --- a/network/src/main/java/seng302/Networking/Exceptions/InvalidMessageException.java +++ b/network/src/main/java/seng302/Networking/Exceptions/InvalidMessageException.java @@ -1,9 +1,5 @@ package seng302.Networking.Exceptions; -/** - * Created by f123 on 07-May-17. - */ - /** * Exception which is thrown when a message is read, but it is invalid in some way (CRC is wrong, sync bytes, etc...). */ diff --git a/network/src/main/java/seng302/Networking/MessageDecoders/RaceStartStatusDecoder.java b/network/src/main/java/seng302/Networking/MessageDecoders/RaceStartStatusDecoder.java index 81a924ed..eba1e565 100644 --- a/network/src/main/java/seng302/Networking/MessageDecoders/RaceStartStatusDecoder.java +++ b/network/src/main/java/seng302/Networking/MessageDecoders/RaceStartStatusDecoder.java @@ -2,9 +2,6 @@ package seng302.Networking.MessageDecoders; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; import java.util.Arrays; import static seng302.Networking.Utils.ByteConverter.*; diff --git a/network/src/main/java/seng302/Networking/MessageDecoders/XMLMessageDecoder.java b/network/src/main/java/seng302/Networking/MessageDecoders/XMLMessageDecoder.java index 9f2a6321..413ca359 100644 --- a/network/src/main/java/seng302/Networking/MessageDecoders/XMLMessageDecoder.java +++ b/network/src/main/java/seng302/Networking/MessageDecoders/XMLMessageDecoder.java @@ -1,12 +1,7 @@ package seng302.Networking.MessageDecoders; -import org.xml.sax.InputSource; - import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.io.StringReader; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.Arrays; diff --git a/network/src/main/java/seng302/Networking/MessageEncoders/XMLMessageEncoder.java b/network/src/main/java/seng302/Networking/MessageEncoders/XMLMessageEncoder.java index 526ee189..55c55375 100644 --- a/network/src/main/java/seng302/Networking/MessageEncoders/XMLMessageEncoder.java +++ b/network/src/main/java/seng302/Networking/MessageEncoders/XMLMessageEncoder.java @@ -1,8 +1,6 @@ package seng302.Networking.MessageEncoders; import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.Arrays; import static seng302.Networking.Utils.ByteConverter.intToBytes; import static seng302.Networking.Utils.ByteConverter.longToBytes; diff --git a/network/src/main/java/seng302/Networking/Messages/AC35Data.java b/network/src/main/java/seng302/Networking/Messages/AC35Data.java index 0291064d..a42a92be 100644 --- a/network/src/main/java/seng302/Networking/Messages/AC35Data.java +++ b/network/src/main/java/seng302/Networking/Messages/AC35Data.java @@ -1,10 +1,6 @@ package seng302.Networking.Messages; -/** - * Created by fwy13 on 25/04/17. - */ - import seng302.Networking.Messages.Enums.MessageType; /** diff --git a/network/src/main/java/seng302/Networking/Messages/BoatLocation.java b/network/src/main/java/seng302/Networking/Messages/BoatLocation.java index 9ebde2ef..85f9891e 100644 --- a/network/src/main/java/seng302/Networking/Messages/BoatLocation.java +++ b/network/src/main/java/seng302/Networking/Messages/BoatLocation.java @@ -1,12 +1,7 @@ package seng302.Networking.Messages; -/** - * Created by f123 on 21-Apr-17. - */ - -import SharedModel.Constants; -import seng302.Networking.Utils.AC35UnitConverter; import seng302.Networking.Messages.Enums.MessageType; +import seng302.Networking.Utils.AC35UnitConverter; import static seng302.Networking.Utils.AC35UnitConverter.convertGPS; import static seng302.Networking.Utils.AC35UnitConverter.convertGPSToInt; @@ -16,6 +11,9 @@ import static seng302.Networking.Utils.AC35UnitConverter.convertGPSToInt; */ public class BoatLocation extends AC35Data { + //Knots x this = meters per second. + public static final double KnotsToMetersPerSecondConversionFactor = + 0.514444; public static final byte Unknown = 0; public static final byte RacingYacht = 1; public static final byte CommitteeBoat = 2; @@ -266,7 +264,7 @@ public class BoatLocation extends AC35Data { */ public static int convertBoatSpeedDoubleToInt(double speed) { //Calculate meters per second. - double metersPerSecond = speed * Constants.KnotsToMetersPerSecondConversionFactor; + double metersPerSecond = speed * KnotsToMetersPerSecondConversionFactor; //Calculate millimeters per second. double millimetersPerSecond = metersPerSecond * 1000.0; @@ -288,7 +286,7 @@ public class BoatLocation extends AC35Data { double metersPerSecond = speed / 1000.0; //Calculate knots. - double knots = metersPerSecond / Constants.KnotsToMetersPerSecondConversionFactor; + double knots = metersPerSecond / KnotsToMetersPerSecondConversionFactor; return knots; } diff --git a/network/src/main/java/seng302/Networking/Messages/Enums/BoatStatusEnum.java b/network/src/main/java/seng302/Networking/Messages/Enums/BoatStatusEnum.java index 06b13fc4..8e8f06b2 100644 --- a/network/src/main/java/seng302/Networking/Messages/Enums/BoatStatusEnum.java +++ b/network/src/main/java/seng302/Networking/Messages/Enums/BoatStatusEnum.java @@ -3,10 +3,6 @@ package seng302.Networking.Messages.Enums; import java.util.HashMap; import java.util.Map; -/** - * Created by esa46 on 28/04/17. - */ - /** * Enumeration that encapsulates the various statuses a boat can have. */ @@ -46,8 +42,8 @@ public enum BoatStatusEnum { private static final Map byteToStatusMap = new HashMap<>(); - /** - * Static initialization block. Initializes the byteToStatusMap. + /* + Static initialization block. Initializes the byteToStatusMap. */ static { for (BoatStatusEnum type : BoatStatusEnum.values()) { diff --git a/network/src/main/java/seng302/Networking/Messages/Enums/MessageType.java b/network/src/main/java/seng302/Networking/Messages/Enums/MessageType.java index 22c38d4a..84ab6a0a 100644 --- a/network/src/main/java/seng302/Networking/Messages/Enums/MessageType.java +++ b/network/src/main/java/seng302/Networking/Messages/Enums/MessageType.java @@ -1,9 +1,5 @@ package seng302.Networking.Messages.Enums; -/** - * Created by hba56 on 21/04/17. - */ - import java.util.HashMap; import java.util.Map; @@ -49,8 +45,8 @@ public enum MessageType { private static final Map byteToTypeMap = new HashMap<>(); - /** - * Static initialization block. Initializes the byteToTypeMap. + /* + Static initialization block. Initializes the byteToTypeMap. */ static { for (MessageType type : MessageType.values()) { diff --git a/network/src/main/java/seng302/Networking/Messages/Enums/RaceStatusEnum.java b/network/src/main/java/seng302/Networking/Messages/Enums/RaceStatusEnum.java index 2563545d..3904eb58 100644 --- a/network/src/main/java/seng302/Networking/Messages/Enums/RaceStatusEnum.java +++ b/network/src/main/java/seng302/Networking/Messages/Enums/RaceStatusEnum.java @@ -76,8 +76,8 @@ public enum RaceStatusEnum { private static final Map byteToStatusMap = new HashMap<>(); - /** - * Static initialization block. Initializes the byteToStatusMap. + /* + Static initialization block. Initializes the byteToStatusMap. */ static { for (RaceStatusEnum type : RaceStatusEnum.values()) { diff --git a/network/src/main/java/seng302/Networking/Messages/Enums/RaceTypeEnum.java b/network/src/main/java/seng302/Networking/Messages/Enums/RaceTypeEnum.java index 01c1539e..57bfa0cf 100644 --- a/network/src/main/java/seng302/Networking/Messages/Enums/RaceTypeEnum.java +++ b/network/src/main/java/seng302/Networking/Messages/Enums/RaceTypeEnum.java @@ -54,8 +54,8 @@ public enum RaceTypeEnum { private static final Map byteToStatusMap = new HashMap<>(); - /** - * Static initialization block. Initializes the byteToStatusMap. + /* + Static initialization block. Initializes the byteToStatusMap. */ static { for (RaceTypeEnum type : RaceTypeEnum.values()) { diff --git a/network/src/main/java/seng302/Networking/Messages/Heartbeat.java b/network/src/main/java/seng302/Networking/Messages/Heartbeat.java index c54f2f08..3a8c960c 100644 --- a/network/src/main/java/seng302/Networking/Messages/Heartbeat.java +++ b/network/src/main/java/seng302/Networking/Messages/Heartbeat.java @@ -2,10 +2,6 @@ package seng302.Networking.Messages; import seng302.Networking.Messages.Enums.MessageType; -/** - * Created by fwy13 on 25/04/17. - */ - /** * Represents a Heartbeat message. */ diff --git a/network/src/main/java/seng302/Networking/Messages/RaceStatus.java b/network/src/main/java/seng302/Networking/Messages/RaceStatus.java index 55ec10ce..07125c6d 100644 --- a/network/src/main/java/seng302/Networking/Messages/RaceStatus.java +++ b/network/src/main/java/seng302/Networking/Messages/RaceStatus.java @@ -3,7 +3,6 @@ package seng302.Networking.Messages; import seng302.Networking.Messages.Enums.MessageType; import seng302.Networking.Utils.AC35UnitConverter; -import java.util.ArrayList; import java.util.List; /** diff --git a/network/src/main/java/seng302/Networking/PacketDump/AC35DumpReader.java b/network/src/main/java/seng302/Networking/PacketDump/AC35DumpReader.java index 97f0d821..2d8b48da 100644 --- a/network/src/main/java/seng302/Networking/PacketDump/AC35DumpReader.java +++ b/network/src/main/java/seng302/Networking/PacketDump/AC35DumpReader.java @@ -13,8 +13,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.zip.CRC32; -import java.util.zip.Checksum; /** * Created by fwy13 on 25/04/17. diff --git a/network/src/test/java/seng302/Networking/ByteConverterTest.java b/network/src/test/java/seng302/Networking/ByteConverterTest.java index a1390b59..fc59cc87 100644 --- a/network/src/test/java/seng302/Networking/ByteConverterTest.java +++ b/network/src/test/java/seng302/Networking/ByteConverterTest.java @@ -4,9 +4,7 @@ import org.junit.Test; import seng302.Networking.Utils.ByteConverter; import java.nio.ByteOrder; -import java.util.Arrays; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/network/src/test/java/seng302/Networking/MessageDecoders/XMLMessageDecoderTest.java b/network/src/test/java/seng302/Networking/MessageDecoders/XMLMessageDecoderTest.java index d63771dd..1b0a572e 100644 --- a/network/src/test/java/seng302/Networking/MessageDecoders/XMLMessageDecoderTest.java +++ b/network/src/test/java/seng302/Networking/MessageDecoders/XMLMessageDecoderTest.java @@ -7,7 +7,6 @@ import seng302.Networking.MessageEncoders.XMLMessageEncoder; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.io.Reader; /** * Created by hba56 on 20/04/17. diff --git a/sharedModel/src/main/java/SharedModel/Constants.java b/sharedModel/src/main/java/SharedModel/Constants.java deleted file mode 100644 index 935c5014..00000000 --- a/sharedModel/src/main/java/SharedModel/Constants.java +++ /dev/null @@ -1,13 +0,0 @@ -package SharedModel; - -/** - * Constants that are used throughout the program - * Created by Erika on 19-Mar-17. - */ -public class Constants { - //Knots x this = meters per second. - public static final double KnotsToMetersPerSecondConversionFactor = 0.514444; - - public static final double wakeScale = 10; - -} diff --git a/sharedModel/src/main/java/SharedModel/Regatta.java b/sharedModel/src/main/java/SharedModel/Regatta.java deleted file mode 100644 index 95db9f35..00000000 --- a/sharedModel/src/main/java/SharedModel/Regatta.java +++ /dev/null @@ -1,99 +0,0 @@ -package SharedModel; - -/** - * Created by jjg64 on 19/04/17. - */ -public class Regatta { - int regattaID; - String RegattaName; - int raceID = 0; - String courseName; - double centralLatitude; - double centralLongitude; - double centralAltitude; - float utcOffset; - float magneticVariation; - - public Regatta(int regattaID, String regattaName, String courseName, double centralLatitude, double centralLongitude, double centralAltitude, float utcOffset, float magneticVariation) { - this.regattaID = regattaID; - this.RegattaName = regattaName; - this.courseName = courseName; - this.centralLatitude = centralLatitude; - this.centralLongitude = centralLongitude; - this.centralAltitude = centralAltitude; - this.utcOffset = utcOffset; - this.magneticVariation = magneticVariation; - } - - public int getRegattaID() { - return regattaID; - } - - public void setRegattaID(int ID) { - this.regattaID = ID; - } - - public String getRegattaName() { - return RegattaName; - } - - public void setRegattaName(String regattaName) { - RegattaName = regattaName; - } - - public int getRaceID() { - return raceID; - } - - public void setRaceID(int raceID) { - this.raceID = raceID; - } - - public String getCourseName() { - return courseName; - } - - public void setCourseName(String courseName) { - this.courseName = courseName; - } - - public double getCentralLatitude() { - return centralLatitude; - } - - public void setCentralLatitude(double centralLatitude) { - this.centralLatitude = centralLatitude; - } - - public double getCentralLongitude() { - return centralLongitude; - } - - public void setCentralLongitude(double centralLongitude) { - this.centralLongitude = centralLongitude; - } - - public double getCentralAltitude() { - return centralAltitude; - } - - public void setCentralAltitude(double centralAltitude) { - this.centralAltitude = centralAltitude; - } - - public float getUtcOffset() { - return utcOffset; - } - - public void setUtcOffset(float utcOffset) { - this.utcOffset = utcOffset; - } - - public float getMagneticVariation() { - return magneticVariation; - } - - public void setMagneticVariation(float magneticVariation) { - this.magneticVariation = magneticVariation; - } -} diff --git a/visualiser/src/main/java/seng302/Controllers/ArrowController.java b/visualiser/src/main/java/seng302/Controllers/ArrowController.java deleted file mode 100644 index af2113b3..00000000 --- a/visualiser/src/main/java/seng302/Controllers/ArrowController.java +++ /dev/null @@ -1,17 +0,0 @@ -package seng302.Controllers; - -import javafx.fxml.FXML; -import javafx.scene.layout.Pane; - -import java.net.URL; -import java.util.ResourceBundle; - -/** - * Created by Joseph on 22/05/2017. - */ -public class ArrowController extends Controller { - - @Override - public void initialize(URL location, ResourceBundle resources) { - } -} diff --git a/visualiser/src/main/java/seng302/Controllers/RaceController.java b/visualiser/src/main/java/seng302/Controllers/RaceController.java index d36964a1..3d27586d 100644 --- a/visualiser/src/main/java/seng302/Controllers/RaceController.java +++ b/visualiser/src/main/java/seng302/Controllers/RaceController.java @@ -5,86 +5,45 @@ import javafx.application.Platform; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.chart.LineChart; -import javafx.scene.chart.NumberAxis; -import javafx.scene.chart.XYChart; import javafx.scene.control.*; +import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; -import javafx.scene.paint.Color; import seng302.Mock.StreamedRace; import seng302.Model.*; import seng302.VisualiserInput; import java.net.URL; -import java.util.*; +import java.util.ResourceBundle; /** * Created by fwy13 on 15/03/2017. */ public class RaceController extends Controller { - @FXML GridPane canvasBase; - - //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 boolean radioBtnChecked; - private boolean selectShow = false; //button to make it so that show doesn't run the listener - - 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 String estTimeCheckAnno = "est 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; + private Sparkline sparkline; + private int legNum; + + @FXML GridPane canvasBase; @FXML Pane arrow; @FXML SplitPane race; @FXML StackPane arrowPane; - @FXML CheckBox showFPS; - @FXML CheckBox showBoatPath; - @FXML CheckBox showName; - @FXML CheckBox showAbbrev; - @FXML CheckBox showSpeed; - @FXML CheckBox showTime; - @FXML CheckBox showEstTime; @FXML Label timer; @FXML Label FPS; @FXML Label timeZone; - @FXML Button saveAnno; + @FXML CheckBox showFPS; @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; + @FXML AnchorPane annotationPane; /** * Updates the ResizableRaceCanvas (raceMap) with most recent data @@ -107,8 +66,6 @@ public class RaceController extends Controller { * @param race Race to listen to. */ public void setInfoTable(StreamedRace race) { - //boatInfoTable.getItems().clear(); - ObservableList startingBoats = race.getStartingBoats(); boatInfoTable.setItems(race.getStartingBoats()); boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); boatSpeedColumn.setCellValueFactory(cellData -> cellData.getValue().getVelocityProp()); @@ -120,7 +77,6 @@ public class RaceController extends Controller { @Override public void initialize(URL location, ResourceBundle resources) { //listener for fps - startBoats = new ArrayList<>(); showFPS.selectedProperty().addListener((ov, old_val, new_val) -> { if (showFPS.isSelected()) { FPS.setVisible(true); @@ -128,70 +84,22 @@ 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); } /** * Creates and sets initial display for Sparkline for race positions. - * A data series for each boat in the race is added. - * Position numbers are displayed. - * * @param boats boats to display on the sparkline */ public void createSparkLine(ObservableList boats){ - // NOTE: Y axis is in negatives to display correct positions - - makeColours(); - startBoats.addAll(boats); - mapBoatColours(); - - // all boats start in 'last' place - for (int i=0; i series = new XYChart.Series(); - series.getData().add(new XYChart.Data(0, -startBoats.size())); - series.getData().add(new XYChart.Data(0, -startBoats.size())); - sparklineChart.getData().add(series); - sparklineChart.getData().get(i).getNode().setStyle("-fx-stroke: " + - ""+boatColours.get(startBoats.get(i).getSourceID())+";"); - } - - sparklineChart.setCreateSymbols(false); - - // set x axis details - xAxis.setAutoRanging(false); - xAxis.setTickMarkVisible(false); - xAxis.setTickLabelsVisible(false); - xAxis.setMinorTickVisible(false); - xAxis.setUpperBound((startBoats.size()+1)*legNum); - xAxis.setTickUnit((startBoats.size()+1)*legNum); - - - // set y axis details - yAxis.setLowerBound(-(startBoats.size()+1)); - yAxis.setUpperBound(0); - yAxis.setAutoRanging(false); - yAxis.setLabel("Position in Race"); - yAxis.setTickUnit(1); - yAxis.setTickMarkVisible(false); - yAxis.setMinorTickVisible(false); - // hide minus number from displaying on axis - yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) { - @Override - public String toString(Number value) { - if ((Double)value == 0.0 - || (Double)value < -startBoats.size()){ - return ""; - } - else { - return String.format("%7.0f", -value.doubleValue()); - } - } - }); + sparkline = new Sparkline(boats, legNum, sparklineChart); + } + + /** + * Updates the sparkline to display current boat positions. + * @param boatsInRace used for current boat positions. + */ + public void updateSparkline(ObservableList boatsInRace){ + sparkline.updateSparkline(boatsInRace); } /** @@ -203,7 +111,6 @@ public class RaceController extends Controller { */ public void startRace(VisualiserInput visualiserInput, RaceClock raceClock) { - //newRace.initialiseBoats(); legNum = visualiserInput.getCourse().getLegs().size()-1; makeArrow(); @@ -212,7 +119,6 @@ public class RaceController extends Controller { raceMap.setMouseTransparent(true); raceMap.widthProperty().bind(canvasBase.widthProperty()); raceMap.heightProperty().bind(canvasBase.heightProperty()); - //raceMap.setBoats(newRace.getStartingBoats()); raceMap.draw(); raceMap.setVisible(true); raceMap.setArrow(arrow.getChildren().get(0)); @@ -230,7 +136,6 @@ public class RaceController extends Controller { race.setVisible(true); - //Initialize save annotation array, fps listener, and annotation listeners timeZone.setText(raceClock.getTimeZone()); //RaceClock.duration isn't necessarily being changed in the javaFX thread, so we need to runlater the update. @@ -244,8 +149,11 @@ public class RaceController extends Controller { raceMap.setRaceClock(raceClock); StreamedRace newRace = new StreamedRace(visualiserInput, this); + initializeFPS(); - initializeAnnotations(); + + // set up annotation displays + new Annotations(annotationPane, raceMap); new Thread((newRace)).start(); } @@ -282,260 +190,6 @@ public class RaceController extends Controller { }); } - /** - * Updates the sparkline to display current boat positions. - * New points are plotted to represent each boat when required. - * - * @param boatsInRace used for current boat positions. - */ - public void updateSparkline(ObservableList boatsInRace){ - int placingVal = boatsInRace.size(); - sparkLineNumber++; - - for (int i = boatsInRace.size() - 1; i >= 0; i--){ - for (int j = startBoats.size() - 1; j >= 0; j--){ - if (boatsInRace.get(i)==startBoats.get(j)){ - - // when a boat is on its first leg - if (boatsInRace.get(i).getCurrentLeg().getLegNumber()==0){ - // adjust boats latest point on X axis - sparklineChart.getData().get(j).getData().get(1) - .setXValue(sparkLineNumber); - } - - // when a boat first enters its second leg - else if (boatsInRace.get(i).getCurrentLeg().getLegNumber - ()==1 && sparklineChart.getData().get(j).getData - ().size()==2){ - // adjust boats position from start mark - sparklineChart.getData().get(j).getData().get(1) - .setYValue(-placingVal); - sparklineChart.getData().get(j).getData().get(1) - .setXValue(sparkLineNumber); - sparklineChart.getData().get(j).getData().add(new XYChart.Data<> - (sparkLineNumber, -placingVal)); - } - - // plot new point for boats current position - else { - sparklineChart.getData().get(j).getData().add - (new XYChart.Data<>(sparkLineNumber, -placingVal)); - } - placingVal-=1; - } - } - } -// xAxis.setUpperBound(sparkLineNumber); -// xAxis.setTickUnit(sparkLineNumber); - } - - private void makeColours() { - colours = new ArrayList<>(Arrays.asList( - colourToHex(Color.BLUEVIOLET), - colourToHex(Color.BLACK), - colourToHex(Color.RED), - colourToHex(Color.ORANGE), - colourToHex(Color.DARKOLIVEGREEN), - colourToHex(Color.LIMEGREEN), - colourToHex(Color.PURPLE), - colourToHex(Color.DARKGRAY), - colourToHex(Color.YELLOW) - )); - } - - private void mapBoatColours() { - int currentColour = 0; - for (Boat boat : startBoats) { - if (!boatColours.containsKey(boat.getSourceID())) { - boatColours.put(boat.getSourceID(), colours.get(currentColour)); - } - currentColour = (currentColour + 1) % colours.size(); - } - } - - - private void storeCurrentAnnotationState(String dictionaryAnnotationKey, boolean selected){ - if (buttonChecked != hideBtn) { - //if we are checking the box straight out of hide instead of using the radio buttons - annoShownBeforeHide.put(dictionaryAnnotationKey, selected); - if (prevBtnChecked == hideBtn && buttonChecked == noBtn){ - storeCurrentAnnotationDictionary(); - } - if (buttonChecked == noBtn) { - selectShow = false; - annotationGroup.selectToggle(showAnnoRBTN); - } - } - } - - private void storeCurrentAnnotationDictionary(){ - 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()); - annoShownBeforeHide.put(estTimeCheckAnno, showEstTime.isSelected()); - } - - /** - * Set up boat annotations - */ - private void initializeAnnotations() { - presetAnno = new ArrayList<>(); - - importantAnno = new HashMap<>(); - importantAnno.put(nameCheckAnno, false); - importantAnno.put(abbrevCheckAnno, false); - importantAnno.put(pathCheckAnno, false); - importantAnno.put(speedCheckAnno, false); - importantAnno.put(timeCheckAnno, false); - importantAnno.put(estTimeCheckAnno, false); - - annoShownBeforeHide = new HashMap<>(); - annoShownBeforeHide.put(nameCheckAnno, true); - annoShownBeforeHide.put(abbrevCheckAnno, true); - annoShownBeforeHide.put(pathCheckAnno, true); - annoShownBeforeHide.put(speedCheckAnno, true); - annoShownBeforeHide.put(timeCheckAnno, true); - annoShownBeforeHide.put(estTimeCheckAnno, true); - //listener for show name in annotation - showName.selectedProperty().addListener((ov, old_val, new_val) -> { - if (old_val != new_val) { - raceMap.toggleAnnoName(); - radioBtnChecked = false; - storeCurrentAnnotationState(nameCheckAnno, new_val); - raceMap.update(); - } - }); - //listener for show abbreviation for annotation - showAbbrev.selectedProperty().addListener((ov, old_val, new_val) -> { - if (old_val != new_val) { - raceMap.toggleAnnoAbbrev(); - radioBtnChecked = false; - storeCurrentAnnotationState(abbrevCheckAnno, new_val); - raceMap.update(); - } - }); - - //listener for show boat path for annotation - showBoatPath.selectedProperty().addListener((ov, old_val, new_val) -> { - if (old_val != new_val) { - raceMap.toggleBoatPath(); - radioBtnChecked = false; - storeCurrentAnnotationState(pathCheckAnno, new_val); - raceMap.update(); - } - }); - //listener to show speed for annotation - showSpeed.selectedProperty().addListener((ov, old_val, new_val) -> { - if (old_val != new_val) { - raceMap.toggleAnnoSpeed(); - radioBtnChecked = false; - storeCurrentAnnotationState(speedCheckAnno, new_val); - raceMap.update(); - } - }); - showTime.selectedProperty().addListener((ov, old_val, new_val) -> { - if (old_val != new_val) { - raceMap.toggleAnnoTime(); - radioBtnChecked = false; - storeCurrentAnnotationState(timeCheckAnno, new_val); - raceMap.update(); - } - }); - showEstTime.selectedProperty().addListener((ov, old_val, new_val) -> { - if (old_val != new_val) { - raceMap.toggleAnnoEstTime(); - radioBtnChecked = false; - storeCurrentAnnotationState(estTimeCheckAnno, new_val); - raceMap.update(); - } - }); - //listener to save currently selected annotation - saveAnno.setOnAction(event -> { - presetAnno.clear(); - presetAnno.add(showName.isSelected()); - presetAnno.add(showAbbrev.isSelected()); - presetAnno.add(showSpeed.isSelected()); - presetAnno.add(showBoatPath.isSelected()); - presetAnno.add(showTime.isSelected()); - presetAnno.add(showEstTime.isSelected()); - }); - //listener for hiding - hideAnnoRBTN.setOnAction((e)->{ - buttonChecked = hideBtn; - selectShow = false; - showName.setSelected(false); - showAbbrev.setSelected(false); - showBoatPath.setSelected(false); - showSpeed.setSelected(false); - showTime.setSelected(false); - showEstTime.setSelected(false); - raceMap.update(); - buttonChecked = noBtn; - prevBtnChecked = hideBtn; - selectShow = true; - }); - //listener for showing all annotations - showAnnoRBTN.setOnAction((e)->{ - if (selectShow) { - 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)); - showEstTime.setSelected(annoShownBeforeHide.get(estTimeCheckAnno)); - raceMap.update(); - buttonChecked = noBtn; - prevBtnChecked = showBtn; - } - selectShow = true; - }); - //listener for showing all important - partialAnnoRBTN.setOnAction((e)->{ - selectShow = false; - buttonChecked = partialBtn; - showName.setSelected(false); - showAbbrev.setSelected(true); - showSpeed.setSelected(true); - showBoatPath.setSelected(false); - showTime.setSelected(false); - showEstTime.setSelected(false); - - raceMap.update(); - buttonChecked = noBtn; - prevBtnChecked = partialBtn; - selectShow = true; - }); - //listener for showing all important - importantAnnoRBTN.setOnAction((e) ->{ - selectShow = false; - 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)); - showEstTime.setSelected(presetAnno.get(5)); - storeCurrentAnnotationDictionary(); - raceMap.update(); - } - buttonChecked = noBtn; - prevBtnChecked = importantBtn; - selectShow = true; - }); - annotationGroup.selectToggle(showAnnoRBTN); - } - - private String colourToHex(Color color) { - return String.format( "#%02X%02X%02X", - (int)( color.getRed() * 255 ), - (int)( color.getGreen() * 255 ), - (int)( color.getBlue() * 255 ) ); - } - private void makeArrow() { arrowPane.getChildren().add(arrow); } diff --git a/visualiser/src/main/java/seng302/GPSCoordinate.java b/visualiser/src/main/java/seng302/GPSCoordinate.java index 0da61471..96519dbe 100644 --- a/visualiser/src/main/java/seng302/GPSCoordinate.java +++ b/visualiser/src/main/java/seng302/GPSCoordinate.java @@ -2,7 +2,9 @@ package seng302; /** * GPS Coordinate for the world map. - * Created by esa46 on 15/03/17. + * It is converted to a {@link seng302.GraphCoordinate GraphCoordinate} via + * the {@link seng302.RaceMap RaceMap} to display objects in their relative + * positions on the {@link seng302.Model.ResizableRaceMap ResizableRaceMap}. */ public class GPSCoordinate { diff --git a/visualiser/src/main/java/seng302/GraphCoordinate.java b/visualiser/src/main/java/seng302/GraphCoordinate.java index 458052dc..2b4523cc 100644 --- a/visualiser/src/main/java/seng302/GraphCoordinate.java +++ b/visualiser/src/main/java/seng302/GraphCoordinate.java @@ -1,8 +1,10 @@ package seng302; /** - * Graph Coordinate that is to be displayed on the Canvas - * Created by cbt24 on 15/03/17. + * It is a coordinate representing a location on the + * {@link seng302.Model.ResizableRaceMap ResizableRaceMap}. + * It has been converted from a {@link seng302.GPSCoordinate GPSCoordinate} + * to display objects in their relative positions. */ public class GraphCoordinate { private final int x; diff --git a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java index b7778c8e..33c7d5ea 100644 --- a/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java +++ b/visualiser/src/main/java/seng302/Mock/BoatXMLReader.java @@ -15,7 +15,9 @@ import java.util.List; import java.util.Map; /** - * XML Read that reads the Boats that are goign to participate in the Race + * XML Reader that reads in a file and initializes + * {@link seng302.Mock.StreamedBoat StreamedBoat}s that will be participating + * in a race. */ public class BoatXMLReader extends XMLReader { private final Map streamedBoatMap = new HashMap<>(); @@ -122,8 +124,9 @@ public class BoatXMLReader extends XMLReader { } for (int i = 0; i < boat.getChildNodes().getLength(); i++) { - Node GPSPosition = boat.getChildNodes().item(i); - if (GPSPosition.getNodeName().equals("GPSposition")) readBoatPositionInformation(sourceID, GPSPosition); + Node GPSposition = boat.getChildNodes().item(i); + if (GPSposition.getNodeName().equals("GPSposition")) + readBoatPositionInformation(sourceID, GPSposition); } } } @@ -131,12 +134,13 @@ public class BoatXMLReader extends XMLReader { /** * Reads the positional information about a boat - * Ignored values: FlagPosition, MastTop, Z value of GPSposition + * Ignored values: FlagPosition, MastTop, Z value of GPSPosition * @param sourceID The source ID of the boat. - * @param GPSPosition The relative GPS position of the boat. + * @param GPSposition The relative GPS position of the boat. */ - private void readBoatPositionInformation(int sourceID, Node GPSPosition) { - // TODO Get relative point before implementing. (GPSposition is based off a relative point). + private void readBoatPositionInformation(int sourceID, Node GPSposition) { + // TODO Get relative point before implementing. (GPSposition is based + // off a relative point). } /** diff --git a/visualiser/src/main/java/seng302/Mock/StreamedRace.java b/visualiser/src/main/java/seng302/Mock/StreamedRace.java index 7cd29c6e..9098e0bd 100644 --- a/visualiser/src/main/java/seng302/Mock/StreamedRace.java +++ b/visualiser/src/main/java/seng302/Mock/StreamedRace.java @@ -268,9 +268,10 @@ public class StreamedRace implements Runnable { } /** - * Takes an estimated time an event will occur, and converts it to the number of seconds before the event will occur. + * Takes an estimated time an event will occur, and converts it to the + * number of seconds before the event will occur. * - * @param estTimeMillis + * @param estTimeMillis estimated time in milliseconds * @return int difference between time the race started and the estimated time */ private int convertEstTime(long estTimeMillis, long currentTime) { diff --git a/visualiser/src/main/java/seng302/Model/Annotations.java b/visualiser/src/main/java/seng302/Model/Annotations.java new file mode 100644 index 00000000..b4f58260 --- /dev/null +++ b/visualiser/src/main/java/seng302/Model/Annotations.java @@ -0,0 +1,284 @@ +package seng302.Model; + +import javafx.fxml.FXML; +import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; +import javafx.scene.control.RadioButton; +import javafx.scene.control.Toggle; +import javafx.scene.layout.AnchorPane; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class that processes user selected annotation visibility options to + * display the requested information on the + * {@link seng302.Model.ResizableRaceMap ResizbleRaceMap}. These are displayed + * via the {@link seng302.Controllers.RaceController RaceController}.
+ * Annotation options for a {@link seng302.Model.Boat Boat} include: its name, + * abbreviation, speed, the time since it passed the last + * {@link seng302.Model.Marker Marker}, estimated time to the next marker, + * and a path it has travelled made up of + * {@link seng302.Model.TrackPoint TrackPoint}s. + */ +public class Annotations { + private ResizableRaceCanvas raceMap; + + // checkable objects in the anchor pane + private Map checkBoxes = new HashMap<>(); + private Map annoToggles = new HashMap<>(); + + // maps of selected and saved annotations + private Map importantAnno = new HashMap<>(); + private Map annoShownBeforeHide = new HashMap<>(); + + // string values match the fx:id value of check boxes + private static String nameCheckAnno = "showName"; + private static String abbrevCheckAnno = "showAbbrev"; + private static String speedCheckAnno = "showSpeed"; + private static String pathCheckAnno = "showBoatPath"; + private static String timeCheckAnno = "showTime"; + private static String estTimeCheckAnno = "showEstTime"; + + // string values match the fx:id value of radio buttons + private static String noBtn = "noBtn"; + private static String hideBtn = "hideAnnoRBtn"; + private static String showBtn = "showAnnoRBtn"; + private static String partialBtn = "partialAnnoRBtn"; + private static String importantBtn = "importantAnnoRBtn"; + + private Boolean selectShow = false; + private String buttonChecked; + private String prevBtnChecked; + @FXML Button saveAnnoBtn; + + /** + * Constructor to set up and display initial annotations + * @param annotationPane javaFX pane containing annotation options + * @param raceMap the canvas to update annotation displays + */ + public Annotations(AnchorPane annotationPane, ResizableRaceCanvas raceMap){ + this.raceMap = raceMap; + + for (Node child : annotationPane.getChildren()) { + // collect all check boxes into a map + if (child.getClass()==CheckBox.class){ + checkBoxes.put(child.getId(), (CheckBox)child); + } + // collect annotation toggle radio buttons into a map + else if (child.getClass()== RadioButton.class){ + //annotationGroup.getToggles().add((RadioButton)child); + annoToggles.put(child.getId(), (RadioButton)child); + } + else if (child.getClass() == Button.class){ + saveAnnoBtn = (Button)child; + } + } + initializeAnnotations(); + } + + + /** + * Set up initial boat annotations and shows all data. + * Defines partial annotations. + * Creates listeners for when the user selects a different annotation + * visibility. + */ + public void initializeAnnotations() { + for (Map.Entry checkBox : checkBoxes.entrySet()) + { annoShownBeforeHide.put(checkBox.getKey(), true); } + + addCheckBoxListeners(); + addSaveAnnoListener(); + addAnnoToggleListeners(); + + annoToggles.get(showBtn).setSelected(true); + } + + /** + * Creates listeners for each checkbox so the annotation display is + * updated when a user selects a different level of annotation visibility. + */ + private void addCheckBoxListeners(){ + //listener for show name in annotation + checkBoxes.get(nameCheckAnno).selectedProperty() + .addListener((ov, old_val, new_val) -> { + if (old_val != new_val) { + raceMap.toggleAnnoName(); + storeCurrentAnnotationState(nameCheckAnno, new_val); + raceMap.update(); + } + }); + + //listener for show abbreviation for annotation + checkBoxes.get(abbrevCheckAnno).selectedProperty() + .addListener((ov, old_val, new_val) -> { + if (old_val != new_val) { + raceMap.toggleAnnoAbbrev(); + storeCurrentAnnotationState(abbrevCheckAnno, new_val); + raceMap.update(); + } + }); + + //listener for show boat path for annotation + checkBoxes.get(pathCheckAnno).selectedProperty() + .addListener((ov, old_val, new_val) -> { + if (old_val != new_val) { + raceMap.toggleBoatPath(); + storeCurrentAnnotationState(pathCheckAnno, new_val); + raceMap.update(); + } + }); + + //listener to show speed for annotation + checkBoxes.get(speedCheckAnno).selectedProperty() + .addListener((ov, old_val, new_val) -> { + if (old_val != new_val) { + raceMap.toggleAnnoSpeed(); + storeCurrentAnnotationState(speedCheckAnno, new_val); + raceMap.update(); + } + }); + + //listener to show time for annotation + checkBoxes.get(timeCheckAnno).selectedProperty() + .addListener((ov, old_val, new_val) -> { + if (old_val != new_val) { + raceMap.toggleAnnoTime(); + storeCurrentAnnotationState(timeCheckAnno, new_val); + raceMap.update(); + } + }); + + //listener to show estimated time for annotation + checkBoxes.get(estTimeCheckAnno).selectedProperty() + .addListener((ov, old_val, new_val) -> { + if (old_val != new_val) { + raceMap.toggleAnnoEstTime(); + storeCurrentAnnotationState(estTimeCheckAnno, new_val); + raceMap.update(); + } + }); + } + + /** + * Creates a listener so the system knows when to save a users currently + * selected annotation options as important for future use. + */ + private void addSaveAnnoListener(){ + //listener to save currently selected annotations as important + saveAnnoBtn.setOnAction(event -> { + importantAnno.clear(); + for (Map.Entry checkBox : checkBoxes.entrySet()){ + importantAnno.put(checkBox.getKey(), + checkBox.getValue().isSelected()); + } + }); + } + + /** + * Creates listeners for each visibility option so that the annotation + * display is updated when a user selects a different level of annotation + * visibility. + */ + private void addAnnoToggleListeners(){ + //listener for hiding all annotations + RadioButton hideAnnoRBtn = (RadioButton)annoToggles.get(hideBtn); + hideAnnoRBtn.setOnAction((e)->{ + buttonChecked = hideBtn; + selectShow = false; + for (Map.Entry checkBox : checkBoxes.entrySet()){ + checkBox.getValue().setSelected(false); + } + raceMap.update(); + buttonChecked = noBtn; + prevBtnChecked = hideBtn; + selectShow = true; + }); + + //listener for showing previously visible annotations + RadioButton showAnnoRBTN = (RadioButton)annoToggles.get(showBtn); + showAnnoRBTN.setOnAction((e)->{ + if (selectShow) { + buttonChecked = showBtn; + for (Map.Entry checkBox : checkBoxes.entrySet()){ + checkBox.getValue().setSelected( + annoShownBeforeHide.get(checkBox.getKey())); + } + raceMap.update(); + buttonChecked = noBtn; + prevBtnChecked = showBtn; + } + selectShow = true; + }); + + //listener for showing a predetermined subset of annotations + RadioButton partialAnnoRBTN = (RadioButton)annoToggles.get(partialBtn); + partialAnnoRBTN.setOnAction((e)->{ + selectShow = false; + buttonChecked = partialBtn; + for (Map.Entry checkBox : checkBoxes.entrySet()){ + // the checkbox defaults for partial annotations + if (checkBox.getKey().equals(abbrevCheckAnno) + || checkBox.getKey().equals(speedCheckAnno)){ + checkBox.getValue().setSelected(true); + } + else { checkBox.getValue().setSelected(false); } + } + raceMap.update(); + buttonChecked = noBtn; + prevBtnChecked = partialBtn; + selectShow = true; + }); + + //listener for showing all saved important annotations + RadioButton importantAnnoRBTN = (RadioButton)annoToggles.get(importantBtn); + importantAnnoRBTN.setOnAction((e) ->{ + selectShow = false; + buttonChecked = importantBtn; + if (importantAnno.size()>0){ + for (Map.Entry checkBox : checkBoxes.entrySet()){ + checkBox.getValue().setSelected + (importantAnno.get(checkBox.getKey())); + } + } + buttonChecked = noBtn; + prevBtnChecked = importantBtn; + selectShow = true; + }); + } + + /** + * Updates the current state of an annotation so that when a user + * deselects the hidden visibility option, the previous annotations will + * be displayed again. + * @param dictionaryAnnotationKey annotation checkbox + * @param selected boolean value representing the state of the checkbox + */ + private void storeCurrentAnnotationState(String dictionaryAnnotationKey, boolean selected){ + if (buttonChecked != hideBtn) { + //if we are checking the box straight out of hide instead of using the radio buttons + annoShownBeforeHide.put(dictionaryAnnotationKey, selected); + if (prevBtnChecked == hideBtn && buttonChecked == noBtn){ + storeCurrentAnnotationDictionary(); + } + if (buttonChecked == noBtn) { + selectShow = false; + annoToggles.get(showBtn).setSelected(true); + } + } + } + + /** + * Stores all current annotation states so that when a user + * deselects the hidden visibility option, the previous annotations will + * be displayed again. + */ + private void storeCurrentAnnotationDictionary(){ + for (Map.Entry checkBox : checkBoxes.entrySet()){ + annoShownBeforeHide.put(checkBox.getKey(), + checkBox.getValue().isSelected()); + } + } +} diff --git a/visualiser/src/main/java/seng302/Model/Boat.java b/visualiser/src/main/java/seng302/Model/Boat.java index c9765107..3d0613ca 100644 --- a/visualiser/src/main/java/seng302/Model/Boat.java +++ b/visualiser/src/main/java/seng302/Model/Boat.java @@ -11,7 +11,10 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; /** - * Created by fwy13 on 3/03/17. + * This class is used to represent and store information about a boat which may + * travel around in a race. It is displayed on the + * {@link seng302.Model.ResizableRaceCanvas ResizableRaceCanvas} via the + * {@link seng302.Controllers.RaceController RaceController}. */ public class Boat { diff --git a/visualiser/src/main/java/seng302/Model/BoatInRace.java b/visualiser/src/main/java/seng302/Model/BoatInRace.java index 39087177..b949900e 100644 --- a/visualiser/src/main/java/seng302/Model/BoatInRace.java +++ b/visualiser/src/main/java/seng302/Model/BoatInRace.java @@ -1,310 +1,311 @@ -package seng302.Model; - -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import javafx.scene.paint.Color; -import org.geotools.referencing.GeodeticCalculator; -import seng302.GPSCoordinate; - -import java.awt.geom.Point2D; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - -/** - * Boat in the Race extends Boat. - * Created by esa46 on 15/03/17. - */ -public class BoatInRace extends Boat { - - private Leg currentLeg; - private double scaledVelocity; - private double distanceTravelledInLeg; - private GPSCoordinate currentPosition; - private long timeFinished; - private Color colour; - private boolean finished = false; - private final StringProperty currentLegName; - private boolean started = false; - private final StringProperty position; - private double heading; - private static final double WAKE_SCALE = 10; - - private final Queue track = new ConcurrentLinkedQueue<>(); - private long nextValidTime = 0; - - private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000; - private static float trackPointTimeInterval = 5000; // every 1 seconds - - /** - * Constructor method. - * - * @param name Name of the boat. - * @param velocity Speed that the boat travels. - * @param colour Colour the boat will be displayed as on the map - * @param abbrev of boat - */ - public BoatInRace(String name, double velocity, Color colour, String abbrev) { - super(name, velocity, abbrev); - setColour(colour); - currentLegName = new SimpleStringProperty(""); - position = new SimpleStringProperty("-"); - } - - /** - * Calculates the azimuth of the travel via map coordinates of the raceMarkers - * - * @return the direction that the boat is heading towards in degrees (-180 to 180). - */ - public double calculateAzimuth() { - - GeodeticCalculator calc = new GeodeticCalculator(); - GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate(); - GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate(); - - calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude()); - calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude()); - - return calc.getAzimuth(); - } - - /** - * Converts an azimuth to a bearing - * - * @param azimuth azimuth value to be converted - * @return the bearings in degrees (0 to 360). - */ - private static double calculateHeading(double azimuth) { - if (azimuth >= 0) { - return azimuth; - } else { - return azimuth + 360; - } - } - - public double getHeading() { - return heading; - } - - public void setHeading(double heading) { - this.heading = heading; - } - - /** - * Calculates the bearing of the travel via map coordinates of the raceMarkers - * - * @return the direction that the boat is heading towards in degrees (0 to 360). - */ - public double calculateHeading() { - double azimuth = calculateAzimuth(); - return calculateHeading(azimuth); - } - - /** - * 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 - * speed. - * - * @return GPSCoordinate of wake endpoint. - */ - public GPSCoordinate getWake() { - double reverseHeading = getHeading() - 180; - double distance = WAKE_SCALE * getVelocity(); - - GeodeticCalculator calc = new GeodeticCalculator(); - calc.setStartingGeographicPoint( - new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude()) - ); - calc.setDirection(reverseHeading, distance); - Point2D endpoint = calc.getDestinationGeographicPoint(); - return new GPSCoordinate(endpoint.getY(), endpoint.getX()); - } - - /** - * @return Scaled velocity of the boat - */ - public double getScaledVelocity() { - return scaledVelocity; - } - - /** - * Sets the boat's scaled velocity - * - * @param velocity of boat - */ - public void setScaledVelocity(double velocity) { - this.scaledVelocity = velocity; - } - - /** - * @return Returns the current position of the boat in a GPSCoordinate Class. - * @see GPSCoordinate - */ - public GPSCoordinate getCurrentPosition() { - return currentPosition; - } - - /** - * Sets the current position on the GPS that the boat. - * - * @param position GPSCoordinate of the position that the boat is currently on. - * @see GPSCoordinate - */ - public void setCurrentPosition(GPSCoordinate position) { - this.currentPosition = position; - } - - /** - * @return Returns the time that the boat finished the race. - */ - public long getTimeFinished() { - return timeFinished; - } - - /** - * Sets the time that the boat finished the race. - * - * @param timeFinished Time the boat finished the race. - */ - public void setTimeFinished(long timeFinished) { - this.timeFinished = timeFinished; - } - - /** - * @return Returns the colour of the boat. - */ - public Color getColour() { - return colour; - } - - /** - * Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas. - * - * @param colour Colour that the boat is to be set to. - * @see ResizableRaceCanvas - */ - private void setColour(Color colour) { - this.colour = colour; - } - - /** - * Gets the current leg that the boat is on. - * - * @return returns the leg the boat is on in a Leg class - * @see Leg - */ - public Leg getCurrentLeg() { - return currentLeg; - } - - /** - * Sets the boat's current leg. - * - * @param currentLeg Leg class that the boat is currently on. - * @see Leg - */ - public void setCurrentLeg(Leg currentLeg) { - this.currentLeg = currentLeg; - this.currentLegName.setValue(currentLeg.getName()); - } - - /** - * @return Name of boat's current leg - */ - public StringProperty getCurrentLegName() { - return currentLegName; - } - - /** - * Gets the distance travelled by the boat in the leg. - * - * @return Returns the value in nautical miles (1.852km) that the boat has traversed. - */ - public double getDistanceTravelledInLeg() { - return distanceTravelledInLeg; - } - - /** - * Sets the distance travelled by the boat in the leg in nautical miles (1.852km) - * - * @param distanceTravelledInLeg Distance travelled by the boat in nautical miles. - */ - public void setDistanceTravelledInLeg(double distanceTravelledInLeg) { - this.distanceTravelledInLeg = distanceTravelledInLeg; - } - - /** - * @return true if boat has finished, false if not - */ - public boolean isFinished() { - return this.finished; - } - - /** - * Sets whether boat is finished or not - * - * @param bool is finished value - */ - public void setFinished(boolean bool) { - this.finished = bool; - } - - public boolean isStarted() { - return started; - } - - public void setStarted(boolean started) { - this.started = started; - } - - public String getPosition() { - return position.get(); - } - - public StringProperty positionProperty() { - return position; - } - - public void setPosition(String position) { - this.position.set(position); - } - - /** - * Adds a new point to boat's track. - * @param coordinate of point on track - * @see seng302.Model.TrackPoint - */ - public void addTrackPoint(GPSCoordinate coordinate) { - Boolean added = System.currentTimeMillis() >= nextValidTime; - long currentTime = System.currentTimeMillis(); - if (added && this.started) { - nextValidTime = currentTime + (long) trackPointTimeInterval; - int TRACK_POINT_LIMIT = 10; - track.add(new TrackPoint(coordinate, currentTime, TRACK_POINT_LIMIT * (long) trackPointTimeInterval)); - } - } - - /** - * Returns the boat's sampled track between start of race and current time. - * @return queue of track points - * @see seng302.Model.TrackPoint - */ - public Queue getTrack() { - return track; - } - - /** - * Get base track point time interval - * @return base track point time interval - */ - public static float getBaseTrackPointTimeInterval() { - return BASE_TRACK_POINT_TIME_INTERVAL; - } - - /** - * Set track point time interval - * @param value track point time interval value - */ - public static void setTrackPointTimeInterval(float value) { - trackPointTimeInterval = value; - } -} +//package seng302.Model; +// +//import javafx.beans.property.SimpleStringProperty; +//import javafx.beans.property.StringProperty; +//import javafx.scene.paint.Color; +//import org.geotools.referencing.GeodeticCalculator; +//import seng302.GPSCoordinate; +// +//import java.awt.geom.Point2D; +//import java.util.Queue; +//import java.util.concurrent.ConcurrentLinkedQueue; +// +///** +// * Boat in the Race extends {@link seng302.Model.Boat Boat}. +// * The extended properties are related to the boats current race position. +// * @See seng302.Model.Boat +// */ +//public class BoatInRace extends Boat { +// +// private Leg currentLeg; +// private double scaledVelocity; +// private double distanceTravelledInLeg; +// private GPSCoordinate currentPosition; +// private long timeFinished; +// private Color colour; +// private boolean finished = false; +// private final StringProperty currentLegName; +// private boolean started = false; +// private final StringProperty position; +// private double heading; +// private static final double WAKE_SCALE = 10; +// +// private final Queue track = new ConcurrentLinkedQueue<>(); +// private long nextValidTime = 0; +// +// private static final float BASE_TRACK_POINT_TIME_INTERVAL = 5000; +// private static float trackPointTimeInterval = 5000; // every 1 seconds +// +// /** +// * Constructor method. +// * +// * @param name Name of the boat. +// * @param velocity Speed that the boat travels. +// * @param colour Colour the boat will be displayed as on the map +// * @param abbrev of boat +// */ +// public BoatInRace(String name, double velocity, Color colour, String abbrev) { +// super(name, velocity, abbrev); +// setColour(colour); +// currentLegName = new SimpleStringProperty(""); +// position = new SimpleStringProperty("-"); +// } +// +// /** +// * Calculates the azimuth of the travel via map coordinates of the raceMarkers +// * +// * @return the direction that the boat is heading towards in degrees (-180 to 180). +// */ +// public double calculateAzimuth() { +// +// GeodeticCalculator calc = new GeodeticCalculator(); +// GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate(); +// GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate(); +// +// calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude()); +// calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude()); +// +// return calc.getAzimuth(); +// } +// +// /** +// * Converts an azimuth to a bearing +// * +// * @param azimuth azimuth value to be converted +// * @return the bearings in degrees (0 to 360). +// */ +// private static double calculateHeading(double azimuth) { +// if (azimuth >= 0) { +// return azimuth; +// } else { +// return azimuth + 360; +// } +// } +// +// public double getHeading() { +// return heading; +// } +// +// public void setHeading(double heading) { +// this.heading = heading; +// } +// +// /** +// * Calculates the bearing of the travel via map coordinates of the raceMarkers +// * +// * @return the direction that the boat is heading towards in degrees (0 to 360). +// */ +// public double calculateHeading() { +// double azimuth = calculateAzimuth(); +// return calculateHeading(azimuth); +// } +// +// /** +// * 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 +// * speed. +// * +// * @return GPSCoordinate of wake endpoint. +// */ +// public GPSCoordinate getWake() { +// double reverseHeading = getHeading() - 180; +// double distance = WAKE_SCALE * getVelocity(); +// +// GeodeticCalculator calc = new GeodeticCalculator(); +// calc.setStartingGeographicPoint( +// new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude()) +// ); +// calc.setDirection(reverseHeading, distance); +// Point2D endpoint = calc.getDestinationGeographicPoint(); +// return new GPSCoordinate(endpoint.getY(), endpoint.getX()); +// } +// +// /** +// * @return Scaled velocity of the boat +// */ +// public double getScaledVelocity() { +// return scaledVelocity; +// } +// +// /** +// * Sets the boat's scaled velocity +// * +// * @param velocity of boat +// */ +// public void setScaledVelocity(double velocity) { +// this.scaledVelocity = velocity; +// } +// +// /** +// * @return Returns the current position of the boat in a GPSCoordinate Class. +// * @see GPSCoordinate +// */ +// public GPSCoordinate getCurrentPosition() { +// return currentPosition; +// } +// +// /** +// * Sets the current position on the GPS that the boat. +// * +// * @param position GPSCoordinate of the position that the boat is currently on. +// * @see GPSCoordinate +// */ +// public void setCurrentPosition(GPSCoordinate position) { +// this.currentPosition = position; +// } +// +// /** +// * @return Returns the time that the boat finished the race. +// */ +// public long getTimeFinished() { +// return timeFinished; +// } +// +// /** +// * Sets the time that the boat finished the race. +// * +// * @param timeFinished Time the boat finished the race. +// */ +// public void setTimeFinished(long timeFinished) { +// this.timeFinished = timeFinished; +// } +// +// /** +// * @return Returns the colour of the boat. +// */ +// public Color getColour() { +// return colour; +// } +// +// /** +// * Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas. +// * +// * @param colour Colour that the boat is to be set to. +// * @see ResizableRaceCanvas +// */ +// private void setColour(Color colour) { +// this.colour = colour; +// } +// +// /** +// * Gets the current leg that the boat is on. +// * +// * @return returns the leg the boat is on in a Leg class +// * @see Leg +// */ +// public Leg getCurrentLeg() { +// return currentLeg; +// } +// +// /** +// * Sets the boat's current leg. +// * +// * @param currentLeg Leg class that the boat is currently on. +// * @see Leg +// */ +// public void setCurrentLeg(Leg currentLeg) { +// this.currentLeg = currentLeg; +// this.currentLegName.setValue(currentLeg.getName()); +// } +// +// /** +// * @return Name of boat's current leg +// */ +// public StringProperty getCurrentLegName() { +// return currentLegName; +// } +// +// /** +// * Gets the distance travelled by the boat in the leg. +// * +// * @return Returns the value in nautical miles (1.852km) that the boat has traversed. +// */ +// public double getDistanceTravelledInLeg() { +// return distanceTravelledInLeg; +// } +// +// /** +// * Sets the distance travelled by the boat in the leg in nautical miles (1.852km) +// * +// * @param distanceTravelledInLeg Distance travelled by the boat in nautical miles. +// */ +// public void setDistanceTravelledInLeg(double distanceTravelledInLeg) { +// this.distanceTravelledInLeg = distanceTravelledInLeg; +// } +// +// /** +// * @return true if boat has finished, false if not +// */ +// public boolean isFinished() { +// return this.finished; +// } +// +// /** +// * Sets whether boat is finished or not +// * +// * @param bool is finished value +// */ +// public void setFinished(boolean bool) { +// this.finished = bool; +// } +// +// public boolean isStarted() { +// return started; +// } +// +// public void setStarted(boolean started) { +// this.started = started; +// } +// +// public String getPosition() { +// return position.get(); +// } +// +// public StringProperty positionProperty() { +// return position; +// } +// +// public void setPosition(String position) { +// this.position.set(position); +// } +// +// /** +// * Adds a new point to boat's track. +// * @param coordinate of point on track +// * @see seng302.Model.TrackPoint +// */ +// public void addTrackPoint(GPSCoordinate coordinate) { +// Boolean added = System.currentTimeMillis() >= nextValidTime; +// long currentTime = System.currentTimeMillis(); +// if (added && this.started) { +// nextValidTime = currentTime + (long) trackPointTimeInterval; +// int TRACK_POINT_LIMIT = 10; +// track.add(new TrackPoint(coordinate, currentTime, TRACK_POINT_LIMIT * (long) trackPointTimeInterval)); +// } +// } +// +// /** +// * Returns the boat's sampled track between start of race and current time. +// * @return queue of track points +// * @see seng302.Model.TrackPoint +// */ +// public Queue getTrack() { +// return track; +// } +// +// /** +// * Get base track point time interval +// * @return base track point time interval +// */ +// public static float getBaseTrackPointTimeInterval() { +// return BASE_TRACK_POINT_TIME_INTERVAL; +// } +// +// /** +// * Set track point time interval +// * @param value track point time interval value +// */ +// public static void setTrackPointTimeInterval(float value) { +// trackPointTimeInterval = value; +// } +//} diff --git a/visualiser/src/main/java/seng302/Model/Leg.java b/visualiser/src/main/java/seng302/Model/Leg.java index 61a4d63b..92b6117a 100644 --- a/visualiser/src/main/java/seng302/Model/Leg.java +++ b/visualiser/src/main/java/seng302/Model/Leg.java @@ -4,7 +4,9 @@ import org.geotools.referencing.GeodeticCalculator; import seng302.GPSCoordinate; /** - * Created by cbt24 on 6/03/17. + * This class represents a leg, which is a portion of a race between two + * {@link seng302.Model.Marker Marker}s. A leg is used to identify a + * {@link seng302.Model.Boat Boat}'s progress through a race. */ public class Leg { private final String name; //nautical miles diff --git a/visualiser/src/main/java/seng302/Model/Marker.java b/visualiser/src/main/java/seng302/Model/Marker.java index 567af254..7c0b7296 100644 --- a/visualiser/src/main/java/seng302/Model/Marker.java +++ b/visualiser/src/main/java/seng302/Model/Marker.java @@ -6,7 +6,11 @@ import seng302.GPSCoordinate; import java.awt.geom.Point2D; /** - * Created by esa46 on 29/03/17. + * A marker on a race course that a boat can pass, to be displayed on the + * {@link seng302.Model.ResizableRaceCanvas ResizableRaceCanvas}. This is + * displayed via the {@link seng302.Controllers.RaceController RaceController}. + *
Markers are also used to calculate a {@link seng302.Model.Leg Leg} + * distance. */ public class Marker { private final GPSCoordinate averageGPSCoordinate; diff --git a/visualiser/src/main/java/seng302/Model/RaceClock.java b/visualiser/src/main/java/seng302/Model/RaceClock.java index 1e36224d..1800a239 100644 --- a/visualiser/src/main/java/seng302/Model/RaceClock.java +++ b/visualiser/src/main/java/seng302/Model/RaceClock.java @@ -16,7 +16,11 @@ import java.time.temporal.ChronoUnit; import java.util.Date; /** - * Created by Gondr on 19/04/2017. + * This class is used to implement a clock which keeps track of and + * displays times relevant to a race. This is displayed on the + * {@link seng302.Model.ResizableRaceCanvas ResizableRaceCanvas} via the + * {@link seng302.Controllers.RaceController RaceController} and the + * {@link seng302.Controllers.StartController StartController}. */ public class RaceClock implements Runnable { private long lastTime; diff --git a/visualiser/src/main/java/seng302/Model/ResizableCanvas.java b/visualiser/src/main/java/seng302/Model/ResizableCanvas.java index 1dab2aa6..95ee7a32 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableCanvas.java +++ b/visualiser/src/main/java/seng302/Model/ResizableCanvas.java @@ -4,7 +4,7 @@ import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; /** - * Created by fwy13 on 4/05/17. + * The abstract class for the resizable race canvases. */ public abstract class ResizableCanvas extends Canvas { protected final GraphicsContext gc; diff --git a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java index bccd3395..cb5107b0 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/visualiser/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -16,9 +16,16 @@ import java.time.ZonedDateTime; import java.util.*; /** - * This creates a JavaFX Canvas that is fills it's parent. - * Cannot be downsized. - * Created by fwy13 on 17/03/17. + * This JavaFX Canvas is used to update and display details for a + * {@link seng302.RaceMap RaceMap} via the + * {@link seng302.Controllers.RaceController RaceController}.
+ * It fills it's parent and cannot be downsized.
+ * Details displayed include: + * {@link seng302.Model.Boat Boats} (and their + * {@link seng302.Model.TrackPoint TrackPoint}s), + * {@link seng302.Model.Marker Markers}, a + * {@link seng302.Model.RaceClock RaceClock}, a wind direction arrow and + * various user selected {@link seng302.Model.Annotations Annotations}. */ public class ResizableRaceCanvas extends ResizableCanvas { private RaceMap map; diff --git a/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java b/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java index 4a2bed6f..01b97af9 100644 --- a/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java +++ b/visualiser/src/main/java/seng302/Model/ResizableRaceMap.java @@ -9,7 +9,10 @@ import seng302.RaceMap; import java.util.List; /** - * Created by fwy13 on 4/05/17. + * This JavaFX Canvas is used to generate the size of a + * {@link seng302.RaceMap RaceMap} using co-ordinates from a + * {@link seng302.RaceDataSource RaceDataSource}. This is done via the + * {@link seng302.Controllers.RaceController RaceController}. */ public class ResizableRaceMap extends ResizableCanvas { private RaceMap map; @@ -34,8 +37,8 @@ public class ResizableRaceMap extends ResizableCanvas { } /** - * Sets the map race that it is auppost to be viewing. - * @param map + * Sets the map race that it is supposed to be viewing. + * @param map the map to be set */ private void setMap(RaceMap map) { this.map = map; diff --git a/visualiser/src/main/java/seng302/Model/Sparkline.java b/visualiser/src/main/java/seng302/Model/Sparkline.java new file mode 100644 index 00000000..0c4e503d --- /dev/null +++ b/visualiser/src/main/java/seng302/Model/Sparkline.java @@ -0,0 +1,179 @@ +package seng302.Model; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.chart.LineChart; +import javafx.scene.chart.NumberAxis; +import javafx.scene.chart.XYChart; +import javafx.scene.paint.Color; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +/** + * Class to process and modify a sparkline display. This display keeps visual + * track of {@link seng302.Model.Boat Boats}s in a race and their current + * placing position as they complete each {@link seng302.Model.Leg Leg} by + * passing a course {@link seng302.Model.Marker Marker}.
+ * This sparkline is displayed using the + * {@link seng302.Controllers.RaceController RaceController}. + */ +public class Sparkline { + private ArrayList colours; + private ArrayList startBoats = new ArrayList<>(); + private Map boatColours = new HashMap<>(); + private Integer legNum; + private Integer sparkLineNumber = 0; + @FXML LineChart sparklineChart; + @FXML NumberAxis xAxis; + @FXML NumberAxis yAxis; + + + /** + * Constructor to set up initial sparkline (LineChart) object + * @param boats boats to display on the sparkline + * @param legNum total number of legs in the race + * @param sparklineChart javaFX LineChart for the sparkline + */ + public Sparkline(ObservableList boats, Integer legNum, + LineChart sparklineChart) { + this.sparklineChart = sparklineChart; + this.legNum = legNum; + this.yAxis = (NumberAxis)sparklineChart.getYAxis(); + this.xAxis = (NumberAxis)sparklineChart.getXAxis(); + startBoats.addAll(boats); + + makeColours(); + mapBoatColours(); + createSparkline(); + } + + + /** + * Creates and sets initial display for Sparkline for race positions. + * A data series for each boat in the race is added. + * Position numbers are displayed. + */ + public void createSparkline(){ + // NOTE: Y axis is in negatives to display correct positions + + // all boats start in 'last' place + for (int i=0; i series = new XYChart.Series(); + series.getData().add(new XYChart.Data(0, -startBoats.size())); + series.getData().add(new XYChart.Data(0, -startBoats.size())); + sparklineChart.getData().add(series); + sparklineChart.getData().get(i).getNode().setStyle("-fx-stroke: " + + ""+boatColours.get(startBoats.get(i).getSourceID())+";"); + } + + sparklineChart.setCreateSymbols(false); + + // set x axis details + xAxis.setAutoRanging(false); + xAxis.setTickMarkVisible(false); + xAxis.setTickLabelsVisible(false); + xAxis.setMinorTickVisible(false); + xAxis.setUpperBound((startBoats.size()+1)*legNum); + xAxis.setTickUnit((startBoats.size()+1)*legNum); + + // set y axis details + yAxis.setLowerBound(-(startBoats.size()+1)); + yAxis.setUpperBound(0); + yAxis.setAutoRanging(false); + yAxis.setLabel("Position in Race"); + yAxis.setTickUnit(1); + yAxis.setTickMarkVisible(false); + yAxis.setMinorTickVisible(false); + + // hide minus number from displaying on axis + yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) { + @Override + public String toString(Number value) { + if ((Double)value == 0.0 + || (Double)value < -startBoats.size()){ + return ""; + } + else { + return String.format("%7.0f", -value.doubleValue()); + } + } + }); + } + + /** + * Updates the sparkline to display current boat positions. + * New points are plotted to represent each boat when required. + * @param boatsInRace current position of the boats in race + */ + public void updateSparkline(ObservableList boatsInRace){ + int placingVal = boatsInRace.size(); + sparkLineNumber++; + + for (int i = boatsInRace.size() - 1; i >= 0; i--){ + for (int j = startBoats.size() - 1; j >= 0; j--){ + if (boatsInRace.get(i)==startBoats.get(j)){ + + // when a boat is on its first leg + if (boatsInRace.get(i).getCurrentLeg().getLegNumber()==0){ + // adjust boats latest point on X axis + sparklineChart.getData().get(j).getData().get(1) + .setXValue(sparkLineNumber); + } + + // when a boat first enters its second leg + else if (boatsInRace.get(i).getCurrentLeg().getLegNumber + ()==1 && sparklineChart.getData().get(j).getData + ().size()==2){ + // adjust boats position from start mark + sparklineChart.getData().get(j).getData().get(1) + .setYValue(-placingVal); + sparklineChart.getData().get(j).getData().get(1) + .setXValue(sparkLineNumber); + sparklineChart.getData().get(j).getData().add(new XYChart.Data<> + (sparkLineNumber, -placingVal)); + } + + // plot new point for boats current position + else { + sparklineChart.getData().get(j).getData().add + (new XYChart.Data<>(sparkLineNumber, -placingVal)); + } + placingVal-=1; + } + } + } + } + + private void makeColours() { + colours = new ArrayList<>(Arrays.asList( + colourToHex(Color.BLUEVIOLET), + colourToHex(Color.BLACK), + colourToHex(Color.RED), + colourToHex(Color.ORANGE), + colourToHex(Color.DARKOLIVEGREEN), + colourToHex(Color.LIMEGREEN), + colourToHex(Color.PURPLE), + colourToHex(Color.DARKGRAY), + colourToHex(Color.YELLOW) + )); + } + + private String colourToHex(Color color) { + return String.format( "#%02X%02X%02X", + (int)( color.getRed() * 255 ), + (int)( color.getGreen() * 255 ), + (int)( color.getBlue() * 255 ) ); + } + + private void mapBoatColours() { + int currentColour = 0; + for (Boat boat : startBoats) { + if (!boatColours.containsKey(boat.getSourceID())) { + boatColours.put(boat.getSourceID(), colours.get(currentColour)); + } + currentColour = (currentColour + 1) % colours.size(); + } + } +} diff --git a/visualiser/src/main/java/seng302/Model/TrackPoint.java b/visualiser/src/main/java/seng302/Model/TrackPoint.java index 1a2007cf..12eab755 100644 --- a/visualiser/src/main/java/seng302/Model/TrackPoint.java +++ b/visualiser/src/main/java/seng302/Model/TrackPoint.java @@ -3,7 +3,13 @@ package seng302.Model; import seng302.GPSCoordinate; /** - * Created by cbt24 on 7/04/17. + * A TrackPoint is a point plotted to display the track a + * {@link seng302.Model.Boat Boat} has travelled in a race.
+ * TrackPoints are displayed on a + * {@link seng302.Model.ResizableRaceCanvas ResizableRaceCanvas}, via the + * {@link seng302.Controllers.RaceController RaceController}.
+ * Track points can be made visible or hidden via the RaceController's + * {@link seng302.Model.Annotations Annotations}. */ public class TrackPoint { private final GPSCoordinate coordinate; diff --git a/visualiser/src/main/java/seng302/RaceDataSource.java b/visualiser/src/main/java/seng302/RaceDataSource.java index 5f2e52ad..e3bb7634 100644 --- a/visualiser/src/main/java/seng302/RaceDataSource.java +++ b/visualiser/src/main/java/seng302/RaceDataSource.java @@ -8,7 +8,11 @@ import java.time.ZonedDateTime; import java.util.List; /** - * Created by connortaylorbrown on 19/04/17. + * An object that holds relevant data for a race.
+ * Information includes: {@link seng302.Model.Boat Boat}s, + * {@link seng302.Model.Leg Leg}s, {@link seng302.Model.Marker Marker}s and + * the {@link seng302.GPSCoordinate GPSCoordinate}s to create a + * {@link seng302.Model.ResizableRaceMap ResizableRaceMap}. */ public interface RaceDataSource { List getBoats(); diff --git a/visualiser/src/main/java/seng302/RaceMap.java b/visualiser/src/main/java/seng302/RaceMap.java index cbd9f2a4..6d55b0a9 100644 --- a/visualiser/src/main/java/seng302/RaceMap.java +++ b/visualiser/src/main/java/seng302/RaceMap.java @@ -1,7 +1,11 @@ package seng302; /** - * Created by cbt24 on 15/03/17. + * The base size of the map to be used for the + * {@link seng302.Model.ResizableRaceMap ResizableRaceMap} and + * {@link seng302.Model.ResizableRaceCanvas ResizableRaceCanvas}. It is used + * to convert {@link seng302.GPSCoordinate GPSCoordinate}s to relative + * {@link seng302.GraphCoordinate GraphCoordinate}s. */ public class RaceMap { private final double x1; diff --git a/visualiser/src/main/java/seng302/VisualiserInput.java b/visualiser/src/main/java/seng302/VisualiserInput.java index 1c552904..f5a3f561 100644 --- a/visualiser/src/main/java/seng302/VisualiserInput.java +++ b/visualiser/src/main/java/seng302/VisualiserInput.java @@ -14,12 +14,13 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ArrayBlockingQueue; import static seng302.Networking.Utils.ByteConverter.bytesToShort; /** - * TCP client which receives packets/messages from a race data source (e.g., mock source, official source), and exposes them to any observers. + * TCP client which receives packets/messages from a race data source + * (e.g., mock source, official source), and exposes them to any observers. + * @see seng302.Mock.StreamedCourse */ public class VisualiserInput implements Runnable { diff --git a/visualiser/src/main/java/seng302/XMLReader.java b/visualiser/src/main/java/seng302/XMLReader.java index 67253791..f250e268 100644 --- a/visualiser/src/main/java/seng302/XMLReader.java +++ b/visualiser/src/main/java/seng302/XMLReader.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.io.InputStream; /** - * Created by fwy13 on 26/03/2017. + * The abstract class for reading in XML race data. */ public abstract class XMLReader { diff --git a/visualiser/src/main/resources/scenes/race.fxml b/visualiser/src/main/resources/scenes/race.fxml index 5f11b477..97168ac1 100644 --- a/visualiser/src/main/resources/scenes/race.fxml +++ b/visualiser/src/main/resources/scenes/race.fxml @@ -3,25 +3,10 @@ - - - - - - - - - - - - - - - - + + - - + @@ -38,7 +23,7 @@ - + @@ -48,11 +33,14 @@