Adding race yacht series to the sparkline.

Next step is to make the series of the boats update when new position information is received.

#story[952]
This commit is contained in:
Kusal Ekanayake
2017-05-18 14:44:10 +12:00
parent b87008f590
commit 390aabc78f
4 changed files with 60 additions and 8 deletions
+32
View File
@@ -1,5 +1,9 @@
package seng302.models;
import java.util.concurrent.ConcurrentLinkedQueue;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.paint.Color;
import java.text.DateFormat;
@@ -16,6 +20,9 @@ public class Yacht {
private Color colour;
private double velocity;
private int index;
private ConcurrentLinkedQueue<Number> dataQ1;
private String boatType;
private Integer sourceID;
private String hullID; //matches HullNum in the XML spec.
@@ -33,6 +40,9 @@ public class Yacht {
// Mark rounding
private Long markRoundingTime;
// Used for sparkline
private XYChart.Series<Number, Number> sparklinePosition;
/**
* Used in EventTest and RaceTest.
*
@@ -54,6 +64,11 @@ public class Yacht {
this.velocity = boatVelocity;
this.shortName = shortName;
this.sourceID = id;
this.sparklinePosition = new XYChart.Series<>();
this.sparklinePosition.setName(boatName);
index = 0;
dataQ1 = new ConcurrentLinkedQueue<>();
}
public Yacht(String boatType, Integer sourceID, String hullID, String shortName, String boatName, String country) {
@@ -63,6 +78,10 @@ public class Yacht {
this.shortName = shortName;
this.boatName = boatName;
this.country = country;
this.sparklinePosition = new XYChart.Series<>();
this.sparklinePosition.setName(boatName);
index = 0;
dataQ1 = new ConcurrentLinkedQueue<>();
}
public String getBoatType() {
@@ -140,6 +159,15 @@ public class Yacht {
}
public void setPosition(String position) {
try {
if (Integer.parseInt(position) != Integer.parseInt(this.position)){
dataQ1.add(Integer.parseInt(position));
sparklinePosition.getData().add(new XYChart.Data<>(index++, dataQ1.remove()));
System.out.println("new position found for " + boatName + " in position " + position + " old(" + this.position + ")");
}
} catch (NumberFormatException e) {
System.out.println("No position found");
}
this.position = position;
}
@@ -167,6 +195,10 @@ public class Yacht {
this.markRoundingTime = markRoundingTime;
}
public Series<Number, Number> getSparklinePosition() {
return sparklinePosition;
}
@Override
public String toString() {
return boatName;