Timer now shows and updates correctly on the start menu. #story[761]
This commit is contained in:
@@ -46,6 +46,7 @@ public class StartController extends Controller {
|
||||
private RaceClock raceClock;
|
||||
|
||||
private RaceDataSource raceData;
|
||||
private long timeLeft = 1;
|
||||
|
||||
/**
|
||||
* Begins the race with a scale factor of 15
|
||||
@@ -89,6 +90,7 @@ public class StartController extends Controller {
|
||||
e.printStackTrace();
|
||||
}
|
||||
initialiseTables();
|
||||
setRaceClock();
|
||||
}
|
||||
|
||||
public AnchorPane startWrapper(){
|
||||
@@ -102,9 +104,6 @@ public class StartController extends Controller {
|
||||
boatNameTable.setItems(observableBoats);
|
||||
boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().getName());
|
||||
boatCodeColumn.setCellValueFactory(new PropertyValueFactory<>("abbrev"));
|
||||
//timezone
|
||||
raceClock = new RaceClock(raceData.getZonedDateTime());
|
||||
timeZoneTime.textProperty().bind(raceClock.timeStringProperty());
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +129,6 @@ public class StartController extends Controller {
|
||||
long currentTimeInSeconds;
|
||||
long remainingSeconds;
|
||||
long hours;
|
||||
long timeLeft;
|
||||
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
@@ -148,7 +146,6 @@ public class StartController extends Controller {
|
||||
hours = minutes / 60;
|
||||
minutes = minutes % 60;
|
||||
updateTime(String.format("Race Clock: -%02d:%02d:%02d", hours, minutes, remainingSeconds));
|
||||
raceClock.updateTime();
|
||||
|
||||
}
|
||||
currentTime = System.currentTimeMillis();
|
||||
@@ -156,4 +153,20 @@ public class StartController extends Controller {
|
||||
}.start();
|
||||
}
|
||||
|
||||
protected void setRaceClock() {
|
||||
raceClock = new RaceClock(raceData.getZonedDateTime());
|
||||
timeZoneTime.textProperty().bind(raceClock.timeStringProperty());
|
||||
|
||||
new AnimationTimer() {
|
||||
@Override
|
||||
public void handle(long arg0) {
|
||||
if (timeLeft > 0) {
|
||||
raceClock.updateTime();
|
||||
} else {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
|
||||
/**
|
||||
* Created by Gondr on 19/04/2017.
|
||||
@@ -26,6 +27,7 @@ public class RaceClock {
|
||||
this.zoneId = zonedDateTime.getZone();
|
||||
this.timeString = new SimpleStringProperty();
|
||||
this.time = zonedDateTime;
|
||||
setTime(time);
|
||||
}
|
||||
|
||||
public static ZonedDateTime getCurrentZonedDateTime(GPSCoordinate gpsCoordinate) {
|
||||
@@ -49,18 +51,15 @@ public class RaceClock {
|
||||
* Updates time by duration elapsed since last update.
|
||||
*/
|
||||
public void updateTime() {
|
||||
this.time.plus(Duration.of(System.currentTimeMillis() - this.lastTime, ChronoUnit.MILLIS));
|
||||
this.time = this.time.plus(Duration.of(System.currentTimeMillis() - this.lastTime, ChronoUnit.MILLIS));
|
||||
this.lastTime = System.currentTimeMillis();
|
||||
setTime(time);
|
||||
}
|
||||
|
||||
public String getTimeZone() {
|
||||
return zoneId.toString();
|
||||
}
|
||||
|
||||
public String getTimeString() {
|
||||
return timeString.get();
|
||||
}
|
||||
|
||||
public StringProperty timeStringProperty() {
|
||||
return timeString;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user