mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merge remote-tracking branch 'origin/Mark_to_MarkGroup' into wake_remake
# Conflicts: # src/main/java/seng302/App.java # src/main/java/seng302/controllers/Controller.java # src/main/java/seng302/models/BoatGroup.java # src/main/java/seng302/models/Wake.java # src/main/java/seng302/models/parsers/StreamParser.java # src/main/resources/views/MainView.fxml
This commit is contained in:
@@ -12,21 +12,28 @@ public class App extends Application
|
|||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
|
||||||
Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml"));
|
Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml"));
|
||||||
primaryStage.setTitle("RaceVision");
|
primaryStage.setTitle("RaceVision");
|
||||||
primaryStage.setScene(new Scene(root));
|
primaryStage.setScene(new Scene(root));
|
||||||
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
StreamReceiver sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"TestThread1");
|
}
|
||||||
// StreamReceiver sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread1");
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
StreamReceiver sr;
|
||||||
|
|
||||||
|
if (args.length > 1){
|
||||||
|
sr = new StreamReceiver("localhost", 8085, "TestThread1");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//StreamReceiver sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941,"TestThread1");
|
||||||
|
sr = new StreamReceiver("livedata.americascup.com", 4941, "TestThread1");
|
||||||
|
}
|
||||||
|
|
||||||
sr.start();
|
sr.start();
|
||||||
StreamParser streamParser = new StreamParser("TestThread2");
|
StreamParser streamParser = new StreamParser("TestThread2");
|
||||||
streamParser.start();
|
streamParser.start();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import seng302.models.RaceObject;
|
|||||||
import seng302.models.mark.*;
|
import seng302.models.mark.*;
|
||||||
import seng302.models.parsers.StreamParser;
|
import seng302.models.parsers.StreamParser;
|
||||||
|
|
||||||
|
import java.sql.Time;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,26 @@
|
|||||||
package seng302.controllers;
|
package seng302.controllers;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
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.TableView;
|
||||||
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by michaelrausch on 21/03/17.
|
* Created by michaelrausch on 21/03/17.
|
||||||
@@ -16,6 +28,20 @@ import java.util.ResourceBundle;
|
|||||||
public class Controller implements Initializable {
|
public class Controller implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane contentPane;
|
private AnchorPane contentPane;
|
||||||
|
@FXML
|
||||||
|
private Label timeTillLive;
|
||||||
|
@FXML
|
||||||
|
private Button streamButton;
|
||||||
|
@FXML
|
||||||
|
private Button switchToRaceViewButton;
|
||||||
|
@FXML
|
||||||
|
private TableView teamList;
|
||||||
|
@FXML
|
||||||
|
private TableColumn boatNameCol;
|
||||||
|
@FXML
|
||||||
|
private TableColumn shortNameCol;
|
||||||
|
@FXML
|
||||||
|
private TableColumn countryCol;
|
||||||
|
|
||||||
private void setContentPane(String jfxUrl){
|
private void setContentPane(String jfxUrl){
|
||||||
try{
|
try{
|
||||||
@@ -33,5 +59,71 @@ public class Controller implements Initializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Running a timer to update the livestream status on welcome screen. Update interval is 500 miliseconds.
|
||||||
|
*/
|
||||||
|
public void startStream() {
|
||||||
|
if (StreamParser.isStreamStatus()) {
|
||||||
|
streamButton.setVisible(false);
|
||||||
|
timeTillLive.setVisible(true);
|
||||||
|
timeTillLive.setTextFill(Color.GREEN);
|
||||||
|
timeTillLive.setText("Connecting...");
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.scheduleAtFixedRate(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
if (StreamParser.isRaceFinished()) {
|
||||||
|
timeTillLive.setTextFill(Color.RED);
|
||||||
|
timeTillLive.setText("Race finished! Waiting for new race...");
|
||||||
|
switchToRaceViewButton.setDisable(true);
|
||||||
|
} else if (StreamParser.getTimeSinceStart() > 0 && StreamParser.getTimeSinceStart() % 10 == 0) {
|
||||||
|
updateTeamList();
|
||||||
|
timeTillLive.setTextFill(Color.RED);
|
||||||
|
switchToRaceViewButton.setDisable(false);
|
||||||
|
Long timerMinute = StreamParser.getTimeSinceStart() / 60;
|
||||||
|
Long timerSecond = StreamParser.getTimeSinceStart() % 60;
|
||||||
|
String timerString = "-" + timerMinute + "." + timerSecond + " minutes";
|
||||||
|
timeTillLive.setText(timerString);
|
||||||
|
} else if (StreamParser.getTimeSinceStart() % 10 == 0) {
|
||||||
|
updateTeamList();
|
||||||
|
timeTillLive.setTextFill(Color.BLACK);
|
||||||
|
switchToRaceViewButton.setDisable(false);
|
||||||
|
Long timerMinute = -1 * StreamParser.getTimeSinceStart() / 60;
|
||||||
|
Long timerSecond = -1 * StreamParser.getTimeSinceStart() % 60;
|
||||||
|
String timerString = timerMinute + "." + timerSecond + " minutes";
|
||||||
|
timeTillLive.setText(timerString);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 0, 500);
|
||||||
|
} else {
|
||||||
|
timeTillLive.setText("Stream not available.");
|
||||||
|
timeTillLive.setTextFill(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void switchToRaceView() {
|
||||||
|
setContentPane("/views/RaceView.fxml");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTeamList() {
|
||||||
|
ObservableList<Boat> data = FXCollections.observableArrayList();
|
||||||
|
teamList.setItems(data);
|
||||||
|
boatNameCol.setCellValueFactory(
|
||||||
|
new PropertyValueFactory<Boat,String>("boatName")
|
||||||
|
);
|
||||||
|
shortNameCol.setCellValueFactory(
|
||||||
|
new PropertyValueFactory<Boat,String>("shortName")
|
||||||
|
);
|
||||||
|
countryCol.setCellValueFactory(
|
||||||
|
new PropertyValueFactory<Boat,String>("country")
|
||||||
|
);
|
||||||
|
for (Boat boat : StreamParser.getBoats()) {
|
||||||
|
data.add(boat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ import javafx.scene.control.Slider;
|
|||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
import seng302.models.*;
|
import seng302.models.*;
|
||||||
import seng302.models.parsers.ConfigParser;
|
import seng302.models.parsers.ConfigParser;
|
||||||
|
import seng302.models.parsers.StreamParser;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -65,7 +67,7 @@ public class RaceViewController extends Thread{
|
|||||||
|
|
||||||
includedCanvasController.setup(this);
|
includedCanvasController.setup(this);
|
||||||
includedCanvasController.initializeCanvas();
|
includedCanvasController.initializeCanvas();
|
||||||
//initializeTimer();
|
initializeTimer();
|
||||||
initializeSettings();
|
initializeSettings();
|
||||||
|
|
||||||
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
||||||
@@ -130,12 +132,11 @@ public class RaceViewController extends Thread{
|
|||||||
timerTimeline.getKeyFrames().add(
|
timerTimeline.getKeyFrames().add(
|
||||||
new KeyFrame(Duration.seconds(1),
|
new KeyFrame(Duration.seconds(1),
|
||||||
event -> {
|
event -> {
|
||||||
// Stop timer if race is finished
|
if (StreamParser.isRaceFinished()) {
|
||||||
if (this.race.isRaceFinished()) {
|
timerLabel.setFill(Color.RED);
|
||||||
this.timerTimeline.stop();
|
timerLabel.setText("Race Finished!");
|
||||||
} else {
|
} else {
|
||||||
timerLabel.setText(convertTimeToMinutesSeconds(race.getRaceTime()));
|
timerLabel.setText(currentTimer());
|
||||||
this.race.incrementRaceTime();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -290,6 +291,20 @@ public class RaceViewController extends Thread{
|
|||||||
return String.format("%02d:%02d", time / 60, time % 60);
|
return String.format("%02d:%02d", time / 60, time % 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String currentTimer() {
|
||||||
|
String timerString = "0:00 minutes";
|
||||||
|
if (StreamParser.getTimeSinceStart() > 0 && StreamParser.getTimeSinceStart() % 10 == 0) {
|
||||||
|
Long timerMinute = StreamParser.getTimeSinceStart() / 60;
|
||||||
|
Long timerSecond = StreamParser.getTimeSinceStart() % 60;
|
||||||
|
timerString = "-" + timerMinute + "." + timerSecond + " minutes";
|
||||||
|
} else if (StreamParser.getTimeSinceStart() % 10 == 0) {
|
||||||
|
Long timerMinute = -1 * StreamParser.getTimeSinceStart() / 60;
|
||||||
|
Long timerSecond = -1 * StreamParser.getTimeSinceStart() % 60;
|
||||||
|
timerString = timerMinute + "." + timerSecond + " minutes";
|
||||||
|
}
|
||||||
|
return timerString;
|
||||||
|
}
|
||||||
|
|
||||||
public void stopTimer() {
|
public void stopTimer() {
|
||||||
timerTimeline.stop();
|
timerTimeline.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public class Boat {
|
|||||||
private int markLastPast;
|
private int markLastPast;
|
||||||
private String shortName;
|
private String shortName;
|
||||||
private int id;
|
private int id;
|
||||||
|
// new attributes to boat
|
||||||
|
private int sourceID;
|
||||||
|
private String boatName;
|
||||||
|
private String country;
|
||||||
|
|
||||||
public Boat(String teamName) {
|
public Boat(String teamName) {
|
||||||
this.teamName = teamName;
|
this.teamName = teamName;
|
||||||
@@ -45,6 +49,21 @@ public class Boat {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New instance created by BoatsParser.
|
||||||
|
*
|
||||||
|
* @param sourceID source ID of the boat
|
||||||
|
* @param boatName full name of the boat
|
||||||
|
* @param shortName short name of the boat
|
||||||
|
* @param country country of the boat
|
||||||
|
*/
|
||||||
|
public Boat(int sourceID, String boatName, String shortName, String country) {
|
||||||
|
this.sourceID = sourceID;
|
||||||
|
this.boatName = boatName;
|
||||||
|
this.shortName = shortName;
|
||||||
|
this.country = country;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the team sailing the boat
|
* Returns the name of the team sailing the boat
|
||||||
*
|
*
|
||||||
@@ -141,4 +160,15 @@ public class Boat {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSourceID() {
|
||||||
|
return sourceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBoatName() {
|
||||||
|
return boatName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCountry() {
|
||||||
|
return country;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package seng302.models.parsers;
|
||||||
|
|
||||||
|
import org.w3c.dom.*;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import seng302.models.Boat;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.StringBufferInputStream;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ryan_ on 30/04/2017.
|
||||||
|
*/
|
||||||
|
public class BoatsParser extends FileParser {
|
||||||
|
private Document doc;
|
||||||
|
|
||||||
|
public BoatsParser(String xmlString) {
|
||||||
|
this.doc = this.parseFile(xmlString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a boat instance from a given node if 'Type' is 'Yacht'
|
||||||
|
*
|
||||||
|
* @param node a boat node
|
||||||
|
* @return an instance of Boat
|
||||||
|
*/
|
||||||
|
private Boat parseBoat(Node node) {
|
||||||
|
try {
|
||||||
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
Element element = (Element) node;
|
||||||
|
if (element.getAttribute("Type").equals("Yacht")) {
|
||||||
|
String sourceID = element.getAttribute("SourceID");
|
||||||
|
String boatName = element.getAttribute("BoatName");
|
||||||
|
String shortName = element.getAttribute("ShortName");
|
||||||
|
String stoweName = element.getAttribute("StoweName");
|
||||||
|
String country = element.getAttribute("Country");
|
||||||
|
Boat boat = new Boat(Integer.parseInt(sourceID), boatName, shortName, country);
|
||||||
|
return boat;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new NoSuchElementException("Cannot generate a boat by given node");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of boats from the xml.
|
||||||
|
*
|
||||||
|
* @return a list of boats
|
||||||
|
*/
|
||||||
|
public List<Boat> getBoats() {
|
||||||
|
ArrayList<Boat> boats = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
NodeList nodes = this.doc.getElementsByTagName("Boat");
|
||||||
|
for (int i = 0; i < nodes.getLength(); i++) {
|
||||||
|
Node node = nodes.item(i);
|
||||||
|
Boat boat = parseBoat(node);
|
||||||
|
if (!(boat == null)) {
|
||||||
|
boats.add(boat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return boats;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
package seng302.models.parsers;
|
package seng302.models.parsers;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.StringReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Haoming Yin (hyi25) on 16/3/2017
|
* Created by Haoming Yin (hyi25) on 16/3/2017
|
||||||
@@ -15,6 +17,8 @@ public abstract class FileParser {
|
|||||||
|
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
|
||||||
|
public FileParser() {}
|
||||||
|
|
||||||
public FileParser(String path) {
|
public FileParser(String path) {
|
||||||
this.filePath = path;
|
this.filePath = path;
|
||||||
}
|
}
|
||||||
@@ -32,6 +36,19 @@ public abstract class FileParser {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Document parseFile(String xmlString) {
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document doc = builder.parse(new InputSource(new StringReader(xmlString)));
|
||||||
|
// optional, in order to recover info from broken line.
|
||||||
|
doc.getDocumentElement().normalize();
|
||||||
|
return doc;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import javafx.geometry.Point3D;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
import seng302.models.Boat;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
@@ -32,6 +33,10 @@ public class StreamParser extends Thread{
|
|||||||
private String threadName;
|
private String threadName;
|
||||||
private Thread t;
|
private Thread t;
|
||||||
private static boolean raceStarted = false;
|
private static boolean raceStarted = false;
|
||||||
|
private static boolean raceFinished = false;
|
||||||
|
private static boolean streamStatus = false;
|
||||||
|
private static long timeSinceStart = -1;
|
||||||
|
private static List<Boat> boats = new ArrayList<>();
|
||||||
|
|
||||||
public StreamParser(String threadName){
|
public StreamParser(String threadName){
|
||||||
this.threadName = threadName;
|
this.threadName = threadName;
|
||||||
@@ -44,6 +49,7 @@ public class StreamParser extends Thread{
|
|||||||
public void run(){
|
public void run(){
|
||||||
try {
|
try {
|
||||||
System.out.println("START OF STREAM");
|
System.out.println("START OF STREAM");
|
||||||
|
streamStatus = true;
|
||||||
while (StreamReceiver.packetBuffer == null || StreamReceiver.packetBuffer.size() < 1) {
|
while (StreamReceiver.packetBuffer == null || StreamReceiver.packetBuffer.size() < 1) {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
}
|
}
|
||||||
@@ -155,16 +161,21 @@ public class StreamParser extends Thread{
|
|||||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
|
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
|
||||||
if (timeTillStart > 0 && timeTillStart % 10 == 0) {
|
if (timeTillStart > 0 && timeTillStart % 10 == 0) {
|
||||||
|
timeSinceStart = timeTillStart;
|
||||||
System.out.println("Time till start: " + timeTillStart + " Seconds");
|
System.out.println("Time till start: " + timeTillStart + " Seconds");
|
||||||
} else {
|
} else {
|
||||||
if (raceStatus == 4 || raceStatus == 8){
|
if (raceStatus == 4 || raceStatus == 8){
|
||||||
|
raceFinished = true;
|
||||||
|
raceStarted = false;
|
||||||
System.out.println("RACE HAS FINISHED");
|
System.out.println("RACE HAS FINISHED");
|
||||||
} else if (!raceStarted){
|
} else if (!raceStarted){
|
||||||
raceStarted = true;
|
raceStarted = true;
|
||||||
|
raceFinished = false;
|
||||||
System.out.println("RACE HAS STARTED");
|
System.out.println("RACE HAS STARTED");
|
||||||
}
|
}
|
||||||
if (timeTillStart % 10 == 0){
|
if (timeTillStart % 10 == 0){
|
||||||
System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
|
System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
|
||||||
|
timeSinceStart = timeTillStart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
|
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
|
||||||
@@ -226,17 +237,24 @@ public class StreamParser extends Thread{
|
|||||||
while (payloadStream.available() > 0 && (currentChar = payloadStream.read()) != 0) {
|
while (payloadStream.available() > 0 && (currentChar = payloadStream.read()) != 0) {
|
||||||
xmlMessage += (char)currentChar;
|
xmlMessage += (char)currentChar;
|
||||||
}
|
}
|
||||||
//Create XML document Object
|
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
// Parse boat xml from server
|
||||||
DocumentBuilder db = null;
|
if (xmlMessageSubType == 7) {
|
||||||
Document doc = null;
|
BoatsParser boatsParser = new BoatsParser(xmlMessage);
|
||||||
try {
|
boats = boatsParser.getBoats();
|
||||||
db = dbf.newDocumentBuilder();
|
|
||||||
doc = db.parse(new InputSource(new StringReader(xmlMessage)));
|
|
||||||
} catch (ParserConfigurationException | IOException | SAXException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
// TODO: 30/04/2017 (ajm412) Figure out how this will tie into the backend of the visualiser now that the parsing is done.
|
|
||||||
|
//Create XML document Object
|
||||||
|
// DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
|
// DocumentBuilder db = null;
|
||||||
|
// try {
|
||||||
|
// db = dbf.newDocumentBuilder();
|
||||||
|
// Document doc = db.parse(new InputSource(new StringReader(xmlMessage)));
|
||||||
|
// // TODO: 25/04/17 ajm412: Check that the object matches expected structure and return Document object.
|
||||||
|
// } catch (ParserConfigurationException | IOException | SAXException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -410,5 +428,50 @@ public class StreamParser extends Thread{
|
|||||||
}
|
}
|
||||||
return partialLong;
|
return partialLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns false if race not started, true otherwise
|
||||||
|
*
|
||||||
|
* @return race started status
|
||||||
|
*/
|
||||||
|
public static boolean isRaceStarted() {
|
||||||
|
return raceStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns false if stream not connected, true otherwise
|
||||||
|
*
|
||||||
|
* @return stream started status
|
||||||
|
*/
|
||||||
|
public static boolean isStreamStatus() {
|
||||||
|
return streamStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns race timer
|
||||||
|
*
|
||||||
|
* @return race timer in long
|
||||||
|
*/
|
||||||
|
public static long getTimeSinceStart() {
|
||||||
|
return timeSinceStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return false if race not finished, true otherwise
|
||||||
|
*
|
||||||
|
* @return race finished status
|
||||||
|
*/
|
||||||
|
public static boolean isRaceFinished() {
|
||||||
|
return raceFinished;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return list of boats from the server
|
||||||
|
*
|
||||||
|
* @return list of boats
|
||||||
|
*/
|
||||||
|
public static List<Boat> getBoats() {
|
||||||
|
return boats;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,62 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.text.*?>
|
||||||
<?import javafx.scene.canvas.*?>
|
<?import javafx.scene.canvas.*?>
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<AnchorPane fx:id="contentPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.Controller">
|
<AnchorPane fx:id="contentPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.Controller">
|
||||||
<children>
|
<children>
|
||||||
<fx:include source="RaceView.fxml" fx:id="raceView"/>
|
<GridPane alignment="CENTER" prefHeight="1080.0" prefWidth="1920.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints maxHeight="403.0" minHeight="0.0" prefHeight="170.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="444.0" minHeight="0.0" prefHeight="52.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="432.0" minHeight="2.0" prefHeight="102.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="635.0" minHeight="0.0" prefHeight="60.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="635.0" minHeight="10.0" prefHeight="365.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="635.0" minHeight="10.0" prefHeight="93.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="599.0" minHeight="10.0" prefHeight="262.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Label alignment="CENTER" text="Welcome to Race Vision" GridPane.halignment="CENTER" GridPane.valignment="BOTTOM">
|
||||||
|
<font>
|
||||||
|
<Font size="40.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label text="Your live AC35 livestream" GridPane.halignment="CENTER" GridPane.rowIndex="1">
|
||||||
|
<font>
|
||||||
|
<Font size="20.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label text="Livestream Status:" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
|
||||||
|
<font>
|
||||||
|
<Font size="28.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="timeTillLive" text="0:00 minutes" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="3">
|
||||||
|
<font>
|
||||||
|
<Font size="27.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Button fx:id="streamButton" mnemonicParsing="false" onAction="#startStream" text="Click to stream" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
|
||||||
|
<Button fx:id="switchToRaceViewButton" disable="true" mnemonicParsing="false" onAction="#switchToRaceView" text="Watch Race" GridPane.halignment="CENTER" GridPane.rowIndex="6" />
|
||||||
|
<TableView fx:id="teamList" maxWidth="500.0" prefHeight="200.0" prefWidth="200.0" GridPane.halignment="CENTER" GridPane.rowIndex="4">
|
||||||
|
<columns>
|
||||||
|
<TableColumn fx:id="boatNameCol" editable="false" prefWidth="250.0" sortable="false" text="Boat Name" />
|
||||||
|
<TableColumn fx:id="shortNameCol" editable="false" prefWidth="125.0" sortable="false" text="Short Name" />
|
||||||
|
<TableColumn fx:id="countryCol" editable="false" prefWidth="125.0" sortable="false" text="Country" />
|
||||||
|
</columns>
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets />
|
||||||
|
</GridPane.margin>
|
||||||
|
</TableView>
|
||||||
|
<Label text="*Team position in table do not correspond to race position" GridPane.halignment="CENTER" GridPane.rowIndex="5" GridPane.valignment="TOP" />
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|||||||
Reference in New Issue
Block a user