Merge branch 'master' of ssh://kielweek.web4sap.com/home/trac/git

This commit is contained in:
Marcus Kammer committed 2012-02-14 15:13:50 +01:00
commit c7bc4980b8
4 files changed
+82 -41

No files matched your search

@@ -37,7 +37,7 @@ import com.google.gwt.maps.client.overlay.Polyline;
import com.google.gwt.maps.client.overlay.PolylineOptions;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.domain.common.ManeuverType;
@@ -52,6 +52,7 @@ import com.sap.sailing.gwt.ui.client.ErrorReporter;
import com.sap.sailing.gwt.ui.client.ParallelExecutionCallback;
import com.sap.sailing.gwt.ui.client.ParallelExecutionHolder;
import com.sap.sailing.gwt.ui.client.RaceSelectionChangeListener;
import com.sap.sailing.gwt.ui.client.RequiresDataInitialization;
import com.sap.sailing.gwt.ui.client.SailingServiceAsync;
import com.sap.sailing.gwt.ui.client.StringMessages;
import com.sap.sailing.gwt.ui.client.TimeListener;
@@ -65,8 +66,8 @@ import com.sap.sailing.gwt.ui.shared.PositionDTO;
import com.sap.sailing.gwt.ui.shared.components.Component;
import com.sap.sailing.gwt.ui.shared.components.SettingsDialogComponent;
public class RaceMap implements TimeListener, CompetitorSelectionChangeListener, RaceSelectionChangeListener,
Component<RaceMapSettings> {
public class RaceMap extends SimplePanel implements TimeListener, CompetitorSelectionChangeListener, RaceSelectionChangeListener,
Component<RaceMapSettings>, RequiresDataInitialization {
protected MapWidget map;
private final SailingServiceAsync sailingService;
@@ -161,9 +162,14 @@ public class RaceMap implements TimeListener, CompetitorSelectionChangeListener,
private final RaceMapSettings settings;
private final StringMessages stringMessages;
private boolean dataInitialized;
private Date lastTimeChangeBeforeInitialization;
public RaceMap(SailingServiceAsync sailingService, ErrorReporter errorReporter, Timer timer,
CompetitorSelectionProvider competitorSelection, StringMessages stringMessages) {
this.setSize("100%", "100%");
this.stringMessages = stringMessages;
this.sailingService = sailingService;
this.errorReporter = errorReporter;
@@ -179,6 +185,9 @@ public class RaceMap implements TimeListener, CompetitorSelectionChangeListener,
this.competitorSelection = competitorSelection;
competitorSelection.addCompetitorSelectionChangeListener(this);
settings = new RaceMapSettings();
lastTimeChangeBeforeInitialization = null;
dataInitialized = false;
initializeData();
}
public double calculateDistance(double lat1, double lng1, double lat2, double lng2) {
@@ -195,7 +204,7 @@ public class RaceMap implements TimeListener, CompetitorSelectionChangeListener,
return dist;
}
public void loadMapsAPI(final Panel parentPanel) {
private void loadMapsAPI() {
Maps.loadMapsApi(mapsAPIKey, "2", false, new Runnable() {
public void run() {
map = new MapWidget();
@@ -206,7 +215,7 @@ public class RaceMap implements TimeListener, CompetitorSelectionChangeListener,
// Add the map to the HTML host page
map.setScrollWheelZoomEnabled(true);
map.setContinuousZoom(true);
parentPanel.add(map);
RaceMap.this.add(map);
map.setSize("100%", "100%");
map.addMapZoomEndHandler(new MapZoomEndHandler() {
@Override
@@ -236,6 +245,14 @@ public class RaceMap implements TimeListener, CompetitorSelectionChangeListener,
lastMousePosition = event.getLatLng();
}
});
//If there was a time change before the API was loaded, reset the time
if (lastTimeChangeBeforeInitialization != null) {
timeChanged(lastTimeChangeBeforeInitialization);
lastTimeChangeBeforeInitialization = null;
}
//Data has been initialized
RaceMap.this.dataInitialized = true;
}
});
}
@@ -267,42 +284,43 @@ public class RaceMap implements TimeListener, CompetitorSelectionChangeListener,
new ParallelExecutionHolder(getBoatsCallback, getMarksCallback) {
@Override
protected void handleSuccess() {
//Do boat specific actions
Map<CompetitorDTO, List<GPSFixDTO>> boatData = getBoatsCallback.getData();
// process response only if not received out of order
if (startedProcessingRequestID < requestID) {
startedProcessingRequestID = requestID;
Date from = new Date(date.getTime() - settings.getTailLengthInMilliseconds());
updateFixes(boatData, fromAndToAndOverlap.getC());
showBoatsOnMap(from, date, getCompetitorsToShow());
if (douglasMarkers != null) {
removeAllMarkDouglasPeuckerpoints();
if (map != null) {
//Do boat specific actions
Map<CompetitorDTO, List<GPSFixDTO>> boatData = getBoatsCallback.getData();
// process response only if not received out of order
if (startedProcessingRequestID < requestID) {
startedProcessingRequestID = requestID;
Date from = new Date(date.getTime() - settings.getTailLengthInMilliseconds());
updateFixes(boatData, fromAndToAndOverlap.getC());
showBoatsOnMap(from, date, getCompetitorsToShow());
if (douglasMarkers != null) {
removeAllMarkDouglasPeuckerpoints();
}
if (maneuverMarkers != null) {
removeAllManeuverMarkers();
}
}
if (maneuverMarkers != null) {
removeAllManeuverMarkers();
//Do mark specific actions
List<MarkDTO> markData = getMarksCallback.getData();
showMarksOnMap(markData);
//Rezoom the map
if (!getSettings().getZoomSettings().contains(ZoomTypes.NONE)) { //Auto zoom if setting is not manual
zoomMapToNewBounds(getSettings().getZoomSettings().getNewBounds(RaceMap.this));
mapFirstZoomDone = true;
} else if (!mapZoomedOrPannedSinceLastRaceSelectionChange) { //Zoom once to the boats
zoomMapToNewBounds(new BoatsBoundsCalculater().calculateNewBounds(RaceMap.this));
mapFirstZoomDone = true;
} else if (!mapZoomedOrPannedSinceLastRaceSelectionChange && !mapFirstZoomDone) { //Zoom once to the buoys
zoomMapToNewBounds(new BuoysBoundsCalculater().calculateNewBounds(RaceMap.this));
mapFirstZoomDone = true;
/* Reset the mapZoomedOrPannedSinceLastRaceSelection: In spite of the fact that the map was just zoomed
* to the bounds of the buoys, it was not a zoom or pan triggered by the user. As a consequence the
* mapZoomedOrPannedSinceLastRaceSelection option has to reset again.
*/
mapZoomedOrPannedSinceLastRaceSelectionChange = false;
}
}
//Do mark specific actions
List<MarkDTO> markData = getMarksCallback.getData();
showMarksOnMap(markData);
//Rezoom the map
if (!getSettings().getZoomSettings().contains(ZoomTypes.NONE)) { //Auto zoom if setting is not manual
zoomMapToNewBounds(getSettings().getZoomSettings().getNewBounds(RaceMap.this));
mapFirstZoomDone = true;
} else if (!mapZoomedOrPannedSinceLastRaceSelectionChange) { //Zoom once to the boats
zoomMapToNewBounds(new BoatsBoundsCalculater().calculateNewBounds(RaceMap.this));
mapFirstZoomDone = true;
} else if (!mapZoomedOrPannedSinceLastRaceSelectionChange && !mapFirstZoomDone) { //Zoom once to the buoys
zoomMapToNewBounds(new BuoysBoundsCalculater().calculateNewBounds(RaceMap.this));
mapFirstZoomDone = true;
/*
* Reset the mapZoomedOrPannedSinceLastRaceSelection: In spite of the fact that the map was just zoomed
* to the bounds of the buoys, it was not a zoom or pan triggered by the user. As a consequence the
* mapZoomedOrPannedSinceLastRaceSelection option has to reset again.
*/
mapZoomedOrPannedSinceLastRaceSelectionChange = false;
} else {
lastTimeChangeBeforeInitialization = date;
}
}
@@ -1191,4 +1209,14 @@ public class RaceMap implements TimeListener, CompetitorSelectionChangeListener,
}
}
@Override
public void initializeData() {
loadMapsAPI();
}
@Override
public boolean isDataInitialized() {
return dataInitialized;
}
}
@@ -71,7 +71,7 @@ public class RaceMapPanel extends FormPanel implements EventDisplayer, TimeListe
mapPanel.setSize("100%", "100%");
grid.setWidget(2, 1, mapPanel);
raceMap = new RaceMap(sailingService, errorReporter, timer, competitorSelectionProvider, stringMessages);
raceMap.loadMapsAPI(mapPanel);
mapPanel.add(raceMap);
raceSelectionModel = new RaceSelectionModel();
raceListBox = new RacesListBoxPanel(eventRefresher, raceSelectionModel, stringMessages);
raceSelectionModel.addRaceSelectionChangeListener(this);
@@ -0,0 +1,13 @@
package com.sap.sailing.gwt.ui.client;
/**
* This is used by UI-Components, which require asynchronous data initialization (for example RaceMap, Charts or the Leaderboard)
* @author Lennart Hensler (D054527)
*
*/
public interface RequiresDataInitialization {
public void initializeData();
public boolean isDataInitialized();
}
@@ -141,7 +141,7 @@ public class RaceBoardPanel extends FormPanel implements EventDisplayer, RaceSel
CollapsableComponentViewer<RaceMapSettings> raceMapViewer = new CollapsableComponentViewer<RaceMapSettings>(
raceMap, "auto", "500px", stringMessages);
raceMap.loadMapsAPI((Panel) raceMapViewer.getViewerWidget().getContent());
((Panel) raceMapViewer.getViewerWidget().getContent()).add(raceMap);
raceMap.onRaceSelectionChange(Collections.singletonList(selectedRaceIdentifier));
collapsableViewers.add(raceMapViewer);
}