Finish screen will show when race finishes, added functionality to return to start screen when in finish screen, updated finishScreenView.fxml to have controller and also four corner anchors to fit to parent

This commit is contained in:
Zhi You Tan
2017-05-24 16:17:56 +12:00
parent 641039720e
commit e7060d4b6f
4 changed files with 208 additions and 138 deletions
@@ -1,14 +1,23 @@
package seng302.controllers; package seng302.controllers;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.PriorityBlockingQueue;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import seng302.models.BoatGroup; import seng302.models.BoatGroup;
@@ -25,12 +34,6 @@ import seng302.models.stream.packets.BoatPositionPacket;
import seng302.server.simulator.GeoUtility; import seng302.server.simulator.GeoUtility;
import seng302.server.simulator.mark.Position; import seng302.server.simulator.mark.Position;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.PriorityBlockingQueue;
/** /**
* Created by ptg19 on 15/03/17. * Created by ptg19 on 15/03/17.
* Modified by Haoming Yin (hyi25) on 20/3/2017. * Modified by Haoming Yin (hyi25) on 20/3/2017.
@@ -85,7 +88,7 @@ public class CanvasController {
VERTICAL VERTICAL
} }
public void setup(RaceViewController raceViewController){ public void setup(RaceViewController raceViewController) {
this.raceViewController = raceViewController; this.raceViewController = raceViewController;
} }
@@ -107,14 +110,13 @@ public class CanvasController {
canvas.heightProperty().bind(new SimpleDoubleProperty(CANVAS_HEIGHT)); canvas.heightProperty().bind(new SimpleDoubleProperty(CANVAS_HEIGHT));
} }
public void initializeCanvas (){ public void initializeCanvas() {
gc = canvas.getGraphicsContext2D(); gc = canvas.getGraphicsContext2D();
gc.setGlobalAlpha(0.5); gc.setGlobalAlpha(0.5);
fitMarksToCanvas(); fitMarksToCanvas();
drawGoogleMap(); drawGoogleMap();
// TODO: 1/05/17 wmu16 - Change this call to now draw the marks as from the xml // TODO: 1/05/17 wmu16 - Change this call to now draw the marks as from the xml
initializeBoats(); initializeBoats();
initializeMarks(); initializeMarks();
@@ -124,17 +126,17 @@ public class CanvasController {
public void handle(long now) { public void handle(long now) {
//fps stuff //fps stuff
long oldFrameTime = frameTimes[frameTimeIndex] ; long oldFrameTime = frameTimes[frameTimeIndex];
frameTimes[frameTimeIndex] = now ; frameTimes[frameTimeIndex] = now;
frameTimeIndex = (frameTimeIndex + 1) % frameTimes.length ; frameTimeIndex = (frameTimeIndex + 1) % frameTimes.length;
if (frameTimeIndex == 0) { if (frameTimeIndex == 0) {
arrayFilled = true ; arrayFilled = true;
} }
long elapsedNanos; long elapsedNanos;
if (arrayFilled) { if (arrayFilled) {
elapsedNanos = now - oldFrameTime ; elapsedNanos = now - oldFrameTime;
long elapsedNanosPerFrame = elapsedNanos / frameTimes.length ; long elapsedNanosPerFrame = elapsedNanos / frameTimes.length;
frameRate = 1_000_000_000.0 / elapsedNanosPerFrame ; frameRate = 1_000_000_000.0 / elapsedNanosPerFrame;
drawFps(frameRate.intValue()); drawFps(frameRate.intValue());
} }
@@ -143,11 +145,29 @@ public class CanvasController {
updateGroups(); updateGroups();
if (StreamParser.isRaceFinished()) { if (StreamParser.isRaceFinished()) {
this.stop(); this.stop();
switchToFinishScreen();
} }
} }
}; };
} }
private void switchToFinishScreen() {
try {
// canvas view -> anchor pane -> grid pane -> main view
GridPane gridPane = (GridPane) canvasPane.getParent().getParent();
AnchorPane contentPane = (AnchorPane) gridPane.getParent();
contentPane.getChildren().removeAll();
contentPane.getChildren().clear();
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
contentPane.getChildren().addAll(
(Pane) FXMLLoader.load(getClass().getResource("/views/FinishScreenView.fxml")));
} catch (javafx.fxml.LoadException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/** /**
* First find the top right and bottom left points' geo locations, then retrieve * First find the top right and bottom left points' geo locations, then retrieve
* map from google to display on image view. - Haoming 22/5/2017 * map from google to display on image view. - Haoming 22/5/2017
@@ -156,19 +176,29 @@ public class CanvasController {
findMetersPerPixel(); findMetersPerPixel();
Point2D topLeftPoint = findScaledXY(maxLatPoint.getLatitude(), minLonPoint.getLongitude()); Point2D topLeftPoint = findScaledXY(maxLatPoint.getLatitude(), minLonPoint.getLongitude());
// distance from top left extreme to panel origin (top left corner) // distance from top left extreme to panel origin (top left corner)
double distanceFromTopLeftToOrigin = Math.sqrt(Math.pow(topLeftPoint.getX() * metersPerPixelX, 2) + Math.pow(topLeftPoint.getY() * metersPerPixelY, 2)); double distanceFromTopLeftToOrigin = Math.sqrt(
Math.pow(topLeftPoint.getX() * metersPerPixelX, 2) + Math
.pow(topLeftPoint.getY() * metersPerPixelY, 2));
// angle from top left extreme to panel origin // angle from top left extreme to panel origin
double bearingFromTopLeftToOrigin = Math.toDegrees(Math.atan2(-topLeftPoint.getX(), topLeftPoint.getY())); double bearingFromTopLeftToOrigin = Math
.toDegrees(Math.atan2(-topLeftPoint.getX(), topLeftPoint.getY()));
// the top left extreme // the top left extreme
Position topLeftPos = new Position(maxLatPoint.getLatitude(), minLonPoint.getLongitude()); Position topLeftPos = new Position(maxLatPoint.getLatitude(), minLonPoint.getLongitude());
Position originPos = GeoUtility.getGeoCoordinate(topLeftPos, bearingFromTopLeftToOrigin, distanceFromTopLeftToOrigin); Position originPos = GeoUtility
.getGeoCoordinate(topLeftPos, bearingFromTopLeftToOrigin, distanceFromTopLeftToOrigin);
// distance from origin corner to bottom right corner of the panel // distance from origin corner to bottom right corner of the panel
double distanceFromOriginToBottomRight = Math.sqrt(Math.pow(PANEL_HEIGHT* metersPerPixelY, 2) + Math.pow(PANEL_WIDTH * metersPerPixelX, 2)); double distanceFromOriginToBottomRight = Math.sqrt(
double bearingFromOriginToBottomRight = Math.toDegrees(Math.atan2(PANEL_WIDTH, -PANEL_HEIGHT)); Math.pow(PANEL_HEIGHT * metersPerPixelY, 2) + Math
Position bottomRightPos = GeoUtility.getGeoCoordinate(originPos, bearingFromOriginToBottomRight, distanceFromOriginToBottomRight); .pow(PANEL_WIDTH * metersPerPixelX, 2));
double bearingFromOriginToBottomRight = Math
.toDegrees(Math.atan2(PANEL_WIDTH, -PANEL_HEIGHT));
Position bottomRightPos = GeoUtility
.getGeoCoordinate(originPos, bearingFromOriginToBottomRight,
distanceFromOriginToBottomRight);
Boundary boundary = new Boundary(originPos.getLat(), bottomRightPos.getLng(), bottomRightPos.getLat(), originPos.getLng()); Boundary boundary = new Boundary(originPos.getLat(), bottomRightPos.getLng(),
bottomRightPos.getLat(), originPos.getLng());
CanvasMap canvasMap = new CanvasMap(boundary); CanvasMap canvasMap = new CanvasMap(boundary);
mapImage.setImage(canvasMap.getMapImage()); mapImage.setImage(canvasMap.getMapImage());
} }
@@ -176,9 +206,10 @@ public class CanvasController {
/** /**
* Adds border marks to the canvas, taken from the XML file * Adds border marks to the canvas, taken from the XML file
* *
* NOTE: This is quite confusing as objects are grabbed from the XMLParser such as Mark and CompoundMark which are * NOTE: This is quite confusing as objects are grabbed from the XMLParser such as Mark and
* named the same as those in the model package but are, however not the same, so they do not have things such as * CompoundMark which are named the same as those in the model package but are, however not the
* a type and must be derived from the number of marks in a compound mark etc.. * same, so they do not have things such as a type and must be derived from the number of marks
* in a compound mark etc..
*/ */
private void addRaceBorder() { private void addRaceBorder() {
XMLParser.RaceXMLObject raceXMLObject = StreamParser.getXmlObject().getRaceXML(); XMLParser.RaceXMLObject raceXMLObject = StreamParser.getXmlObject().getRaceXML();
@@ -189,9 +220,11 @@ public class CanvasController {
double[] yBoundaryPoints = new double[courseLimits.size()]; double[] yBoundaryPoints = new double[courseLimits.size()];
for (int i = 0; i < courseLimits.size() - 1; i++) { for (int i = 0; i < courseLimits.size() - 1; i++) {
Limit thisPoint1 = courseLimits.get(i); Limit thisPoint1 = courseLimits.get(i);
SingleMark thisMark1 = new SingleMark("", thisPoint1.getLat(), thisPoint1.getLng(), thisPoint1.getSeqID()); SingleMark thisMark1 = new SingleMark("", thisPoint1.getLat(), thisPoint1.getLng(),
Limit thisPoint2 = courseLimits.get(i+1); thisPoint1.getSeqID());
SingleMark thisMark2 = new SingleMark("", thisPoint2.getLat(), thisPoint2.getLng(), thisPoint2.getSeqID()); Limit thisPoint2 = courseLimits.get(i + 1);
SingleMark thisMark2 = new SingleMark("", thisPoint2.getLat(), thisPoint2.getLng(),
thisPoint2.getSeqID());
Point2D borderPoint1 = findScaledXY(thisMark1); Point2D borderPoint1 = findScaledXY(thisMark1);
Point2D borderPoint2 = findScaledXY(thisMark2); Point2D borderPoint2 = findScaledXY(thisMark2);
gc.strokeLine(borderPoint1.getX(), borderPoint1.getY(), gc.strokeLine(borderPoint1.getX(), borderPoint1.getY(),
@@ -199,21 +232,23 @@ public class CanvasController {
xBoundaryPoints[i] = borderPoint1.getX(); xBoundaryPoints[i] = borderPoint1.getX();
yBoundaryPoints[i] = borderPoint1.getY(); yBoundaryPoints[i] = borderPoint1.getY();
} }
Limit thisPoint1 = courseLimits.get(courseLimits.size()-1); Limit thisPoint1 = courseLimits.get(courseLimits.size() - 1);
SingleMark thisMark1 = new SingleMark("", thisPoint1.getLat(), thisPoint1.getLng(), thisPoint1.getSeqID()); SingleMark thisMark1 = new SingleMark("", thisPoint1.getLat(), thisPoint1.getLng(),
thisPoint1.getSeqID());
Limit thisPoint2 = courseLimits.get(0); Limit thisPoint2 = courseLimits.get(0);
SingleMark thisMark2 = new SingleMark("", thisPoint2.getLat(), thisPoint2.getLng(), thisPoint2.getSeqID()); SingleMark thisMark2 = new SingleMark("", thisPoint2.getLat(), thisPoint2.getLng(),
thisPoint2.getSeqID());
Point2D borderPoint1 = findScaledXY(thisMark1); Point2D borderPoint1 = findScaledXY(thisMark1);
Point2D borderPoint2 = findScaledXY(thisMark2); Point2D borderPoint2 = findScaledXY(thisMark2);
gc.strokeLine(borderPoint1.getX(), borderPoint1.getY(), gc.strokeLine(borderPoint1.getX(), borderPoint1.getY(),
borderPoint2.getX(), borderPoint2.getY()); borderPoint2.getX(), borderPoint2.getY());
xBoundaryPoints[courseLimits.size()-1] = borderPoint1.getX(); xBoundaryPoints[courseLimits.size() - 1] = borderPoint1.getX();
yBoundaryPoints[courseLimits.size()-1] = borderPoint1.getY(); yBoundaryPoints[courseLimits.size() - 1] = borderPoint1.getY();
// gc.setFill(Color.LIGHTBLUE); // gc.setFill(Color.LIGHTBLUE);
// gc.fillPolygon(xBoundaryPoints,yBoundaryPoints,yBoundaryPoints.length); // gc.fillPolygon(xBoundaryPoints,yBoundaryPoints,yBoundaryPoints.length);
} }
private void updateGroups(){ private void updateGroups() {
for (BoatGroup boatGroup : boatGroups) { for (BoatGroup boatGroup : boatGroups) {
// some raceObjects will have multiple ID's (for instance gate marks) // some raceObjects will have multiple ID's (for instance gate marks)
//checking if the current "ID" has any updates associated with it //checking if the current "ID" has any updates associated with it
@@ -235,7 +270,7 @@ public class CanvasController {
} }
private void checkForCourseChanges() { private void checkForCourseChanges() {
if (StreamParser.isNewRaceXmlReceived()){ if (StreamParser.isNewRaceXmlReceived()) {
gc.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); gc.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
drawGoogleMap(); drawGoogleMap();
addRaceBorder(); addRaceBorder();
@@ -243,29 +278,33 @@ public class CanvasController {
} }
private void updateBoatGroup(BoatGroup boatGroup) { private void updateBoatGroup(BoatGroup boatGroup) {
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions.get(boatGroup.getRaceId()); PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.boatPositions
.get(boatGroup.getRaceId());
// giving the movementQueue a 5 packet buffer to account for slightly out of order packets // giving the movementQueue a 5 packet buffer to account for slightly out of order packets
if (movementQueue.size() > 0){ if (movementQueue.size() > 0) {
try { try {
BoatPositionPacket positionPacket = movementQueue.take(); BoatPositionPacket positionPacket = movementQueue.take();
Point2D p2d = findScaledXY(positionPacket.getLat(), positionPacket.getLon()); Point2D p2d = findScaledXY(positionPacket.getLat(), positionPacket.getLon());
double heading = 360.0 / 0xffff * positionPacket.getHeading(); double heading = 360.0 / 0xffff * positionPacket.getHeading();
boatGroup.setDestination(p2d.getX(), p2d.getY(), heading, positionPacket.getGroundSpeed(), positionPacket.getTimeValid(), frameRate, boatGroup.getRaceId()); boatGroup.setDestination(p2d.getX(), p2d.getY(), heading,
} catch (InterruptedException e){ positionPacket.getGroundSpeed(), positionPacket.getTimeValid(), frameRate,
boatGroup.getRaceId());
} catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
// } // }
} }
} }
void updateMarkGroup (long raceId, MarkGroup markGroup) { void updateMarkGroup(long raceId, MarkGroup markGroup) {
PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.markPositions.get(raceId); PriorityBlockingQueue<BoatPositionPacket> movementQueue = StreamParser.markPositions
if (movementQueue.size() > 0){ .get(raceId);
if (movementQueue.size() > 0) {
try { try {
BoatPositionPacket positionPacket = movementQueue.take(); BoatPositionPacket positionPacket = movementQueue.take();
Point2D p2d = findScaledXY(positionPacket.getLat(), positionPacket.getLon()); Point2D p2d = findScaledXY(positionPacket.getLat(), positionPacket.getLon());
markGroup.moveMarkTo(p2d.getX(), p2d.getY(), raceId); markGroup.moveMarkTo(p2d.getX(), p2d.getY(), raceId);
} catch (InterruptedException e){ } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -278,7 +317,8 @@ public class CanvasController {
Map<Integer, Yacht> boats = StreamParser.getBoats(); Map<Integer, Yacht> boats = StreamParser.getBoats();
Group boatAnnotations = new Group(); Group boatAnnotations = new Group();
ArrayList<Participant> participants = StreamParser.getXmlObject().getRaceXML().getParticipants(); ArrayList<Participant> participants = StreamParser.getXmlObject().getRaceXML()
.getParticipants();
ArrayList<Integer> participantIDs = new ArrayList<>(); ArrayList<Integer> participantIDs = new ArrayList<>();
for (Participant p : participants) { for (Participant p : participants) {
participantIDs.add(p.getsourceID()); participantIDs.add(p.getsourceID());
@@ -307,7 +347,8 @@ public class CanvasController {
} else { } else {
GateMark gMark = (GateMark) mark; GateMark gMark = (GateMark) mark;
MarkGroup markGroup = new MarkGroup(gMark, findScaledXY(gMark.getSingleMark1()), findScaledXY(gMark.getSingleMark2())); //should be 2 objects in the list. MarkGroup markGroup = new MarkGroup(gMark, findScaledXY(gMark.getSingleMark1()),
findScaledXY(gMark.getSingleMark2())); //should be 2 objects in the list.
markGroups.add(markGroup); markGroups.add(markGroup);
} }
} }
@@ -339,6 +380,7 @@ public class CanvasController {
public double prefWidth(double height) { public double prefWidth(double height) {
return getWidth(); return getWidth();
} }
@Override @Override
public double prefHeight(double width) { public double prefHeight(double width) {
return getHeight(); return getHeight();
@@ -346,24 +388,25 @@ public class CanvasController {
} }
private void drawFps(int fps){ private void drawFps(int fps) {
if (raceViewController.isDisplayFps()){ if (raceViewController.isDisplayFps()) {
gc.clearRect(5,5,50,20); gc.clearRect(5, 5, 50, 20);
gc.setFill(Color.SKYBLUE); gc.setFill(Color.SKYBLUE);
gc.fillRect(4,4,51,21); gc.fillRect(4, 4, 51, 21);
gc.setFill(Color.BLACK); gc.setFill(Color.BLACK);
gc.setFont(new Font(14)); gc.setFont(new Font(14));
gc.setLineWidth(3); gc.setLineWidth(3);
gc.fillText(fps + " FPS", 5, 20); gc.fillText(fps + " FPS", 5, 20);
} else { } else {
gc.clearRect(5,5,50,20); gc.clearRect(5, 5, 50, 20);
gc.setFill(Color.SKYBLUE); gc.setFill(Color.SKYBLUE);
gc.fillRect(4,4,51,21); gc.fillRect(4, 4, 51, 21);
} }
} }
/** /**
* Calculates x and y location for every marker that fits it to the canvas the race will be drawn on. * Calculates x and y location for every marker that fits it to the canvas the race will be
* drawn on.
*/ */
private void fitMarksToCanvas() { private void fitMarksToCanvas() {
//Check is called once to avoid unnecessarily change the course limits once the race is running //Check is called once to avoid unnecessarily change the course limits once the race is running
@@ -377,8 +420,9 @@ public class CanvasController {
/** /**
* Sets the class variables minLatPoint, maxLatPoint, minLonPoint, maxLonPoint to the marker with the leftmost * Sets the class variables minLatPoint, maxLatPoint, minLonPoint, maxLonPoint to the marker
* marker, rightmost marker, southern most marker and northern most marker respectively. * with the leftmost marker, rightmost marker, southern most marker and northern most marker
* respectively.
*/ */
private void findMinMaxPoint() { private void findMinMaxPoint() {
List<Limit> sortedPoints = new ArrayList<>(); List<Limit> sortedPoints = new ArrayList<>();
@@ -387,70 +431,83 @@ public class CanvasController {
} }
sortedPoints.sort(Comparator.comparingDouble(Limit::getLat)); sortedPoints.sort(Comparator.comparingDouble(Limit::getLat));
Limit minLatMark = sortedPoints.get(0); Limit minLatMark = sortedPoints.get(0);
Limit maxLatMark = sortedPoints.get(sortedPoints.size()-1); Limit maxLatMark = sortedPoints.get(sortedPoints.size() - 1);
minLatPoint = new SingleMark(minLatMark.toString(), minLatMark.getLat(), minLatMark.getLng(), minLatMark.getSeqID()); minLatPoint = new SingleMark(minLatMark.toString(), minLatMark.getLat(),
maxLatPoint = new SingleMark(maxLatMark.toString(), maxLatMark.getLat(), maxLatMark.getLng(), maxLatMark.getSeqID()); minLatMark.getLng(), minLatMark.getSeqID());
maxLatPoint = new SingleMark(maxLatMark.toString(), maxLatMark.getLat(),
maxLatMark.getLng(), maxLatMark.getSeqID());
sortedPoints.sort(Comparator.comparingDouble(Limit::getLng)); sortedPoints.sort(Comparator.comparingDouble(Limit::getLng));
//If the course is on a point on the earth where longitudes wrap around. //If the course is on a point on the earth where longitudes wrap around.
Limit minLonMark = sortedPoints.get(0); Limit minLonMark = sortedPoints.get(0);
Limit maxLonMark = sortedPoints.get(sortedPoints.size()-1); Limit maxLonMark = sortedPoints.get(sortedPoints.size() - 1);
minLonPoint = new SingleMark(minLonMark.toString(), minLonMark.getLat(), minLonMark.getLng(), minLonMark.getSeqID()); minLonPoint = new SingleMark(minLonMark.toString(), minLonMark.getLat(),
maxLonPoint = new SingleMark(maxLonMark.toString(), maxLonMark.getLat(), maxLonMark.getLng(), maxLonMark.getSeqID()); minLonMark.getLng(), minLonMark.getSeqID());
maxLonPoint = new SingleMark(maxLonMark.toString(), maxLonMark.getLat(),
maxLonMark.getLng(), maxLonMark.getSeqID());
if (maxLonPoint.getLongitude() - minLonPoint.getLongitude() > 180) { if (maxLonPoint.getLongitude() - minLonPoint.getLongitude() > 180) {
horizontalInversion = true; horizontalInversion = true;
} }
} }
/** /**
* Calculates the location of a reference point, this is always the point with minimum latitude, in relation to the * Calculates the location of a reference point, this is always the point with minimum latitude,
* canvas. * in relation to the canvas.
* *
* @param minLonToMaxLon The horizontal distance between the point of minimum longitude to maximum longitude. * @param minLonToMaxLon The horizontal distance between the point of minimum longitude to
* maximum longitude.
*/ */
private void calculateReferencePointLocation (double minLonToMaxLon) { private void calculateReferencePointLocation(double minLonToMaxLon) {
Mark referencePoint = minLatPoint; Mark referencePoint = minLatPoint;
double referenceAngle; double referenceAngle;
if (scaleDirection == ScaleDirection.HORIZONTAL) { if (scaleDirection == ScaleDirection.HORIZONTAL) {
referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, minLonPoint)); referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, minLonPoint));
referencePointX = LHS_BUFFER + distanceScaleFactor * Math.sin(referenceAngle) * Mark.calculateDistance(referencePoint, minLonPoint); referencePointX = LHS_BUFFER + distanceScaleFactor * Math.sin(referenceAngle) * Mark
.calculateDistance(referencePoint, minLonPoint);
referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, maxLatPoint)); referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, maxLatPoint));
referencePointY = CANVAS_HEIGHT - (TOP_BUFFER + BOT_BUFFER); referencePointY = CANVAS_HEIGHT - (TOP_BUFFER + BOT_BUFFER);
referencePointY -= distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, maxLatPoint); referencePointY -= distanceScaleFactor * Math.cos(referenceAngle) * Mark
.calculateDistance(referencePoint, maxLatPoint);
referencePointY = referencePointY / 2; referencePointY = referencePointY / 2;
referencePointY += TOP_BUFFER; referencePointY += TOP_BUFFER;
referencePointY += distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, maxLatPoint); referencePointY += distanceScaleFactor * Math.cos(referenceAngle) * Mark
.calculateDistance(referencePoint, maxLatPoint);
} else { } else {
referencePointY = CANVAS_HEIGHT - BOT_BUFFER; referencePointY = CANVAS_HEIGHT - BOT_BUFFER;
referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, minLonPoint)); referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, minLonPoint));
referencePointX = LHS_BUFFER; referencePointX = LHS_BUFFER;
referencePointX += distanceScaleFactor * Math.sin(referenceAngle) * Mark.calculateDistance(referencePoint, minLonPoint); referencePointX += distanceScaleFactor * Math.sin(referenceAngle) * Mark
referencePointX += ((CANVAS_WIDTH - (LHS_BUFFER + RHS_BUFFER)) - (minLonToMaxLon * distanceScaleFactor)) / 2; .calculateDistance(referencePoint, minLonPoint);
referencePointX += ((CANVAS_WIDTH - (LHS_BUFFER + RHS_BUFFER)) - (minLonToMaxLon
* distanceScaleFactor)) / 2;
} }
if(horizontalInversion) { if (horizontalInversion) {
referencePointX = CANVAS_WIDTH - RHS_BUFFER - (referencePointX - LHS_BUFFER); referencePointX = CANVAS_WIDTH - RHS_BUFFER - (referencePointX - LHS_BUFFER);
} }
} }
/** /**
* Finds the scale factor necessary to fit all race markers within the onscreen map and assigns it to distanceScaleFactor * Finds the scale factor necessary to fit all race markers within the onscreen map and assigns
* Returns the max horizontal distance of the map. * it to distanceScaleFactor Returns the max horizontal distance of the map.
*/ */
private double scaleRaceExtremities () { private double scaleRaceExtremities() {
double vertAngle = Math.abs(Mark.calculateHeadingRad(minLatPoint, maxLatPoint)); double vertAngle = Math.abs(Mark.calculateHeadingRad(minLatPoint, maxLatPoint));
double vertDistance = Math.cos(vertAngle) * Mark.calculateDistance(minLatPoint, maxLatPoint); double vertDistance =
Math.cos(vertAngle) * Mark.calculateDistance(minLatPoint, maxLatPoint);
double horiAngle = Mark.calculateHeadingRad(minLonPoint, maxLonPoint); double horiAngle = Mark.calculateHeadingRad(minLonPoint, maxLonPoint);
if (horiAngle <= (Math.PI / 2)) if (horiAngle <= (Math.PI / 2)) {
horiAngle = (Math.PI / 2) - horiAngle; horiAngle = (Math.PI / 2) - horiAngle;
else } else {
horiAngle = horiAngle - (Math.PI / 2); horiAngle = horiAngle - (Math.PI / 2);
double horiDistance = Math.cos(horiAngle) * Mark.calculateDistance(minLonPoint, maxLonPoint); }
double horiDistance =
Math.cos(horiAngle) * Mark.calculateDistance(minLonPoint, maxLonPoint);
double vertScale = (CANVAS_HEIGHT - (TOP_BUFFER + BOT_BUFFER)) / vertDistance; double vertScale = (CANVAS_HEIGHT - (TOP_BUFFER + BOT_BUFFER)) / vertDistance;
@@ -464,35 +521,47 @@ public class CanvasController {
return horiDistance; return horiDistance;
} }
private Point2D findScaledXY (Mark unscaled) { private Point2D findScaledXY(Mark unscaled) {
return findScaledXY (unscaled.getLatitude(), unscaled.getLongitude()); return findScaledXY(unscaled.getLatitude(), unscaled.getLongitude());
} }
private Point2D findScaledXY (double unscaledLat, double unscaledLon) { private Point2D findScaledXY(double unscaledLat, double unscaledLon) {
double distanceFromReference; double distanceFromReference;
double angleFromReference; double angleFromReference;
int xAxisLocation = (int) referencePointX; int xAxisLocation = (int) referencePointX;
int yAxisLocation = (int) referencePointY; int yAxisLocation = (int) referencePointY;
angleFromReference = Mark.calculateHeadingRad(minLatPoint.getLatitude(), minLatPoint.getLongitude(), unscaledLat, unscaledLon); angleFromReference = Mark
distanceFromReference = Mark.calculateDistance(minLatPoint.getLatitude(), minLatPoint.getLongitude(), unscaledLat, unscaledLon); .calculateHeadingRad(minLatPoint.getLatitude(), minLatPoint.getLongitude(), unscaledLat,
unscaledLon);
distanceFromReference = Mark
.calculateDistance(minLatPoint.getLatitude(), minLatPoint.getLongitude(), unscaledLat,
unscaledLon);
if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) { if (angleFromReference >= 0 && angleFromReference <= Math.PI / 2) {
xAxisLocation += (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference); xAxisLocation += (int) Math
yAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference); .round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
yAxisLocation -= (int) Math
.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
} else if (angleFromReference >= 0) { } else if (angleFromReference >= 0) {
angleFromReference = angleFromReference - Math.PI / 2; angleFromReference = angleFromReference - Math.PI / 2;
xAxisLocation += (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference); xAxisLocation += (int) Math
yAxisLocation += (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference); .round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
yAxisLocation += (int) Math
.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
} else if (angleFromReference < 0 && angleFromReference >= -Math.PI / 2) { } else if (angleFromReference < 0 && angleFromReference >= -Math.PI / 2) {
angleFromReference = Math.abs(angleFromReference); angleFromReference = Math.abs(angleFromReference);
xAxisLocation -= (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference); xAxisLocation -= (int) Math
yAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference); .round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
yAxisLocation -= (int) Math
.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
} else { } else {
angleFromReference = Math.abs(angleFromReference) - Math.PI / 2; angleFromReference = Math.abs(angleFromReference) - Math.PI / 2;
xAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference); xAxisLocation -= (int) Math
yAxisLocation += (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference); .round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
yAxisLocation += (int) Math
.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
} }
if(horizontalInversion) { if (horizontalInversion) {
xAxisLocation = CANVAS_WIDTH - RHS_BUFFER - (xAxisLocation - LHS_BUFFER); xAxisLocation = CANVAS_WIDTH - RHS_BUFFER - (xAxisLocation - LHS_BUFFER);
} }
return new Point2D(xAxisLocation, yAxisLocation); return new Point2D(xAxisLocation, yAxisLocation);
@@ -501,7 +570,7 @@ public class CanvasController {
/** /**
* Find the number of meters per pixel. * Find the number of meters per pixel.
*/ */
private void findMetersPerPixel () { private void findMetersPerPixel() {
Point2D p1, p2; Point2D p1, p2;
Mark m1, m2; Mark m1, m2;
double theta, distance, dx, dy, dHorizontal, dVertical; double theta, distance, dx, dy, dHorizontal, dVertical;
@@ -3,27 +3,22 @@ package seng302.controllers;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.application.Platform;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import seng302.models.Yacht; import seng302.models.Yacht;
import seng302.models.stream.StreamParser; import seng302.models.stream.StreamParser;
public class FinishScreenViewController implements Initializable { public class FinishScreenViewController implements Initializable {
@FXML @FXML
private GridPane finishScreenGridPane; private GridPane finishScreenGridPane;
@FXML @FXML
@@ -39,7 +34,8 @@ public class FinishScreenViewController implements Initializable {
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
finishScreenGridPane.getStylesheets().add(getClass().getResource("/css/master.css").toString()); finishScreenGridPane.getStylesheets()
.add(getClass().getResource("/css/master.css").toString());
finishOrderTable.getStylesheets().add(getClass().getResource("/css/master.css").toString()); finishOrderTable.getStylesheets().add(getClass().getResource("/css/master.css").toString());
// set up data for table // set up data for table
@@ -65,19 +61,18 @@ public class FinishScreenViewController implements Initializable {
finishOrderTable.refresh(); finishOrderTable.refresh();
} }
private void setContentPane(String jfxUrl){ private void setContentPane(String jfxUrl) {
try{ try {
// get the main controller anchor pane (FinishView -> RaceView -> MainView) // get the main controller anchor pane (FinishView -> MainView)
AnchorPane contentPane = (AnchorPane) finishScreenGridPane.getParent().getParent(); AnchorPane contentPane = (AnchorPane) finishScreenGridPane.getParent();
contentPane.getChildren().removeAll(); contentPane.getChildren().removeAll();
contentPane.getChildren().clear(); contentPane.getChildren().clear();
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString()); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); contentPane.getChildren()
} .addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
catch(javafx.fxml.LoadException e){ } catch (javafx.fxml.LoadException e) {
e.printStackTrace(); e.printStackTrace();
} } catch (IOException e) {
catch(IOException e){
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -11,7 +11,6 @@ import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
@@ -25,6 +24,7 @@ import seng302.models.Yacht;
import seng302.models.stream.StreamParser; import seng302.models.stream.StreamParser;
public class StartScreenController implements Initializable { public class StartScreenController implements Initializable {
@FXML @FXML
private GridPane gridPane; private GridPane gridPane;
@FXML @FXML
@@ -48,19 +48,18 @@ public class StartScreenController implements Initializable {
private boolean switchedToRaceView = false; private boolean switchedToRaceView = false;
private void setContentPane(String jfxUrl){ private void setContentPane(String jfxUrl) {
try{ try {
// get the main controller anchor pane (MainView.fxml) // get the main controller anchor pane (MainView.fxml)
AnchorPane contentPane = (AnchorPane) gridPane.getParent(); AnchorPane contentPane = (AnchorPane) gridPane.getParent();
contentPane.getChildren().removeAll(); contentPane.getChildren().removeAll();
contentPane.getChildren().clear(); contentPane.getChildren().clear();
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString()); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); contentPane.getChildren()
} .addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
catch(javafx.fxml.LoadException e){ } catch (javafx.fxml.LoadException e) {
e.printStackTrace(); e.printStackTrace();
} } catch (IOException e) {
catch(IOException e){
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -72,9 +71,13 @@ public class StartScreenController implements Initializable {
} }
/** /**
* Running a timer to update the livestream status on welcome screen. Update interval is 1 second. * Running a timer to update the livestream status on welcome screen. Update interval is 1
* second.
*/ */
public void startStream() { public void startStream() {
// reset boolean for switch to race view
switchedToRaceView = false;
if (StreamParser.isStreamStatus()) { if (StreamParser.isStreamStatus()) {
streamButton.setVisible(false); streamButton.setVisible(false);
realTime.setVisible(true); realTime.setVisible(true);
@@ -102,8 +105,10 @@ public class StartScreenController implements Initializable {
updateTeamList(); updateTeamList();
timeTillLive.setTextFill(Color.RED); timeTillLive.setTextFill(Color.RED);
switchToRaceViewButton.setDisable(false); switchToRaceViewButton.setDisable(false);
String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60); String timerMinute = Long
String timerSecond = Long.toString(StreamParser.getTimeSinceStart() % 60); .toString(StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long
.toString(StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) { if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond; timerSecond = "0" + timerSecond;
} }
@@ -114,8 +119,10 @@ public class StartScreenController implements Initializable {
updateTeamList(); updateTeamList();
timeTillLive.setTextFill(Color.BLACK); timeTillLive.setTextFill(Color.BLACK);
switchToRaceViewButton.setDisable(false); switchToRaceViewButton.setDisable(false);
String timerMinute = Long.toString(-1 * StreamParser.getTimeSinceStart() / 60); String timerMinute = Long
String timerSecond = Long.toString(-1 * StreamParser.getTimeSinceStart() % 60); .toString(-1 * StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long
.toString(-1 * StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) { if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond; timerSecond = "0" + timerSecond;
} }
@@ -3,10 +3,9 @@
<?import javafx.geometry.*?> <?import javafx.geometry.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<GridPane fx:id="finishScreenGridPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" nodeOrientation="LEFT_TO_RIGHT" prefHeight="837.0" prefWidth="800.0" style="-fx-background-color: #2C2c36;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <GridPane fx:id="finishScreenGridPane" nodeOrientation="LEFT_TO_RIGHT" prefWidth="800.0" style="-fx-background-color: #2C2c36;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.FinishScreenViewController">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints> </columnConstraints>