bug4202 fixed timing issues related to mode initialisation before map

was ready
This commit is contained in:
Kai Börnert committed 2018-09-19 11:22:33 +02:00
1 parent 99cc455602
commit 77ee210432
3 files changed
+43 -18

No files matched your search

@@ -174,6 +174,7 @@ public class RaceMap extends AbstractCompositeComponent<RaceMapSettings> impleme
private AbsolutePanel rootPanel = new AbsolutePanel();
private MapWidget map;
private Collection<Runnable> mapInitializedListener;
/**
* Always valid, non-<code>null</code>. Must be used to map all coordinates, headings, bearings, and directions
@@ -553,6 +554,7 @@ public class RaceMap extends AbstractCompositeComponent<RaceMapSettings> impleme
updateCoordinateSystemFromSettings();
lastTimeChangeBeforeInitialization = null;
isMapInitialized = false;
mapInitializedListener = new ArrayList<>();
this.hasPolar = false;
headerPanel = new FlowPanel();
headerPanel.setStyleName("RaceMap-HeaderPanel");
@@ -774,16 +776,16 @@ public class RaceMap extends AbstractCompositeComponent<RaceMapSettings> impleme
if (!currentlyDragging) {
refreshMapWithoutAnimation();
}
if (!isMapInitialized) {
// ensure at least one redraw after starting the map
RaceMap.this.isMapInitialized = true;
redraw();
} else if (!mapFirstZoomDone) {
// ensure the zoom is correct in cases, were a redraw will not finish due to already running
// remote requests and ensure the next redraw will not be cancelled in paused state, due to
// identical time
if (!mapFirstZoomDone) {
zoomMapToNewBounds(settings.getZoomSettings().getNewBounds(RaceMap.this));
remoteCallsToSkipInExecution.clear();
redraw();
}
if (!isMapInitialized) {
RaceMap.this.isMapInitialized = true;
mapInitializedListener.forEach(c -> c.run());
mapInitializedListener.clear();
// ensure at least one redraw after starting the map, but not before other things like modes
// initialize, as they might change the timer or other settings
redraw();
}
}
@@ -2884,7 +2886,9 @@ public class RaceMap extends AbstractCompositeComponent<RaceMapSettings> impleme
public void onResize() {
if (map != null) {
map.triggerResize();
zoomMapToNewBounds(settings.getZoomSettings().getNewBounds(RaceMap.this));
if (isMapInitialized) {
zoomMapToNewBounds(settings.getZoomSettings().getNewBounds(RaceMap.this));
}
}
// Adjust RaceMap headers to avoid overlapping based on the RaceMap width
boolean isCompactHeader = this.getOffsetWidth() <= 600;
@@ -3140,4 +3144,13 @@ public class RaceMap extends AbstractCompositeComponent<RaceMapSettings> impleme
public RaceMapLifecycle getLifecycle() {
return raceMapLifecycle;
}
public void addMapInitializedListener(Runnable runnable) {
if (isMapInitialized) {
runnable.run();
} else {
this.mapInitializedListener.add(runnable);
}
}
}
@@ -78,8 +78,19 @@ public abstract class AbstractRaceBoardMode implements RaceBoardMode, RaceTimesI
leaderboardPanel.setAutoExpandPreSelected(true);
this.timer = raceBoardPanel.getTimer();
this.raceIdentifier = raceBoardPanel.getSelectedRaceIdentifier();
raceBoardPanel.getMap().addMapInitializedListener(new Runnable() {
public void run() {
checkIfTrigger();
};
});
}
protected void checkIfTrigger() {
if (raceBoardPanel.getMap().isDataInitialized()) {
trigger();
}
}
/**
* Called whenever new information of any sort has become available. Subclasses can use this
* to decide whether everything they need has been received in order to carry out their actions.
@@ -118,7 +129,7 @@ public abstract class AbstractRaceBoardMode implements RaceBoardMode, RaceTimesI
long clientTimeWhenRequestWasSent, Date serverTimeDuringRequest, long clientTimeWhenResponseWasReceived) {
this.raceTimesInfo = raceTimesInfo;
this.raceTimesInfoForRace = raceTimesInfo.get(getRaceIdentifier());
trigger();
checkIfTrigger();
}
protected void stopReceivingRaceTimesInfos() {
@@ -131,7 +142,8 @@ public abstract class AbstractRaceBoardMode implements RaceBoardMode, RaceTimesI
@Override
public void updatedLeaderboard(LeaderboardDTO leaderboard) {
this.leaderboard = leaderboard;
trigger();
checkIfTrigger();
;
}
protected void stopReceivingLeaderboard() {
@@ -140,9 +152,9 @@ public abstract class AbstractRaceBoardMode implements RaceBoardMode, RaceTimesI
/**
* Fetches the leaderboard named {@code leaderboardName} for {@code timePoint} with details for race column
* {@code raceColumnName} and stores it in {@link #leaderboardForSpecificTimePoint}, then invokes {@link #trigger()}.
* If a {@link #getLeaderboard()} has been received already, it is passed on in the call in order to reduce the
* bandwidth required, based on a differential approach.
* {@code raceColumnName} and stores it in {@link #leaderboardForSpecificTimePoint}, then invokes
* {@link #checkIfTrigger()}. If a {@link #getLeaderboard()} has been received already, it is passed on in the call
* in order to reduce the bandwidth required, based on a differential approach.
*/
protected void loadLeaderboardForSpecificTimePoint(String leaderboardName,
String raceColumnName, Date timePoint) {
@@ -156,7 +168,7 @@ public abstract class AbstractRaceBoardMode implements RaceBoardMode, RaceTimesI
public void onSuccess(LeaderboardDTO result) {
leaderboardForSpecificTimePoint = result;
getLeaderboardPanel().updateLeaderboard(result);
trigger();
checkIfTrigger();
}
};
final ArrayList<String> raceColumnNameAsList = new ArrayList<>();
@@ -174,7 +186,7 @@ public abstract class AbstractRaceBoardMode implements RaceBoardMode, RaceTimesI
@Override
public void currentRaceSelected(RaceIdentifier raceIdentifier, RaceColumnDTO raceColumn) {
this.raceColumn = raceColumn;
trigger();
checkIfTrigger();
}
protected Map<RegattaAndRaceIdentifier, RaceTimesInfoDTO> getRaceTimesInfo() {
@@ -42,7 +42,7 @@ public abstract class RaceBoardModeWithPerRaceCompetitors extends AbstractRaceBo
@Override
public void competitorsForRaceDefined(Iterable<CompetitorDTO> competitorsInRace) {
this.competitorsInRace = competitorsInRace;
trigger();
checkIfTrigger();
}
protected Iterable<CompetitorDTO> getCompetitorsInRace() {