mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Implemented real time race clock on the start screen using data from stream.
#story[594]
This commit is contained in:
@@ -22,10 +22,9 @@ import seng302.models.parsers.XMLParser;
|
|||||||
import javax.xml.crypto.dsig.XMLObject;
|
import javax.xml.crypto.dsig.XMLObject;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.text.DateFormat;
|
||||||
import java.util.ResourceBundle;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Timer;
|
import java.util.*;
|
||||||
import java.util.TimerTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by michaelrausch on 21/03/17.
|
* Created by michaelrausch on 21/03/17.
|
||||||
@@ -47,6 +46,8 @@ public class Controller implements Initializable {
|
|||||||
private TableColumn shortNameCol;
|
private TableColumn shortNameCol;
|
||||||
@FXML
|
@FXML
|
||||||
private TableColumn countryCol;
|
private TableColumn countryCol;
|
||||||
|
@FXML
|
||||||
|
private Label realTime;
|
||||||
|
|
||||||
private void setContentPane(String jfxUrl){
|
private void setContentPane(String jfxUrl){
|
||||||
try{
|
try{
|
||||||
@@ -64,7 +65,9 @@ public class Controller implements Initializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||||
|
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
realTime.setText(format.format(System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +77,7 @@ public class Controller implements Initializable {
|
|||||||
if (StreamParser.isStreamStatus()) {
|
if (StreamParser.isStreamStatus()) {
|
||||||
XMLParser xmlParser = StreamParser.getXmlObject();
|
XMLParser xmlParser = StreamParser.getXmlObject();
|
||||||
streamButton.setVisible(false);
|
streamButton.setVisible(false);
|
||||||
|
realTime.setVisible(true);
|
||||||
timeTillLive.setVisible(true);
|
timeTillLive.setVisible(true);
|
||||||
timeTillLive.setTextFill(Color.GREEN);
|
timeTillLive.setTextFill(Color.GREEN);
|
||||||
timeTillLive.setText("Connecting...");
|
timeTillLive.setText("Connecting...");
|
||||||
@@ -83,10 +87,12 @@ public class Controller implements Initializable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
if (StreamParser.isRaceFinished()) {
|
if (StreamParser.isRaceFinished()) {
|
||||||
|
realTime.setText(StreamParser.getCurrentTimeString());
|
||||||
timeTillLive.setTextFill(Color.RED);
|
timeTillLive.setTextFill(Color.RED);
|
||||||
timeTillLive.setText("Race finished! Waiting for new race...");
|
timeTillLive.setText("Race finished! Waiting for new race...");
|
||||||
switchToRaceViewButton.setDisable(true);
|
switchToRaceViewButton.setDisable(true);
|
||||||
} else if (StreamParser.getTimeSinceStart() > 0) {
|
} else if (StreamParser.getTimeSinceStart() > 0) {
|
||||||
|
realTime.setText(StreamParser.getCurrentTimeString());
|
||||||
updateTeamList();
|
updateTeamList();
|
||||||
timeTillLive.setTextFill(Color.RED);
|
timeTillLive.setTextFill(Color.RED);
|
||||||
switchToRaceViewButton.setDisable(false);
|
switchToRaceViewButton.setDisable(false);
|
||||||
@@ -98,6 +104,7 @@ public class Controller implements Initializable {
|
|||||||
String timerString = "-" + timerMinute + ":" + timerSecond + " minutes";
|
String timerString = "-" + timerMinute + ":" + timerSecond + " minutes";
|
||||||
timeTillLive.setText(timerString);
|
timeTillLive.setText(timerString);
|
||||||
} else {
|
} else {
|
||||||
|
realTime.setText(StreamParser.getCurrentTimeString());
|
||||||
updateTeamList();
|
updateTeamList();
|
||||||
timeTillLive.setTextFill(Color.BLACK);
|
timeTillLive.setTextFill(Color.BLACK);
|
||||||
switchToRaceViewButton.setDisable(false);
|
switchToRaceViewButton.setDisable(false);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class StreamParser extends Thread{
|
|||||||
private static long timeSinceStart = -1;
|
private static long timeSinceStart = -1;
|
||||||
private static List<XMLParser.BoatXMLObject.Boat> boats = new ArrayList<>();
|
private static List<XMLParser.BoatXMLObject.Boat> boats = new ArrayList<>();
|
||||||
private static double windDirection = 0;
|
private static double windDirection = 0;
|
||||||
|
private static String currentTimeString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to initialise the thread name and stream parser object so a thread can be executed
|
* Used to initialise the thread name and stream parser object so a thread can be executed
|
||||||
@@ -177,6 +178,7 @@ public class StreamParser extends Thread{
|
|||||||
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||||
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;
|
||||||
|
currentTimeString = format.format((new Date (currentTime)).getTime());
|
||||||
if (timeTillStart > 0) {
|
if (timeTillStart > 0) {
|
||||||
timeSinceStart = timeTillStart;
|
timeSinceStart = timeTillStart;
|
||||||
System.out.println("Time till start: " + timeTillStart + " Seconds");
|
System.out.println("Time till start: " + timeTillStart + " Seconds");
|
||||||
@@ -502,5 +504,14 @@ public class StreamParser extends Thread{
|
|||||||
public static double getWindDirection() {
|
public static double getWindDirection() {
|
||||||
return windDirection;
|
return windDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns stream time in formatted string format
|
||||||
|
*
|
||||||
|
* @return String of stream time
|
||||||
|
*/
|
||||||
|
public static String getCurrentTimeString() {
|
||||||
|
return currentTimeString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
<RowConstraints maxHeight="170.0" minHeight="170.0" prefHeight="170.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="170.0" minHeight="170.0" prefHeight="170.0" vgrow="SOMETIMES" />
|
||||||
<RowConstraints maxHeight="52.0" minHeight="52.0" prefHeight="52.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="52.0" minHeight="52.0" prefHeight="52.0" vgrow="SOMETIMES" />
|
||||||
<RowConstraints maxHeight="102.0" minHeight="102.0" prefHeight="102.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="102.0" minHeight="102.0" prefHeight="102.0" vgrow="SOMETIMES" />
|
||||||
<RowConstraints maxHeight="60.0" minHeight="60.0" prefHeight="60.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="28.0" minHeight="20.0" prefHeight="28.0" vgrow="SOMETIMES" />
|
||||||
<RowConstraints maxHeight="365.0" minHeight="365.0" prefHeight="365.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="55.0" minHeight="55.0" prefHeight="55.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints maxHeight="318.0" minHeight="318.0" prefHeight="318.0" vgrow="SOMETIMES" />
|
||||||
<RowConstraints maxHeight="93.0" minHeight="93.0" prefHeight="93.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="93.0" minHeight="93.0" prefHeight="93.0" vgrow="SOMETIMES" />
|
||||||
<RowConstraints maxHeight="262.0" minHeight="262.0" prefHeight="262.0" vgrow="SOMETIMES" />
|
<RowConstraints maxHeight="262.0" minHeight="262.0" prefHeight="262.0" vgrow="SOMETIMES" />
|
||||||
</rowConstraints>
|
</rowConstraints>
|
||||||
@@ -38,14 +39,14 @@
|
|||||||
<Font size="28.0" />
|
<Font size="28.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label fx:id="timeTillLive" text="0:00 minutes" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="3">
|
<Label fx:id="timeTillLive" text="0:00 minutes" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="4">
|
||||||
<font>
|
<font>
|
||||||
<Font size="27.0" />
|
<Font size="27.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Button fx:id="streamButton" mnemonicParsing="false" onAction="#startStream" text="Click to stream" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
|
<Button fx:id="streamButton" mnemonicParsing="false" onAction="#startStream" text="Click to stream" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
|
||||||
<Button fx:id="switchToRaceViewButton" disable="true" mnemonicParsing="false" onAction="#switchToRaceView" text="Watch Race" GridPane.halignment="CENTER" GridPane.rowIndex="6" GridPane.valignment="TOP" />
|
<Button fx:id="switchToRaceViewButton" disable="true" mnemonicParsing="false" onAction="#switchToRaceView" text="Watch Race" GridPane.halignment="CENTER" GridPane.rowIndex="7" GridPane.valignment="TOP" />
|
||||||
<TableView fx:id="teamList" maxWidth="500.0" prefHeight="200.0" prefWidth="200.0" GridPane.halignment="CENTER" GridPane.rowIndex="4">
|
<TableView fx:id="teamList" maxWidth="500.0" prefHeight="200.0" prefWidth="200.0" GridPane.halignment="CENTER" GridPane.rowIndex="5">
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn fx:id="boatNameCol" editable="false" prefWidth="250.0" sortable="false" text="Boat Name" />
|
<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="shortNameCol" editable="false" prefWidth="125.0" sortable="false" text="Short Name" />
|
||||||
@@ -55,7 +56,8 @@
|
|||||||
<Insets />
|
<Insets />
|
||||||
</GridPane.margin>
|
</GridPane.margin>
|
||||||
</TableView>
|
</TableView>
|
||||||
<Label text="*Team position in table do not correspond to race position" GridPane.halignment="CENTER" GridPane.rowIndex="5" GridPane.valignment="TOP" />
|
<Label text="*Team position in table do not correspond to race position" GridPane.halignment="CENTER" GridPane.rowIndex="6" GridPane.valignment="TOP" />
|
||||||
|
<Label fx:id="realTime" text="Local time" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="BOTTOM" />
|
||||||
</children>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
|
|||||||
Reference in New Issue
Block a user