Refactored the raceClock

- created a class that hosts the raceClock
- refactored the raceController to use a raceClock.
#story[761]
main
Fan-Wu Yang 9 years ago
parent 7790322e04
commit e501102bc5

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="" />
</component>

@ -176,14 +176,8 @@ public class RaceController extends Controller {
ongoingRacePane.setVisible(true); ongoingRacePane.setVisible(true);
//timezone //timezone
TimeZoneLookup timeZoneLookup = new TimeZoneLookup(); RaceClock raceClock = new RaceClock(raceXMLReader.getMark());
TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(raceXMLReader.getMark().getLatitude(), raceXMLReader.getMark().getLongitude()); timeZone.textProperty().bind(raceClock.timeProperty());
ZoneId zoneId = ZoneId.of(timeZoneResult.getResult());
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
ZonedDateTime zonedDateTime =localDateTime.atZone(zoneId);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z");
// System.out.println(dateTimeFormatter.format(zonedDateTime));
timeZone.setText(dateTimeFormatter.format(zonedDateTime));
initializeFPS(); initializeFPS();
initializeAnnotations(); initializeAnnotations();

@ -0,0 +1,46 @@
package seng302.Model;
import com.github.bfsmith.geotimezone.TimeZoneLookup;
import com.github.bfsmith.geotimezone.TimeZoneResult;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import seng302.GPSCoordinate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**
* Created by Gondr on 19/04/2017.
*/
public class RaceClock {
private StringProperty time;
private DateTimeFormatter dateTimeFormatter;
private ZoneId zoneId;
public RaceClock(GPSCoordinate gpsCoordinate){
TimeZoneLookup timeZoneLookup = new TimeZoneLookup();
TimeZoneResult timeZoneResult = timeZoneLookup.getTimeZone(gpsCoordinate.getLatitude(), gpsCoordinate.getLongitude());
ZoneId zoneId = ZoneId.of(timeZoneResult.getResult());
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM HH:mm:ss z");
// System.out.println(dateTimeFormatter.format(zonedDateTime));
time = new SimpleStringProperty(dateTimeFormatter.format(zonedDateTime));
}
public void updateTime(){
LocalDateTime localDateTime = LocalDateTime.now(zoneId);
ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
time.setValue(dateTimeFormatter.format(zonedDateTime));
}
public String getTime() {
return time.get();
}
public StringProperty timeProperty() {
return time;
}
}
Loading…
Cancel
Save