mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Several tweaks and improvements to a annotations and other visual aspects of them program. Fixed bug causing minimization crashes.
#implement #refactor #issue[23]
This commit is contained in:
@@ -63,8 +63,8 @@ public class App extends Application {
|
|||||||
//Change the StreamReceiver in this else block to change the default data source.
|
//Change the StreamReceiver in this else block to change the default data source.
|
||||||
else{
|
else{
|
||||||
// sr = new StreamReceiver("localhost", 4949, "RaceStream");
|
// sr = new StreamReceiver("localhost", 4949, "RaceStream");
|
||||||
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
|
// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
|
||||||
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
|
sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
|
||||||
}
|
}
|
||||||
|
|
||||||
sr.start();
|
sr.start();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import javafx.scene.canvas.Canvas;
|
|||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.shape.Polygon;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import seng302.fxObjects.BoatGroup;
|
import seng302.fxObjects.BoatGroup;
|
||||||
import seng302.models.Colors;
|
import seng302.models.Colors;
|
||||||
@@ -65,6 +66,7 @@ public class CanvasController {
|
|||||||
private List<MarkGroup> markGroups = new ArrayList<>();
|
private List<MarkGroup> markGroups = new ArrayList<>();
|
||||||
private List<BoatGroup> boatGroups = new ArrayList<>();
|
private List<BoatGroup> boatGroups = new ArrayList<>();
|
||||||
private Text FPSdisplay = new Text();
|
private Text FPSdisplay = new Text();
|
||||||
|
private Polygon raceBorder = new Polygon();
|
||||||
|
|
||||||
//FRAME RATE
|
//FRAME RATE
|
||||||
private Double frameRate = 60.0;
|
private Double frameRate = 60.0;
|
||||||
@@ -107,6 +109,7 @@ public class CanvasController {
|
|||||||
FPSdisplay.setLayoutY(20);
|
FPSdisplay.setLayoutY(20);
|
||||||
FPSdisplay.setStrokeWidth(2);
|
FPSdisplay.setStrokeWidth(2);
|
||||||
group.getChildren().add(FPSdisplay);
|
group.getChildren().add(FPSdisplay);
|
||||||
|
group.getChildren().add(raceBorder);
|
||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
@@ -114,10 +117,15 @@ public class CanvasController {
|
|||||||
initializeMarks();
|
initializeMarks();
|
||||||
timer = new AnimationTimer() {
|
timer = new AnimationTimer() {
|
||||||
|
|
||||||
|
private long lastTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
|
|
||||||
//fps stuff
|
//fps stuff
|
||||||
|
if (lastTime == 0) {
|
||||||
|
lastTime = now;
|
||||||
|
} else {
|
||||||
|
if (now - lastTime >= (1e8 / 60)) { //Fix for framerate going above 60 when minimized
|
||||||
long oldFrameTime = frameTimes[frameTimeIndex] ;
|
long oldFrameTime = frameTimes[frameTimeIndex] ;
|
||||||
frameTimes[frameTimeIndex] = now ;
|
frameTimes[frameTimeIndex] = now ;
|
||||||
frameTimeIndex = (frameTimeIndex + 1) % frameTimes.length ;
|
frameTimeIndex = (frameTimeIndex + 1) % frameTimes.length ;
|
||||||
@@ -131,13 +139,13 @@ public class CanvasController {
|
|||||||
frameRate = 1_000_000_000.0 / elapsedNanosPerFrame ;
|
frameRate = 1_000_000_000.0 / elapsedNanosPerFrame ;
|
||||||
drawFps(frameRate.intValue());
|
drawFps(frameRate.intValue());
|
||||||
}
|
}
|
||||||
|
updateGroups(frameRate);
|
||||||
// TODO: 1/05/17 cir27 - Make the RaceObjects update on the actual delay.
|
|
||||||
elapsedNanos = 1000 / 60;
|
|
||||||
updateGroups();
|
|
||||||
if (StreamParser.isRaceFinished()) {
|
if (StreamParser.isRaceFinished()) {
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
lastTime = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -153,37 +161,19 @@ public class CanvasController {
|
|||||||
private void addRaceBorder() {
|
private void addRaceBorder() {
|
||||||
XMLParser.RaceXMLObject raceXMLObject = StreamParser.getXmlObject().getRaceXML();
|
XMLParser.RaceXMLObject raceXMLObject = StreamParser.getXmlObject().getRaceXML();
|
||||||
ArrayList<Limit> courseLimits = raceXMLObject.getCourseLimit();
|
ArrayList<Limit> courseLimits = raceXMLObject.getCourseLimit();
|
||||||
gc.setStroke(Color.DARKBLUE);
|
raceBorder.setStroke(new Color(0.0f, 0.0f, 0.74509807f, 1));
|
||||||
gc.setLineWidth(3);
|
raceBorder.setStrokeWidth(3);
|
||||||
double[] xBoundaryPoints = new double[courseLimits.size()];
|
raceBorder.setFill(new Color(0,0,0,0));
|
||||||
double[] yBoundaryPoints = new double[courseLimits.size()];
|
List<Double> boundaryPoints = new ArrayList<>();
|
||||||
for (int i = 0; i < courseLimits.size() - 1; i++) {
|
for (Limit limit : courseLimits) {
|
||||||
Limit thisPoint1 = courseLimits.get(i);
|
Point2D location = findScaledXY(limit.getLat(), limit.getLng());
|
||||||
SingleMark thisMark1 = new SingleMark("", thisPoint1.getLat(), thisPoint1.getLng(), thisPoint1.getSeqID());
|
boundaryPoints.add(location.getX());
|
||||||
Limit thisPoint2 = courseLimits.get(i+1);
|
boundaryPoints.add(location.getY());
|
||||||
SingleMark thisMark2 = new SingleMark("", thisPoint2.getLat(), thisPoint2.getLng(), thisPoint2.getSeqID());
|
|
||||||
Point2D borderPoint1 = findScaledXY(thisMark1);
|
|
||||||
Point2D borderPoint2 = findScaledXY(thisMark2);
|
|
||||||
gc.strokeLine(borderPoint1.getX(), borderPoint1.getY(),
|
|
||||||
borderPoint2.getX(), borderPoint2.getY());
|
|
||||||
xBoundaryPoints[i] = borderPoint1.getX();
|
|
||||||
yBoundaryPoints[i] = borderPoint1.getY();
|
|
||||||
}
|
}
|
||||||
Limit thisPoint1 = courseLimits.get(courseLimits.size()-1);
|
raceBorder.getPoints().setAll(boundaryPoints);
|
||||||
SingleMark thisMark1 = new SingleMark("", thisPoint1.getLat(), thisPoint1.getLng(), thisPoint1.getSeqID());
|
|
||||||
Limit thisPoint2 = courseLimits.get(0);
|
|
||||||
SingleMark thisMark2 = new SingleMark("", thisPoint2.getLat(), thisPoint2.getLng(), thisPoint2.getSeqID());
|
|
||||||
Point2D borderPoint1 = findScaledXY(thisMark1);
|
|
||||||
Point2D borderPoint2 = findScaledXY(thisMark2);
|
|
||||||
gc.strokeLine(borderPoint1.getX(), borderPoint1.getY(),
|
|
||||||
borderPoint2.getX(), borderPoint2.getY());
|
|
||||||
xBoundaryPoints[courseLimits.size()-1] = borderPoint1.getX();
|
|
||||||
yBoundaryPoints[courseLimits.size()-1] = borderPoint1.getY();
|
|
||||||
gc.setFill(Color.LIGHTBLUE);
|
|
||||||
gc.fillPolygon(xBoundaryPoints,yBoundaryPoints,yBoundaryPoints.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGroups(){
|
private void updateGroups(double frameRate){
|
||||||
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
|
||||||
|
|||||||
@@ -327,76 +327,31 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
|||||||
return displayFps;
|
return displayFps;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the important annotations for a specific BoatGroup
|
|
||||||
* @param bg The boat group to set the annotations for
|
|
||||||
*/
|
|
||||||
private void setBoatGroupImportantAnnotations(BoatGroup bg) {
|
|
||||||
if (importantAnnotations.getAnnotationState(Annotation.NAME)) {
|
|
||||||
bg.setTeamNameObjectVisible(true);
|
|
||||||
} else {
|
|
||||||
bg.setTeamNameObjectVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (importantAnnotations.getAnnotationState(Annotation.SPEED)) {
|
|
||||||
bg.setVelocityObjectVisible(true);
|
|
||||||
} else {
|
|
||||||
bg.setVelocityObjectVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (importantAnnotations.getAnnotationState(Annotation.TRACK)) {
|
|
||||||
bg.setLineGroupVisible(true);
|
|
||||||
} else {
|
|
||||||
bg.setLineGroupVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (importantAnnotations.getAnnotationState(Annotation.WAKE)) {
|
|
||||||
bg.setWakeVisible(true);
|
|
||||||
} else {
|
|
||||||
bg.setWakeVisible(false);
|
|
||||||
}
|
|
||||||
//TODO fix boat annotations with new boatgroup
|
|
||||||
if (importantAnnotations.getAnnotationState(Annotation.ESTTIMETONEXTMARK)) {
|
|
||||||
bg.setEstTimeToNextMarkObjectVisible(true);
|
|
||||||
} else {
|
|
||||||
bg.setEstTimeToNextMarkObjectVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (importantAnnotations.getAnnotationState(Annotation.LEGTIME)) {
|
|
||||||
bg.setLegTimeObjectVisible(true);
|
|
||||||
} else {
|
|
||||||
bg.setLegTimeObjectVisible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setAnnotations(Integer annotationLevel) {
|
private void setAnnotations(Integer annotationLevel) {
|
||||||
switch (annotationLevel) {
|
switch (annotationLevel) {
|
||||||
// No Annotations
|
// No Annotations
|
||||||
case 0:
|
case 0:
|
||||||
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
|
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
|
||||||
bg.setTeamNameObjectVisible(false);
|
bg.setVisibility(false, false, false, false, false, false);
|
||||||
bg.setVelocityObjectVisible(false);
|
|
||||||
bg.setEstTimeToNextMarkObjectVisible(false);
|
|
||||||
bg.setLegTimeObjectVisible(false);
|
|
||||||
bg.setLineGroupVisible(false);
|
|
||||||
bg.setWakeVisible(false);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Important Annotations
|
// Important Annotations
|
||||||
case 1:
|
case 1:
|
||||||
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
|
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
|
||||||
setBoatGroupImportantAnnotations(bg);
|
bg.setVisibility(
|
||||||
|
importantAnnotations.getAnnotationState(Annotation.NAME),
|
||||||
|
importantAnnotations.getAnnotationState(Annotation.SPEED),
|
||||||
|
importantAnnotations.getAnnotationState(Annotation.ESTTIMETONEXTMARK),
|
||||||
|
importantAnnotations.getAnnotationState(Annotation.LEGTIME),
|
||||||
|
importantAnnotations.getAnnotationState(Annotation.TRACK),
|
||||||
|
importantAnnotations.getAnnotationState(Annotation.WAKE)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// All Annotations
|
// All Annotations
|
||||||
case 2:
|
case 2:
|
||||||
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
|
for (BoatGroup bg : includedCanvasController.getBoatGroups()) {
|
||||||
bg.setTeamNameObjectVisible(true);
|
bg.setVisibility(true, true, true, true, true, true);
|
||||||
bg.setVelocityObjectVisible(true);
|
|
||||||
bg.setEstTimeToNextMarkObjectVisible(true);
|
|
||||||
bg.setLegTimeObjectVisible(true);
|
|
||||||
bg.setLineGroupVisible(true);
|
|
||||||
bg.setWakeVisible(true);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import javafx.scene.Group;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
import seng302.controllers.annotations.Annotation;
|
||||||
import seng302.models.Yacht;
|
import seng302.models.Yacht;
|
||||||
import seng302.models.stream.StreamParser;
|
import seng302.models.stream.StreamParser;
|
||||||
|
|
||||||
@@ -12,81 +13,56 @@ import java.text.DateFormat;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by cir27 on 23/05/17.
|
* Collection of annotations for boats.
|
||||||
*/
|
*/
|
||||||
public class BoatAnnotations extends Group{
|
class BoatAnnotations extends Group{
|
||||||
|
|
||||||
private static final double TEAMNAME_X_OFFSET = 18d;
|
//Text offset constants
|
||||||
private static final double TEAMNAME_Y_OFFSET = -29d;
|
private static final double X_OFFSET_TEXT = 18d;
|
||||||
private static final double VELOCITY_X_OFFSET = 18d;
|
private static final double Y_OFFSET_TEXT_INIT = -29d;
|
||||||
private static final double VELOCITY_Y_OFFSET = -17d;
|
private static final double Y_OFFSET_PER_TEXT = 12d;
|
||||||
private static final double ESTTIMETONEXTMARK_X_OFFSET = 18d;
|
//Background constants
|
||||||
private static final double ESTTIMETONEXTMARK_Y_OFFSET = -5d;
|
private static final double TEXT_BUFFER = 3;
|
||||||
private static final double LEGTIME_X_OFFSET = 18d;
|
private static final double BACKGROUND_X = X_OFFSET_TEXT - TEXT_BUFFER;
|
||||||
private static final double LEGTIME_Y_OFFSET = 7d;
|
private static final double BACKGROUND_Y = Y_OFFSET_TEXT_INIT - TEXT_BUFFER;
|
||||||
|
private static final double BACKGROUND_H_PER_TEXT = 9.5d;
|
||||||
|
private static final double BACKGROUND_W = 125d;
|
||||||
|
private static final double BACKGROUND_ARC_SIZE = 10;
|
||||||
|
|
||||||
private Rectangle background = new Rectangle();
|
private Rectangle background = new Rectangle();
|
||||||
private Text teamNameObject;
|
private Text teamNameObject;
|
||||||
private Text velocityObject;
|
private Text velocityObject;
|
||||||
private Text estTimeToNextMarkObject;
|
private Text estTimeToNextMarkObject;
|
||||||
private Text legTimeObject;
|
private Text legTimeObject;
|
||||||
private Long lastMarkTime;
|
|
||||||
|
|
||||||
public enum Annotations {
|
private Yacht boat;
|
||||||
TEAM_NAME,
|
|
||||||
VELOCITY_OBJECT,
|
|
||||||
TTNEXT,
|
|
||||||
LEG_TIME,
|
|
||||||
}
|
|
||||||
|
|
||||||
BoatAnnotations (Yacht boat, Color theme) {
|
BoatAnnotations (Yacht boat, Color theme) {
|
||||||
super.setCache(true);
|
super.setCache(true);
|
||||||
background.setX(15d);
|
this.boat = boat;
|
||||||
background.setY(-32d);
|
background.setX(BACKGROUND_X);
|
||||||
background.setWidth(150);
|
background.setY(BACKGROUND_Y);
|
||||||
background.setHeight(55);
|
background.setWidth(BACKGROUND_W);
|
||||||
background.setArcHeight(10);
|
background.setHeight(Math.abs(BACKGROUND_X) + TEXT_BUFFER + BACKGROUND_H_PER_TEXT * 4);
|
||||||
background.setArcWidth(10);
|
background.setArcHeight(BACKGROUND_ARC_SIZE);
|
||||||
background.setFill(new Color(1, 1, 1, 0.35));
|
background.setArcWidth(BACKGROUND_ARC_SIZE);
|
||||||
|
background.setFill(new Color(1, 1, 1, 0.5));
|
||||||
background.setStroke(theme);
|
background.setStroke(theme);
|
||||||
background.setStrokeWidth(2);
|
background.setStrokeWidth(2);
|
||||||
background.setCache(true);
|
background.setCache(true);
|
||||||
background.setCacheHint(CacheHint.SPEED);
|
background.setCacheHint(CacheHint.SPEED);
|
||||||
|
|
||||||
teamNameObject = getTextObject(boat.getShortName(), theme);
|
teamNameObject = getTextObject(boat.getShortName(), theme);
|
||||||
teamNameObject.relocate(TEAMNAME_X_OFFSET, TEAMNAME_Y_OFFSET);
|
teamNameObject.relocate(X_OFFSET_TEXT, Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT);
|
||||||
|
|
||||||
velocityObject = getTextObject("", theme);
|
velocityObject = getTextObject("0 m/s", theme);
|
||||||
velocityObject.relocate(VELOCITY_X_OFFSET, VELOCITY_Y_OFFSET);
|
velocityObject.relocate(X_OFFSET_TEXT, Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT * 2);
|
||||||
//On change listener
|
|
||||||
boat.getReadOnlyVelocityProperty().addListener((obs, oldVal, newVal) ->
|
|
||||||
velocityObject.setText(String.format("%.2f m/s", newVal.doubleValue()))
|
|
||||||
);
|
|
||||||
//Invalidation listener
|
|
||||||
boat.getReadOnlyVelocityProperty().addListener(obs ->
|
|
||||||
velocityObject.setText("")
|
|
||||||
);
|
|
||||||
|
|
||||||
estTimeToNextMarkObject = getTextObject("Next mark: ", theme);
|
estTimeToNextMarkObject = getTextObject("Next mark: ", theme);
|
||||||
estTimeToNextMarkObject.relocate(ESTTIMETONEXTMARK_X_OFFSET, ESTTIMETONEXTMARK_Y_OFFSET);
|
estTimeToNextMarkObject.relocate(X_OFFSET_TEXT, Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT * 3);
|
||||||
boat.getReadOnlyNextMarkProperty().addListener((obs, oldVal, newVal) -> {
|
|
||||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
|
||||||
String timeToNextMark = format
|
|
||||||
.format(newVal.longValue() - StreamParser.getCurrentTimeLong());
|
|
||||||
estTimeToNextMarkObject.setText("Next mark: " + timeToNextMark);
|
|
||||||
});
|
|
||||||
boat.getReadOnlyNextMarkProperty().addListener(obs ->
|
|
||||||
estTimeToNextMarkObject.setText("Next mark: - ")
|
|
||||||
);
|
|
||||||
|
|
||||||
legTimeObject = getTextObject("Last mark: -", theme);
|
legTimeObject = getTextObject("Last mark: -", theme);
|
||||||
legTimeObject.relocate(LEGTIME_X_OFFSET, LEGTIME_Y_OFFSET);
|
legTimeObject.relocate(X_OFFSET_TEXT, Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT * 4);
|
||||||
boat.getReadOnlyMarkRoundingProperty().addListener((obs, oldTime, newTime) -> {
|
|
||||||
lastMarkTime = newTime.longValue();
|
|
||||||
});
|
|
||||||
boat.getReadOnlyMarkRoundingProperty().addListener(obs ->
|
|
||||||
legTimeObject.setText("Last mark: - ")
|
|
||||||
);
|
|
||||||
|
|
||||||
super.getChildren().addAll(background, teamNameObject, velocityObject, estTimeToNextMarkObject, legTimeObject);
|
super.getChildren().addAll(background, teamNameObject, velocityObject, estTimeToNextMarkObject, legTimeObject);
|
||||||
}
|
}
|
||||||
@@ -106,30 +82,52 @@ public class BoatAnnotations extends Group{
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTeamNameObjectVisible(Boolean visible) {
|
void update () {
|
||||||
teamNameObject.setVisible(visible);
|
velocityObject.setText(String.format(String.format("%.2f m/s", boat.getVelocity())));
|
||||||
|
|
||||||
|
if (boat.getTimeTillNext() != null) {
|
||||||
|
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||||
|
String timeToNextMark = format
|
||||||
|
.format(boat.getTimeTillNext() - StreamParser.getCurrentTimeLong());
|
||||||
|
estTimeToNextMarkObject.setText("Next mark: " + timeToNextMark);
|
||||||
|
} else {
|
||||||
|
estTimeToNextMarkObject.setText("Next mark: -");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVelocityObjectVisible(Boolean visible) {
|
if (boat.getMarkRoundTime() != null) {
|
||||||
velocityObject.setVisible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEstTimeToNextMarkObjectVisible(Boolean visible) {
|
|
||||||
estTimeToNextMarkObject.setVisible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLegTimeObjectVisible(Boolean visible) {
|
|
||||||
legTimeObject.setVisible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update () {
|
|
||||||
if (lastMarkTime != null) {
|
|
||||||
DateFormat format = new SimpleDateFormat("mm:ss");
|
DateFormat format = new SimpleDateFormat("mm:ss");
|
||||||
String elapsedTime = format
|
String elapsedTime = format
|
||||||
.format(StreamParser.getCurrentTimeLong() - lastMarkTime);
|
.format(StreamParser.getCurrentTimeLong() - boat.getMarkRoundTime());
|
||||||
legTimeObject.setText("Last mark: " + elapsedTime);
|
legTimeObject.setText("Last mark: " + elapsedTime);
|
||||||
}else {
|
}else {
|
||||||
legTimeObject.setText("Last mark: - ");
|
legTimeObject.setText("Last mark: - ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setVisibile (boolean nameVisibility, boolean speedVisibility,
|
||||||
|
boolean estTimeVisibility, boolean lastMarkVisibility) {
|
||||||
|
int totalVisible = 0;
|
||||||
|
totalVisible = updateVisibility(nameVisibility, teamNameObject, totalVisible);
|
||||||
|
totalVisible = updateVisibility(speedVisibility, velocityObject, totalVisible);
|
||||||
|
totalVisible = updateVisibility(estTimeVisibility, estTimeToNextMarkObject, totalVisible);
|
||||||
|
totalVisible = updateVisibility(lastMarkVisibility, legTimeObject, totalVisible);
|
||||||
|
if (totalVisible != 0) {
|
||||||
|
background.setVisible(true);
|
||||||
|
background.setHeight(Math.abs(BACKGROUND_X) + TEXT_BUFFER + BACKGROUND_H_PER_TEXT * totalVisible);
|
||||||
|
} else {
|
||||||
|
background.setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int updateVisibility (boolean visibility, Text text, int totalVisible) {
|
||||||
|
if (visibility){
|
||||||
|
totalVisible ++;
|
||||||
|
text.setVisible(true);
|
||||||
|
text.setLayoutX(X_OFFSET_TEXT);
|
||||||
|
text.setLayoutY(Y_OFFSET_TEXT_INIT + Y_OFFSET_PER_TEXT * totalVisible);
|
||||||
|
} else {
|
||||||
|
text.setVisible(false);
|
||||||
|
}
|
||||||
|
return totalVisible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,13 +47,9 @@ public class BoatGroup extends Group {
|
|||||||
private Double distanceTravelled = 0.0;
|
private Double distanceTravelled = 0.0;
|
||||||
private Point2D lastPoint;
|
private Point2D lastPoint;
|
||||||
private boolean destinationSet;
|
private boolean destinationSet;
|
||||||
private Color textColor = Color.RED;
|
private BoatAnnotations boatAnnotations;;
|
||||||
private double rotationalVelocity;
|
|
||||||
private double rotation;
|
|
||||||
|
|
||||||
private BoatAnnotations boatAnnotations;
|
private Boolean isSelected = true; //All boats are initialised as selected
|
||||||
|
|
||||||
private Boolean isSelected = true; //All boats are initalised as selected
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a BoatGroup with the default triangular boat polygon.
|
* Creates a BoatGroup with the default triangular boat polygon.
|
||||||
@@ -63,9 +59,9 @@ public class BoatGroup extends Group {
|
|||||||
* @param color The colour of the boat polygon and the trailing line.
|
* @param color The colour of the boat polygon and the trailing line.
|
||||||
*/
|
*/
|
||||||
public BoatGroup(Yacht boat, Color color) {
|
public BoatGroup(Yacht boat, Color color) {
|
||||||
|
destinationSet = false;
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
initChildren(color);
|
initChildren(color);
|
||||||
this.textColor = color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,27 +75,11 @@ public class BoatGroup extends Group {
|
|||||||
* polygon.
|
* polygon.
|
||||||
*/
|
*/
|
||||||
public BoatGroup(Yacht boat, Color color, double... points) {
|
public BoatGroup(Yacht boat, Color color, double... points) {
|
||||||
|
destinationSet = false;
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
initChildren(color, points);
|
initChildren(color, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Return a text object with caching and a color applied
|
|
||||||
// *
|
|
||||||
// * @param defaultText The default text to display
|
|
||||||
// * @param fill The text fill color
|
|
||||||
// * @return The text object
|
|
||||||
// */
|
|
||||||
// private Text getTextObject(String defaultText, Color fill) {
|
|
||||||
// Text text = new Text(defaultText);
|
|
||||||
//
|
|
||||||
// text.setFill(fill);
|
|
||||||
// text.setCacheHint(CacheHint.SPEED);
|
|
||||||
// text.setCache(true);
|
|
||||||
//
|
|
||||||
// return text;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the javafx objects that will be the in the group by default.
|
* Creates the javafx objects that will be the in the group by default.
|
||||||
*
|
*
|
||||||
@@ -108,9 +88,6 @@ public class BoatGroup extends Group {
|
|||||||
* polygon.
|
* polygon.
|
||||||
*/
|
*/
|
||||||
private void initChildren(Color color, double... points) {
|
private void initChildren(Color color, double... points) {
|
||||||
textColor = color;
|
|
||||||
destinationSet = false;
|
|
||||||
|
|
||||||
boatPoly = new Polygon(points);
|
boatPoly = new Polygon(points);
|
||||||
boatPoly.setFill(color);
|
boatPoly.setFill(color);
|
||||||
boatPoly.setOnMouseEntered(event -> {
|
boatPoly.setOnMouseEntered(event -> {
|
||||||
@@ -125,7 +102,6 @@ public class BoatGroup extends Group {
|
|||||||
boatPoly.setCache(true);
|
boatPoly.setCache(true);
|
||||||
boatPoly.setCacheHint(CacheHint.SPEED);
|
boatPoly.setCacheHint(CacheHint.SPEED);
|
||||||
boatAnnotations = new BoatAnnotations(boat, color);
|
boatAnnotations = new BoatAnnotations(boat, color);
|
||||||
|
|
||||||
wake = new Wake(0, -BOAT_HEIGHT);
|
wake = new Wake(0, -BOAT_HEIGHT);
|
||||||
super.getChildren().addAll(boatPoly, boatAnnotations);
|
super.getChildren().addAll(boatPoly, boatAnnotations);
|
||||||
}
|
}
|
||||||
@@ -171,58 +147,16 @@ public class BoatGroup extends Group {
|
|||||||
boatPoly.setLayoutY(y);
|
boatPoly.setLayoutY(y);
|
||||||
boatAnnotations.setLayoutX(x);
|
boatAnnotations.setLayoutX(x);
|
||||||
boatAnnotations.setLayoutY(y);
|
boatAnnotations.setLayoutY(y);
|
||||||
// int i = 0;
|
|
||||||
// for (Node n : boatAnnotations.getkiddies()) {
|
|
||||||
// n.setLayoutX(x + 10 + i);
|
|
||||||
// n.setLayoutY(y + 10 + i);
|
|
||||||
// i += 10;
|
|
||||||
// }
|
|
||||||
wake.setLayoutX(x);
|
wake.setLayoutX(x);
|
||||||
wake.setLayoutY(y);
|
wake.setLayoutY(y);
|
||||||
wake.rotate(rotation);
|
wake.rotate(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rotateTo(double rotation) {
|
private void rotateTo(double rotation) {
|
||||||
this.rotation = rotation;
|
|
||||||
boatPoly.getTransforms().setAll(new Rotate(rotation));
|
boatPoly.getTransforms().setAll(new Rotate(rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Updates the time until next mark label, will create a label if one doesn't exist
|
|
||||||
// */
|
|
||||||
// private void updateTimeTillNextMark() {
|
|
||||||
// if (estTimeToNextMarkObject == null) {
|
|
||||||
// estTimeToNextMarkObject = getTextObject("Next mark: -", textColor);
|
|
||||||
// }
|
|
||||||
// if (boat.getEstimateTimeAtNextMark() != null) {
|
|
||||||
// DateFormat format = new SimpleDateFormat("mm:ss");
|
|
||||||
// String timeToNextMark = format
|
|
||||||
// .format(boat.getEstimateTimeAtNextMark() - StreamParser.getCurrentTimeLong());
|
|
||||||
// estTimeToNextMarkObject.setText("Next mark: " + timeToNextMark);
|
|
||||||
// } else {
|
|
||||||
// estTimeToNextMarkObject.setText("Next mark: -");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Updates the time since last mark rounding, will create a label if one doesn't exist
|
|
||||||
// */
|
|
||||||
// private void updateLastMarkRoundingTime() {
|
|
||||||
// if (legTimeObject == null) {
|
|
||||||
// legTimeObject = getTextObject("Last mark: -", textColor);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (boat.getMarkRoundingTime() != null) {
|
|
||||||
// DateFormat format = new SimpleDateFormat("mm:ss");
|
|
||||||
// String elapsedTime = format
|
|
||||||
// .format(StreamParser.getCurrentTimeLong() - boat.getMarkRoundingTime());
|
|
||||||
// legTimeObject.setText("Last mark: " + elapsedTime);
|
|
||||||
// } else {
|
|
||||||
// legTimeObject.setText("Last mark: -");
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void move() {
|
public void move() {
|
||||||
double dx = xIncrement * framesToMove;
|
double dx = xIncrement * framesToMove;
|
||||||
double dy = yIncrement * framesToMove;
|
double dy = yIncrement * framesToMove;
|
||||||
@@ -256,8 +190,7 @@ public class BoatGroup extends Group {
|
|||||||
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
lastPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rotateTo(rotation + rotationalVelocity * 1000 / 60);
|
wake.updatePosition();
|
||||||
wake.updatePosition(1000 / 60);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,19 +235,9 @@ public class BoatGroup extends Group {
|
|||||||
|
|
||||||
destinationSet = true;
|
destinationSet = true;
|
||||||
|
|
||||||
rotationalVelocity = calculateRotationalVelocity(rotation);
|
rotateTo(rotation);
|
||||||
|
wake.setRotation(rotation, groundSpeed);
|
||||||
// updateTimeTillNextMark();
|
|
||||||
// updateLastMarkRoundingTime();
|
|
||||||
|
|
||||||
if (Math.abs(rotationalVelocity) > 0.075) {
|
|
||||||
rotationalVelocity = 0.0;
|
|
||||||
wake.rotate(rotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
//rotateTo(rotation);
|
|
||||||
boat.setVelocity(groundSpeed);
|
boat.setVelocity(groundSpeed);
|
||||||
wake.setRotationalVelocity(rotationalVelocity, groundSpeed);
|
|
||||||
lastTimeValid = timeValid;
|
lastTimeValid = timeValid;
|
||||||
isStopped = false;
|
isStopped = false;
|
||||||
lastRotation = rotation;
|
lastRotation = rotation;
|
||||||
@@ -324,30 +247,15 @@ public class BoatGroup extends Group {
|
|||||||
|
|
||||||
public void setIsSelected(Boolean isSelected) {
|
public void setIsSelected(Boolean isSelected) {
|
||||||
this.isSelected = isSelected;
|
this.isSelected = isSelected;
|
||||||
setTeamNameObjectVisible(isSelected);
|
|
||||||
setVelocityObjectVisible(isSelected);
|
|
||||||
setLineGroupVisible(isSelected);
|
setLineGroupVisible(isSelected);
|
||||||
setWakeVisible(isSelected);
|
setWakeVisible(isSelected);
|
||||||
setEstTimeToNextMarkObjectVisible(isSelected);
|
|
||||||
setLegTimeObjectVisible(isSelected);
|
|
||||||
boatAnnotations.setVisible(isSelected);
|
boatAnnotations.setVisible(isSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setVisibility (boolean teamName, boolean velocity, boolean estTime, boolean legTime, boolean trail, boolean wake) {
|
||||||
public void setTeamNameObjectVisible(Boolean visible) {
|
boatAnnotations.setVisibile(teamName, velocity, estTime, legTime);
|
||||||
boatAnnotations.setTeamNameObjectVisible(visible);
|
this.wake.setVisible(wake);
|
||||||
}
|
this.lineGroup.setVisible(trail);
|
||||||
|
|
||||||
public void setVelocityObjectVisible(Boolean visible) {
|
|
||||||
boatAnnotations.setVelocityObjectVisible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEstTimeToNextMarkObjectVisible(Boolean visible) {
|
|
||||||
boatAnnotations.setEstTimeToNextMarkObjectVisible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLegTimeObjectVisible(Boolean visible) {
|
|
||||||
boatAnnotations.setLegTimeObjectVisible(visible);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLineGroupVisible(Boolean visible) {
|
public void setLineGroupVisible(Boolean visible) {
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ public class MarkGroup extends Group {
|
|||||||
{
|
{
|
||||||
if (mainMark.getMarkType() == MarkType.SINGLE_MARK) {
|
if (mainMark.getMarkType() == MarkType.SINGLE_MARK) {
|
||||||
Circle markCircle = (Circle) super.getChildren().get(0);
|
Circle markCircle = (Circle) super.getChildren().get(0);
|
||||||
|
//One of the test streams produced frequent, jittery movements. Added this as a fix.
|
||||||
if (Math.abs(markCircle.getCenterX() - x) > 5 || Math.abs(markCircle.getCenterY() - y) > 5) {
|
if (Math.abs(markCircle.getCenterX() - x) > 5 || Math.abs(markCircle.getCenterY() - y) > 5) {
|
||||||
markCircle.setCenterX(x);
|
markCircle.setCenterX(x);
|
||||||
markCircle.setCenterY(y);
|
markCircle.setCenterY(y);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import javafx.scene.shape.Arc;
|
|||||||
import javafx.scene.shape.ArcType;
|
import javafx.scene.shape.ArcType;
|
||||||
import javafx.scene.shape.StrokeLineCap;
|
import javafx.scene.shape.StrokeLineCap;
|
||||||
import javafx.scene.transform.Rotate;
|
import javafx.scene.transform.Rotate;
|
||||||
|
import javafx.scene.transform.Scale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A group containing objects used to represent wakes onscreen. Contains functionality for their animation.
|
* A group containing objects used to represent wakes onscreen. Contains functionality for their animation.
|
||||||
@@ -18,13 +19,12 @@ class Wake extends Group {
|
|||||||
//The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less.
|
//The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less.
|
||||||
private final double MAX_DIFF = 75;
|
private final double MAX_DIFF = 75;
|
||||||
//Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation.
|
//Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation.
|
||||||
private final int UNIFICATION_SPEED = 750;
|
private final int UNIFICATION_SPEED = 45;
|
||||||
|
|
||||||
|
|
||||||
private Arc[] arcs = new Arc[numWakes];
|
private Arc[] arcs = new Arc[numWakes];
|
||||||
private double[] rotationalVelocities = new double[numWakes];
|
private double[] rotationalVelocities = new double[numWakes];
|
||||||
private double[] rotations = new double[numWakes];
|
private double[] rotations = new double[numWakes];
|
||||||
private double baseRad;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a wake at the given location.
|
* Create a wake at the given location.
|
||||||
@@ -40,26 +40,26 @@ class Wake extends Group {
|
|||||||
//Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg.
|
//Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg.
|
||||||
arc = new Arc(0, 0, 0, 0, -110, 40);
|
arc = new Arc(0, 0, 0, 0, -110, 40);
|
||||||
arc.setCache(true);
|
arc.setCache(true);
|
||||||
arc.setCacheHint(CacheHint.SCALE_AND_ROTATE);
|
arc.setCacheHint(CacheHint.ROTATE);
|
||||||
arc.setType(ArcType.OPEN);
|
arc.setType(ArcType.OPEN);
|
||||||
arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i)));
|
arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i)));
|
||||||
arc.setStrokeWidth(3.0);
|
arc.setStrokeWidth(3.0);
|
||||||
arc.setStrokeLineCap(StrokeLineCap.ROUND);
|
arc.setStrokeLineCap(StrokeLineCap.ROUND);
|
||||||
arc.setFill(new Color(0.0, 0.0, 0.0, 0.0));
|
arc.setFill(new Color(0.0, 0.0, 0.0, 0.0));
|
||||||
baseRad = (20 / numWakes);
|
|
||||||
arcs[i] = arc;
|
arcs[i] = arc;
|
||||||
|
arc.getTransforms().setAll(
|
||||||
|
new Rotate(1)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
super.getChildren().addAll(arcs);
|
super.getChildren().addAll(arcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void setRotation (double rotation, double velocity) {
|
||||||
* Sets the rotationalVelocity of each arc.
|
if (Math.abs(rotations[0] - rotation) > 20) {
|
||||||
*
|
rotate(rotation);
|
||||||
* @param rotationalVelocity The rotationalVelocity the wake should move at.
|
} else {
|
||||||
* @param velocity The real world velocity of the boat in m/s.
|
rotations[0] = rotation;
|
||||||
*/
|
((Rotate) arcs[0].getTransforms().get(0)).setAngle(rotation);
|
||||||
void setRotationalVelocity(double rotationalVelocity, double velocity) {
|
|
||||||
rotationalVelocities[0] = rotationalVelocity;
|
|
||||||
for (int i = 1; i < numWakes; i++) {
|
for (int i = 1; i < numWakes; i++) {
|
||||||
double wakeSeparationRad = Math.toRadians(rotations[i - 1] - rotations[i]);
|
double wakeSeparationRad = Math.toRadians(rotations[i - 1] - rotations[i]);
|
||||||
double shortestDistance = Math.atan2(
|
double shortestDistance = Math.atan2(
|
||||||
@@ -67,35 +67,33 @@ class Wake extends Group {
|
|||||||
Math.cos(wakeSeparationRad)
|
Math.cos(wakeSeparationRad)
|
||||||
);
|
);
|
||||||
double distDeg = Math.toDegrees(shortestDistance);
|
double distDeg = Math.toDegrees(shortestDistance);
|
||||||
|
|
||||||
if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) {
|
if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) {
|
||||||
rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * 2 * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (distDeg < (MAX_DIFF / numWakes))
|
if (distDeg < (MAX_DIFF / numWakes)) {
|
||||||
rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
|
||||||
else
|
} else
|
||||||
rotationalVelocities[i] = rotationalVelocities[i - 1];
|
rotationalVelocities[i] = rotationalVelocities[i - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double rad = baseRad + velocity;
|
double rad = (12 / numWakes) + velocity;
|
||||||
for (Arc arc : arcs) {
|
for (Arc arc : arcs) {
|
||||||
arc.setRadiusX(rad);
|
arc.setRadiusX(rad);
|
||||||
arc.setRadiusY(rad);
|
arc.setRadiusY(rad);
|
||||||
rad += (10 / numWakes) + (velocity / 2);
|
rad += (12 / numWakes) + (velocity / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arcs rotate based on the distance they would have travelled over the supplied time interval.
|
* Arcs rotate based on the distance they would have travelled over the supplied time interval.
|
||||||
*
|
|
||||||
* @param timeInterval the time interval, in microseconds, that the wake should move.
|
|
||||||
*/
|
*/
|
||||||
void updatePosition(long timeInterval) {
|
void updatePosition() {
|
||||||
for (int i = 0; i < numWakes; i++) {
|
for (int i = 0; i < numWakes; i++) {
|
||||||
rotations[i] = rotations[i] + rotationalVelocities[i] * timeInterval;
|
rotations[i] = rotations[i] + rotationalVelocities[i];
|
||||||
arcs[i].getTransforms().setAll(new Rotate(rotations[i]));
|
((Rotate) arcs[i].getTransforms().get(0)).setAngle(rotations[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
package seng302.models;
|
|
||||||
|
|
||||||
import javafx.animation.Timeline;
|
|
||||||
import javafx.beans.property.DoubleProperty;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by zyt10 on 17/03/17.
|
|
||||||
* this class is literally just to associate a timeline with a DoubleProperty x and y
|
|
||||||
*/
|
|
||||||
public class TimelineInfo {
|
|
||||||
private Timeline timeline;
|
|
||||||
private DoubleProperty x;
|
|
||||||
private DoubleProperty y;
|
|
||||||
|
|
||||||
public TimelineInfo(Timeline timeline, DoubleProperty x, DoubleProperty y) {
|
|
||||||
this.timeline = timeline;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Timeline getTimeline() {
|
|
||||||
return timeline;
|
|
||||||
}
|
|
||||||
public DoubleProperty getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
public DoubleProperty getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,237 +23,6 @@ public class Yacht {
|
|||||||
// Used in boat group
|
// Used in boat group
|
||||||
private Color colour;
|
private Color colour;
|
||||||
|
|
||||||
private DoubleProperty velocityProperty = new DoubleProperty() {
|
|
||||||
|
|
||||||
private ObservableValue<? extends Number> boundValue;
|
|
||||||
private List<ChangeListener> changeListeners = new ArrayList<>();
|
|
||||||
private List<InvalidationListener> invalidationListeners = new ArrayList<>();
|
|
||||||
private double velocity;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bind(ObservableValue<? extends Number> observable) {
|
|
||||||
boundValue = observable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unbind() {
|
|
||||||
boundValue = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBound() {
|
|
||||||
if (boundValue == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getBean() {
|
|
||||||
return Yacht.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "velocity property of " + boatName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get() {
|
|
||||||
return velocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addListener(ChangeListener<? super Number> listener) {
|
|
||||||
changeListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeListener(ChangeListener<? super Number> listener) {
|
|
||||||
changeListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addListener(InvalidationListener listener) {
|
|
||||||
invalidationListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeListener(InvalidationListener listener) {
|
|
||||||
invalidationListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set (double newVelocity) {
|
|
||||||
double oldVelocity = velocity;
|
|
||||||
velocity = newVelocity;
|
|
||||||
if (newVelocity >= 0)
|
|
||||||
for (ChangeListener cl : changeListeners) {
|
|
||||||
cl.changed(this, oldVelocity, newVelocity);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for (InvalidationListener il : invalidationListeners) {
|
|
||||||
il.invalidated(this);
|
|
||||||
}
|
|
||||||
if (isBound())
|
|
||||||
boundValue.notify();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private LongProperty timeAtNextProperty = new LongProperty() {
|
|
||||||
|
|
||||||
private ObservableValue<? extends Number> boundValue;
|
|
||||||
private List<ChangeListener> changeListeners = new ArrayList<>();
|
|
||||||
private List<InvalidationListener> invalidationListeners = new ArrayList<>();
|
|
||||||
private long estimate;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bind(ObservableValue<? extends Number> observable) {
|
|
||||||
boundValue = observable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unbind() {
|
|
||||||
boundValue = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBound() {
|
|
||||||
if (boundValue == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getBean() {
|
|
||||||
return Yacht.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "estimated time to next mark property of " + boatName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long get() {
|
|
||||||
return estimate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addListener(ChangeListener<? super Number> listener) {
|
|
||||||
changeListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeListener(ChangeListener<? super Number> listener) {
|
|
||||||
changeListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addListener(InvalidationListener listener) {
|
|
||||||
invalidationListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeListener(InvalidationListener listener) {
|
|
||||||
invalidationListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set (long newEstimate) {
|
|
||||||
long oldEstimate = estimate;
|
|
||||||
estimate = newEstimate;
|
|
||||||
if (newEstimate >= 0)
|
|
||||||
for (ChangeListener cl : changeListeners) {
|
|
||||||
cl.changed(this, oldEstimate, newEstimate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for (InvalidationListener il : invalidationListeners) {
|
|
||||||
il.invalidated(this);
|
|
||||||
}
|
|
||||||
if (isBound())
|
|
||||||
boundValue.notify();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private LongProperty markRoundingTimeProperty = new LongProperty() {
|
|
||||||
private ObservableValue<? extends Number> boundValue;
|
|
||||||
private List<ChangeListener> changeListeners = new ArrayList<>();
|
|
||||||
private List<InvalidationListener> invalidationListeners = new ArrayList<>();
|
|
||||||
private long roundingTime;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bind(ObservableValue<? extends Number> observable) {
|
|
||||||
boundValue = observable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unbind() {
|
|
||||||
boundValue = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBound() {
|
|
||||||
if (boundValue == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getBean() {
|
|
||||||
return Yacht.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "time from last mark property of " + boatName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long get() {
|
|
||||||
return roundingTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addListener(ChangeListener<? super Number> listener) {
|
|
||||||
changeListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeListener(ChangeListener<? super Number> listener) {
|
|
||||||
changeListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addListener(InvalidationListener listener) {
|
|
||||||
invalidationListeners.add(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeListener(InvalidationListener listener) {
|
|
||||||
invalidationListeners.remove(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set (long newTime) {
|
|
||||||
long oldTime = newTime;
|
|
||||||
roundingTime = newTime;
|
|
||||||
if (newTime >= 0)
|
|
||||||
for (ChangeListener cl : changeListeners) {
|
|
||||||
cl.changed(this, oldTime, newTime);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
for (InvalidationListener il : invalidationListeners) {
|
|
||||||
il.invalidated(this);
|
|
||||||
}
|
|
||||||
if (isBound())
|
|
||||||
boundValue.notify();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private String boatType;
|
private String boatType;
|
||||||
private Integer sourceID;
|
private Integer sourceID;
|
||||||
private String hullID; //matches HullNum in the XML spec.
|
private String hullID; //matches HullNum in the XML spec.
|
||||||
@@ -267,6 +36,10 @@ public class Yacht {
|
|||||||
private Integer penaltiesServed;
|
private Integer penaltiesServed;
|
||||||
private Long estimateTimeAtFinish;
|
private Long estimateTimeAtFinish;
|
||||||
private String position;
|
private String position;
|
||||||
|
private double velocity;
|
||||||
|
private Long timeTillNext;
|
||||||
|
private Long markRoundTime;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used in EventTest and RaceTest.
|
* Used in EventTest and RaceTest.
|
||||||
@@ -286,7 +59,7 @@ public class Yacht {
|
|||||||
*/
|
*/
|
||||||
public Yacht(String boatName, double boatVelocity, String shortName, int id) {
|
public Yacht(String boatName, double boatVelocity, String shortName, int id) {
|
||||||
this.boatName = boatName;
|
this.boatName = boatName;
|
||||||
this.velocityProperty.set(boatVelocity);
|
this.velocity = boatVelocity;
|
||||||
this.shortName = shortName;
|
this.shortName = shortName;
|
||||||
this.sourceID = id;
|
this.sourceID = id;
|
||||||
}
|
}
|
||||||
@@ -352,7 +125,7 @@ public class Yacht {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setEstimateTimeAtNextMark(Long estimateTimeAtNextMark) {
|
public void setEstimateTimeAtNextMark(Long estimateTimeAtNextMark) {
|
||||||
timeAtNextProperty.set(estimateTimeAtNextMark);
|
timeTillNext = estimateTimeAtNextMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEstimateTimeAtFinish() {
|
public String getEstimateTimeAtFinish() {
|
||||||
@@ -381,12 +154,24 @@ public class Yacht {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setVelocity(double velocity) {
|
public void setVelocity(double velocity) {
|
||||||
velocityProperty.set(velocity);
|
this.velocity = velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setMarkRoundingTime(Long markRoundingTime) {
|
public void setMarkRoundingTime(Long markRoundingTime) {
|
||||||
markRoundingTimeProperty.set(markRoundingTime);
|
this.markRoundTime = markRoundingTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getVelocity() {
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTimeTillNext() {
|
||||||
|
return timeTillNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getMarkRoundTime() {
|
||||||
|
return markRoundTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -394,15 +179,4 @@ public class Yacht {
|
|||||||
return boatName;
|
return boatName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReadOnlyDoubleProperty getReadOnlyVelocityProperty () {
|
|
||||||
return velocityProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReadOnlyLongProperty getReadOnlyNextMarkProperty() {
|
|
||||||
return timeAtNextProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReadOnlyLongProperty getReadOnlyMarkRoundingProperty() {
|
|
||||||
return markRoundingTimeProperty;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user