r572 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer
Author: fdesbois Date: 2012-09-12 13:52:18 +0200 (Wed, 12 Sep 2012) New Revision: 572 Url: http://forge.codelutin.com/repositories/revision/sammoa/572 Log: fixes #1426 : - manage update on map for observation changed (time and species) - add label support - improve GPS currentLocation behavior with captureDelay - improve FlightController, some doubloons were created on currentLocation retrieval Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerOnBoard.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-09-12 11:52:18 UTC (rev 572) @@ -40,6 +40,8 @@ import fr.ulr.sammoa.persistence.Flights; import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.persistence.GeoPointDAO; +import fr.ulr.sammoa.persistence.GeoPointImpl; +import fr.ulr.sammoa.persistence.GeoPoints; import fr.ulr.sammoa.persistence.Observation; import fr.ulr.sammoa.persistence.ObservationDAO; import fr.ulr.sammoa.persistence.ObservationStatus; @@ -62,6 +64,7 @@ import fr.ulr.sammoa.persistence.TransectFlights; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.joda.time.DateTime; import org.joda.time.Interval; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -448,6 +451,73 @@ return result; } + public GeoPoint getGeoPoint(Flight flight, + Date date) { + + TopiaContext tx = beginTransaction(); + try { + + List<GeoPoint> geoPoints = getFlightGeoPoints(tx, flight); + + GeoPoint result = getGeoPoint(tx, flight, geoPoints, date); + return result; + + } catch (TopiaException ex) { + throw new TopiaRuntimeException(ex); + } finally { + endTransaction(tx); + } + } + + public GeoPoint getGeoPoint(TopiaContext tx, + Flight flight, + List<GeoPoint> geoPoints, + Date date) throws TopiaException { + + DateTime newTime = Dates.toDateTime(date); + + // Retrieve the appropriate location + GeoPoint location = GeoPoints.getClosestPoint(geoPoints, date); + DateTime locationTime = Dates.toDateTime(location.getRecordTime()); + + if (logger.isDebugEnabled()) { + logger.debug(String.format("Find locationTime %1$tH:%1$tM:%1$tS.%1$tL", + locationTime.toDate()) + ); + } + + GeoPoint result; + + // Create a new location if no one is available for the newTime + if (!locationTime.isEqual(newTime)) { + + result = new GeoPointImpl(location.getLatitude(), location.getLongitude()); + result.setSpeed(location.getSpeed()); + result.setAltitude(location.getAltitude()); + + int captureDelay = Dates + .toInterval(locationTime, newTime) + .toDuration() + .toStandardSeconds() + .getSeconds(); + + result.setCaptureDelay(captureDelay); + + result.setFlight(flight); + result.setRecordTime(newTime.toDate()); + SammoaDAOHelper.getGeoPointDAO(tx).create(result); + geoPoints.add(result); + + if (logger.isDebugEnabled()) { + logger.debug("Create a new GeoPoint : {}", result); + } + + } else { + result = location; + } + return result; + } + public List<GeoPoint> getFlightGeoPoints(Flight flight) { TopiaContext transaction = beginTransaction(); Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-09-12 11:52:18 UTC (rev 572) @@ -28,11 +28,14 @@ import fr.ulr.sammoa.application.device.DeviceStateEvent; import fr.ulr.sammoa.application.device.DeviceStateListener; import fr.ulr.sammoa.application.device.DeviceTechnicalException; +import fr.ulr.sammoa.persistence.Dates; import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.persistence.GeoPointImpl; import fr.ulr.sammoa.persistence.GeoPoints; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Date; import java.util.Set; import java.util.Timer; import java.util.TimerTask; @@ -156,6 +159,44 @@ return gpsLocationListeners; } + @Override + public GeoPoint getCurrentLocation() { + + GeoPoint lastLocation = getLastLocation(); + + Date currentDate = getDate(); + + GeoPoint result = new GeoPointImpl(lastLocation.getLatitude(), lastLocation.getLongitude()); + result.setAltitude(lastLocation.getAltitude()); + result.setSpeed(lastLocation.getSpeed()); + result.setRecordTime(currentDate); + + if (lastLocation.getRecordTime() != null) { + long captureDelay = Dates + .toInterval(lastLocation.getRecordTime(), currentDate) + .toDuration() + .getStandardSeconds(); + result.setCaptureDelay((int) captureDelay); + + if (logger.isTraceEnabled()) { + logger.trace("CaptureDelay = {} for GeoPoint {}", captureDelay, result); + } + } + + if (logger.isWarnEnabled() && GeoPoints.isCoordinatesEmpty(result)) { + logger.warn("Retrieve a location without any coordinates : {}", result); + } + return result; + } + + protected Date getDate() { + // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp + Date result = Dates.newDateWithoutMillis(); + return result; + } + + protected abstract GeoPoint getLastLocation(); + public void setState(DeviceState state, DeviceTechnicalException error) { DeviceState oldValue = getState(); this.state = state; @@ -220,7 +261,7 @@ nbFailures = 0; } - location.setCaptureDelay(nbFailures * config.getCheckPeriod()); +// location.setCaptureDelay(nbFailures * config.getCheckPeriod()); // Data is unavailable if (GeoPoints.isCoordinatesEmpty(location) || sameLocation && nbFailures >= nbFailuresMax) { Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-09-12 11:52:18 UTC (rev 572) @@ -26,14 +26,12 @@ import fr.ulr.sammoa.application.device.DeviceState; import fr.ulr.sammoa.application.device.DeviceTechnicalException; -import fr.ulr.sammoa.persistence.Dates; import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.persistence.GeoPointImpl; import fr.ulr.sammoa.persistence.GeoPoints; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; import java.util.Random; /** @@ -130,24 +128,37 @@ } @Override - public GeoPoint getCurrentLocation() { + protected GeoPoint getLastLocation() { GeoPoint result; if (currentLocation == null) { result = new GeoPointImpl(GeoPoints.EMPTY_COORDINATE, GeoPoints.EMPTY_COORDINATE); result.setRecordTime(getDate()); - - } else if (currentLocation.getTopiaId() != null) { - result = new GeoPointImpl(currentLocation.getLatitude(), currentLocation.getLongitude()); - result.setAltitude(currentLocation.getAltitude()); - result.setSpeed(currentLocation.getSpeed()); - result.setRecordTime(getDate()); - } else { result = currentLocation; } return result; } + // +// @Override +// public GeoPoint getCurrentLocation() { +// GeoPoint result; +// if (currentLocation == null) { +// result = new GeoPointImpl(GeoPoints.EMPTY_COORDINATE, GeoPoints.EMPTY_COORDINATE); +// result.setRecordTime(getDate()); +// +// } else if (currentLocation.getTopiaId() != null) { +// result = new GeoPointImpl(currentLocation.getLatitude(), currentLocation.getLongitude()); +// result.setAltitude(currentLocation.getAltitude()); +// result.setSpeed(currentLocation.getSpeed()); +// result.setRecordTime(getDate()); +// +// } else { +// result = currentLocation; +// } +// return result; +// } + protected class GpsPointGenerator implements Runnable { @Override @@ -179,9 +190,4 @@ } } - protected Date getDate() { - Date result = Dates.newDateWithoutMillis(); - return result; - } - } Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java 2012-09-12 11:52:18 UTC (rev 572) @@ -27,7 +27,6 @@ import fr.ulr.sammoa.application.device.DeviceState; import fr.ulr.sammoa.application.device.DeviceTechnicalException; -import fr.ulr.sammoa.persistence.Dates; import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.persistence.GeoPointImpl; import fr.ulr.sammoa.persistence.GeoPoints; @@ -62,6 +61,8 @@ protected GPSPosition lastPosition; + protected Date lastPositionDate; + protected float lastAltitude; protected float lastSpeed; @@ -156,23 +157,12 @@ } @Override - public GeoPoint getCurrentLocation() { + protected GeoPoint getLastLocation() { if (logger.isTraceEnabled()) { logger.trace("Ask lastPosition = {}", lastPosition); } -// if (!Objects.equal(lastPosition, lastSendPosition) && lastPosition != null) { -// -// result = new GeoPointImpl(lastPosition.getLatitude(), lastPosition.getLongitude()); -// result.setAltitude(lastAltitude); -// result.setSpeed(lastSpeed); -// // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp -// result.setRecordTime(new Date()); -// -// lastSendPosition = lastPosition; -// } - double latitude = lastPosition != null ? lastPosition.getLatitude() : GeoPoints.EMPTY_COORDINATE; @@ -184,14 +174,49 @@ GeoPoint result = new GeoPointImpl(latitude, longitude); result.setAltitude(lastAltitude); result.setSpeed(lastSpeed); - result.setRecordTime(getDate()); + result.setRecordTime(lastPositionDate); - if (logger.isWarnEnabled() && lastPosition == null) { - logger.warn("Retrieve a location without any coordinates : {}", result); - } return result; } + // +// @Override +// public GeoPoint getCurrentLocation() { +// +// if (logger.isTraceEnabled()) { +// logger.trace("Ask lastPosition = {}", lastPosition); +// } +// +//// if (!Objects.equal(lastPosition, lastSendPosition) && lastPosition != null) { +//// +//// result = new GeoPointImpl(lastPosition.getLatitude(), lastPosition.getLongitude()); +//// result.setAltitude(lastAltitude); +//// result.setSpeed(lastSpeed); +//// // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp +//// result.setRecordTime(new Date()); +//// +//// lastSendPosition = lastPosition; +//// } +// +// double latitude = lastPosition != null +// ? lastPosition.getLatitude() +// : GeoPoints.EMPTY_COORDINATE; +// +// double longitude = lastPosition != null +// ? lastPosition.getLongitude() +// : GeoPoints.EMPTY_COORDINATE; +// +// GeoPoint result = new GeoPointImpl(latitude, longitude); +// result.setAltitude(lastAltitude); +// result.setSpeed(lastSpeed); +// result.setRecordTime(getDate()); +// +// if (logger.isWarnEnabled() && lastPosition == null) { +// logger.warn("Retrieve a location without any coordinates : {}", result); +// } +// return result; +// } + @Override protected DeviceTechnicalException onError(GeoPoint location) { @@ -217,18 +242,18 @@ if (GeoPoints.isCoordinatesEmpty(location)) { - result = new DeviceTechnicalException(this, - "GPS is not ready, turn it on or wait for it to find satellites"); + result = new DeviceTechnicalException( + this, "GPS is not ready, turn it on or wait for it to find satellites"); } else { if (lastNumberSatellites == 0) { - result = new DeviceTechnicalException(this, - "GPS signal lost, there is no available satellite found"); + result = new DeviceTechnicalException( + this, "GPS signal lost, there is no available satellite found"); } else { - result = new DeviceTechnicalException(this, - "GPS signal lost, please check the connection port"); + result = new DeviceTechnicalException( + this, "GPS signal lost, please check the connection port"); } } } @@ -257,13 +282,13 @@ close(); super.finalize(); } +// +// protected Date getDate() { +// // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp +// Date result = Dates.newDateWithoutMillis(); +// return result; +// } - protected Date getDate() { - // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp - Date result = Dates.newDateWithoutMillis(); - return result; - } - /** * Si l'on recoit des evenements, c'est que le gps fonctionne. * Il sont envoyé par le traitement des flux NMEA et propagé par le @@ -297,6 +322,7 @@ } if (GPSDataProcessor.LOCATION.equals(property)) { + lastPositionDate = getDate(); lastPosition = (GPSPosition) evt.getNewValue(); } else if (GPSDataProcessor.ALTITUDE.equals(property)) { Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerOnBoard.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerOnBoard.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerOnBoard.java 2012-09-12 11:52:18 UTC (rev 572) @@ -25,6 +25,7 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; import fr.ulr.sammoa.application.device.DeviceManager; import fr.ulr.sammoa.application.device.audio.AudioRecorder; import fr.ulr.sammoa.application.device.gps.GpsHandler; @@ -38,8 +39,12 @@ import fr.ulr.sammoa.persistence.TransectFlight; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; +import java.util.Date; +import java.util.Map; /** * Created: 21/08/12 @@ -48,6 +53,11 @@ */ public class FlightControllerOnBoard extends BaseFlightController implements GpsLocationListener { + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(FlightControllerOnBoard.class); + + protected Map<Date, GeoPoint> geoPoints = Maps.newHashMap(); + @Override public <T extends DeviceManager> void openDeviceManager(Class<T> deviceManager) { boolean autoStart = initialized && isRunning(); @@ -73,6 +83,10 @@ super.init(flight); + geoPoints = Maps.newHashMap(Maps.uniqueIndex( + service.getFlightGeoPoints(flight), GeoPoints.toDate()) + ); + initCurrentRoute(service.getLastUnfinishedRoute(flight)); if (isRunning()) { @@ -108,18 +122,25 @@ @Override public void locationChanged(GpsLocationEvent event) { GeoPoint newLocation = event.getNewValue(); - if (!GeoPoints.isCoordinatesEmpty(newLocation) && newLocation.getTopiaId() == null) { + GeoPoint existLocation = geoPoints.get(newLocation.getRecordTime()); + if (existLocation == null) { newLocation.setFlight(flight); persistence.delayEntityCreation(newLocation); + geoPoints.put(newLocation.getRecordTime(), newLocation); } } @Override protected GeoPoint getLocation(TopiaContext tx) throws TopiaException { - GeoPoint result = getGpsHandler().getCurrentLocation(); - result.setFlight(flight); - if (result.getTopiaId() == null) { - SammoaDAOHelper.getGeoPointDAO(tx).create(result); + GeoPoint gpsLocation = getGpsHandler().getCurrentLocation(); + GeoPoint result = geoPoints.get(gpsLocation.getRecordTime()); + if (result == null) { + gpsLocation.setFlight(flight); + if (logger.isDebugEnabled()) { + logger.debug("Create a GeoPoint {}", gpsLocation); + } + result = SammoaDAOHelper.getGeoPointDAO(tx).create(gpsLocation); + geoPoints.put(result.getRecordTime(), result); } return result; } Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-09-12 11:52:18 UTC (rev 572) @@ -30,11 +30,8 @@ import fr.ulr.sammoa.persistence.Dates; import fr.ulr.sammoa.persistence.Flight; import fr.ulr.sammoa.persistence.GeoPoint; -import fr.ulr.sammoa.persistence.GeoPointImpl; -import fr.ulr.sammoa.persistence.GeoPoints; import fr.ulr.sammoa.persistence.Route; import fr.ulr.sammoa.persistence.Routes; -import fr.ulr.sammoa.persistence.SammoaDAOHelper; import fr.ulr.sammoa.persistence.TransectFlight; import fr.ulr.sammoa.persistence.TransectFlights; import org.joda.time.DateTime; @@ -85,8 +82,6 @@ Preconditions.checkNotNull(currentRoute, "You must set the current route to retrieve location"); Preconditions.checkState(!geoPoints.isEmpty(), "No geoPoints available"); - GeoPoint result; - if (logger.isDebugEnabled()) { logger.debug(String.format("Get location after startTime %1$tH:%1$tM:%1$tS.%1$tL (audio position = %2$d)", getAudioReader().getStartDate(), @@ -111,42 +106,44 @@ } // Retrieve the appropriate location - GeoPoint location = GeoPoints.getClosestPoint(geoPoints, newTime.toDate()); - DateTime locationTime = Dates.toDateTime(location.getRecordTime()); + GeoPoint result = service.getGeoPoint(tx, flight, geoPoints, newTime.toDate()); - if (logger.isDebugEnabled()) { - logger.debug(String.format("Find locationTime %1$tH:%1$tM:%1$tS.%1$tL", - locationTime.toDate()) - ); - } - - // Create a new location if no one is available for the newTime - if (!locationTime.isEqual(newTime)) { - - result = new GeoPointImpl(location.getLatitude(), location.getLongitude()); - result.setSpeed(location.getSpeed()); - result.setAltitude(location.getAltitude()); - - int captureDelay = Dates - .toInterval(locationTime, newTime) - .toDuration() - .toStandardSeconds() - .getSeconds(); - - result.setCaptureDelay(captureDelay); - - result.setFlight(flight); - result.setRecordTime(newTime.toDate()); - SammoaDAOHelper.getGeoPointDAO(tx).create(result); - geoPoints.add(result); - - if (logger.isDebugEnabled()) { - logger.debug("Create a new GeoPoint : {}", result); - } - - } else { - result = location; - } +// GeoPoint location = GeoPoints.getClosestPoint(geoPoints, newTime.toDate()); +// DateTime locationTime = Dates.toDateTime(location.getRecordTime()); +// +// if (logger.isDebugEnabled()) { +// logger.debug(String.format("Find locationTime %1$tH:%1$tM:%1$tS.%1$tL", +// locationTime.toDate()) +// ); +// } +// +// // Create a new location if no one is available for the newTime +// if (!locationTime.isEqual(newTime)) { +// +// result = new GeoPointImpl(location.getLatitude(), location.getLongitude()); +// result.setSpeed(location.getSpeed()); +// result.setAltitude(location.getAltitude()); +// +// int captureDelay = Dates +// .toInterval(locationTime, newTime) +// .toDuration() +// .toStandardSeconds() +// .getSeconds(); +// +// result.setCaptureDelay(captureDelay); +// +// result.setFlight(flight); +// result.setRecordTime(newTime.toDate()); +// SammoaDAOHelper.getGeoPointDAO(tx).create(result); +// geoPoints.add(result); +// +// if (logger.isDebugEnabled()) { +// logger.debug("Create a new GeoPoint : {}", result); +// } +// +// } else { +// result = location; +// } return result; } Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-09-12 11:52:18 UTC (rev 572) @@ -26,7 +26,6 @@ import com.google.common.base.Function; import com.google.common.base.Objects; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.FluentIterable; import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; @@ -67,21 +66,14 @@ return result; } - public static List<GeoPoint> retainsValidCoordinates(Iterable<GeoPoint> input) { - List<GeoPoint> result = FluentIterable.from(input) - .filter(Predicates.not(withCoordinatesEmpty())) - .toImmutableList(); - return result; - } - public static boolean isCoordinatesEmpty(GeoPoint geoPoint) { return geoPoint.getLatitude() == GeoPoints.EMPTY_COORDINATE && geoPoint.getLongitude() == GeoPoints.EMPTY_COORDINATE; } - public static Predicate<GeoPoint> withCoordinatesEmpty() { - return IS_COORDINATES_EMPTY_PREDICATE; - } +// public static Predicate<GeoPoint> withCoordinatesEmpty() { +// return IS_COORDINATES_EMPTY_PREDICATE; +// } public static Function<GeoPoint, Date> toDate() { return TO_DATE_FUNCTION; @@ -117,14 +109,14 @@ } }; - private static Predicate<GeoPoint> IS_COORDINATES_EMPTY_PREDICATE = new Predicate<GeoPoint>() { +// private static Predicate<GeoPoint> IS_COORDINATES_EMPTY_PREDICATE = new Predicate<GeoPoint>() { +// +// @Override +// public boolean apply(GeoPoint input) { +// return isCoordinatesEmpty(input); +// } +// }; - @Override - public boolean apply(GeoPoint input) { - return isCoordinatesEmpty(input); - } - }; - private static class WithDatePredicate implements Predicate<GeoPoint> { protected Date date; Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java 2012-09-12 11:52:18 UTC (rev 572) @@ -53,9 +53,20 @@ } public static Iterable<Date> toDates(Iterable<Observation> observations) { - return Iterables.transform(observations, TO_DATE_FUNCTION); + return Iterables.transform(observations, toDate()); } + public static String toLabel(Observation observation) { + Species species = observation.getSpecies(); + return (species != null ? species.getCode() : "") + " (S" + observation.getObservationNumber() + ")"; + } + + public static GeoPoint toGeoPoint(Observation observation, + Iterable<GeoPoint> geoPoints) { + Date date = observation.getObservationTime(); + return Iterables.find(geoPoints, GeoPoints.withDate(date), GeoPoints.newEmptyGeoPoint(date)); + } + public static Iterable<Observation> filterInRoute(Iterable<Observation> observations, Route route, Iterable<Route> routes, @@ -172,6 +183,18 @@ return result; } + public static Function<Observation, GeoPoint> toGeoPoint(final Iterable<GeoPoint> geoPoints) { + return new ToGeoPointFunction(geoPoints); + } + + public static Function<Observation, Date> toDate() { + return TO_DATE_FUNCTION; + } + + public static Function<Observation, String> toLabel() { + return TO_LABEL_FUNCTION; + } + public static Predicate<Observation> inDateInterval(Interval interval) { return new InDateIntervalPredicate(interval); } @@ -188,6 +211,28 @@ } }; + private static Function<Observation, String> TO_LABEL_FUNCTION = new Function<Observation, String>() { + + @Override + public String apply(Observation input) { + return toLabel(input); + } + }; + + private static class ToGeoPointFunction implements Function<Observation, GeoPoint> { + + protected Iterable<GeoPoint> geoPoints; + + public ToGeoPointFunction(Iterable<GeoPoint> geoPoints) { + this.geoPoints = geoPoints; + } + + @Override + public GeoPoint apply(Observation input) { + return toGeoPoint(input, geoPoints); + } + } + private static class InRoutePredicate implements Predicate<Observation> { protected Route route; Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-12 11:52:18 UTC (rev 572) @@ -233,8 +233,7 @@ List<Observer> observers = flightService.getFlightObserverForPositions(flight); List<Observation> observations = flightService.getObservations(flight); List<Route> routes = flightService.getRoutes(flight); - List<GeoPoint> geoPoints = - GeoPoints.retainsValidCoordinates(flightService.getFlightGeoPoints(flight)); + List<GeoPoint> geoPoints = flightService.getFlightGeoPoints(flight); if (logger.isTraceEnabled()) { for (GeoPoint geoPoint : geoPoints) { @@ -739,13 +738,17 @@ Observation observation = event.getObservation(); getModel().addObservation(observation); - // Add the GeoPoint to the layer - GeoPoint geoPoint = event.getGeoPoint(); - if (!GeoPoints.isCoordinatesEmpty(geoPoint)) { - observationLayer.addGeoPoint(geoPoint); - } + setObservationGeoPointInMap(observation, event.getGeoPoint()); } + public void setObservationGeoPointInMap(Observation observation, GeoPoint geoPoint) { + observationLayer.putGeoPoint(observation, geoPoint, Observations.toLabel(observation)); + } + + public void setObservationLabelInMap(Observation observation) { + observationLayer.setLabel(observation, Observations.toLabel(observation)); + } + public void selectStrate(StrateModel strate) { if (logger.isDebugEnabled()) { @@ -1092,12 +1095,11 @@ observationLayer = new SimpleGeoPointLayer(); observationLayer.setProperties(properties); - - List<GeoPoint> geoPoints = GeoPoints.getClosestPoints( - getModel().getGeoPoints(), - Observations.toDates(getModel().getObservations()) + observationLayer.setGeoPoints( + getModel().getObservations(), + Observations.toGeoPoint(getModel().getGeoPoints()), + Observations.toLabel() ); - observationLayer.setGeoPoints(geoPoints); mapHandler.add(observationLayer); } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-12 11:52:18 UTC (rev 572) @@ -36,6 +36,8 @@ import fr.ulr.sammoa.application.device.audio.AudioRecorder; import fr.ulr.sammoa.application.device.gps.GpsHandler; import fr.ulr.sammoa.application.flightController.FlightController; +import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.persistence.GeoPoints; import fr.ulr.sammoa.persistence.Observation; import fr.ulr.sammoa.persistence.ObservationStatus; import fr.ulr.sammoa.persistence.Observations; @@ -837,12 +839,20 @@ getParentUI().getHandler().getFlightController().setCurrentRoute(newValue); + if (oldValue != null) { + oldValue.removePropertyChangeListener( + Route.PROPERTY_BEGIN_TIME, routeTimeChangeListener); + } + if (newValue == null) { // no unselect but ensure valid button (a select will cause a loop) getModel().setObservationEditBean(null); } else { + newValue.addPropertyChangeListener( + Route.PROPERTY_BEGIN_TIME, routeTimeChangeListener); + // Set audio position setAudioReaderPositionDate(newValue.getBeginTime()); @@ -862,14 +872,16 @@ if (oldValue != null) { oldValue.removePropertyChangeListener( - Observation.PROPERTY_OBSERVATION_TIME, - observationTimeChangeListener); + Observation.PROPERTY_OBSERVATION_TIME, observationTimeChangeListener); + oldValue.removePropertyChangeListener( + Observation.PROPERTY_SPECIES, observationSpeciesChangeListener); } if (newValue != null) { newValue.addPropertyChangeListener( - Observation.PROPERTY_OBSERVATION_TIME, - observationTimeChangeListener); + Observation.PROPERTY_OBSERVATION_TIME, observationTimeChangeListener); + newValue.addPropertyChangeListener( + Observation.PROPERTY_SPECIES, observationSpeciesChangeListener); selectRouteByObservation(newValue); @@ -878,14 +890,53 @@ } } + protected GeoPoint ensureGeoPoint(Date date) { + + List<GeoPoint> modelPoints = getModel().getGeoPoints(); + GeoPoint result = Iterables.find(modelPoints, GeoPoints.withDate(date), null); + + if (result == null) { + FlightService service = context.getService(FlightService.class); + result = service.getGeoPoint(getModel().getFlight(), date); + modelPoints.add(result); + } + return result; + } + + private PropertyChangeListener routeTimeChangeListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + ensureGeoPoint((Date) evt.getNewValue()); + } + }; + private PropertyChangeListener observationTimeChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - selectRouteByObservation((Observation) evt.getSource()); + + Observation observation = (Observation) evt.getSource(); + + GeoPoint geoPoint = ensureGeoPoint((Date) evt.getNewValue()); + + getParentUI().getHandler().setObservationGeoPointInMap(observation, geoPoint); + + selectRouteByObservation(observation); } }; + private PropertyChangeListener observationSpeciesChangeListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + + Observation observation = (Observation) evt.getSource(); + + getParentUI().getHandler().setObservationLabelInMap(observation); + } + }; + /** * Editor for type {@link TransectFlight}. This will use the * {@link DefaultCellEditor} with {@link JComboBox} as editor component. Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java 2012-09-12 11:52:18 UTC (rev 572) @@ -26,10 +26,19 @@ import com.bbn.openmap.layer.OMGraphicHandlerLayer; import com.bbn.openmap.omGraphics.DrawingAttributes; import com.bbn.openmap.omGraphics.OMGraphic; +import com.bbn.openmap.omGraphics.OMGraphicConstants; import com.bbn.openmap.omGraphics.OMGraphicList; +import com.bbn.openmap.omGraphics.OMText; +import com.bbn.openmap.omGraphics.OMTextLabeler; +import com.google.common.base.Function; +import com.google.common.base.Objects; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.persistence.GeoPoints; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.util.List; import java.util.Properties; /** @@ -41,25 +50,96 @@ private static final long serialVersionUID = 1L; + /** Logger. */ + private static final Logger logger = LoggerFactory.getLogger(BaseGeoPointLayer.class); + protected DrawingAttributes drawingAttributes = DrawingAttributes.getDefaultClone(); - public void setGeoPoints(List<GeoPoint> geoPoints) { + public void setGeoPoints(Iterable<GeoPoint> geoPoints) { + setList(new OMGraphicList()); - for (GeoPoint geoPoint : geoPoints) { - addGraphic(geoPoint); + for (GeoPoint reference : geoPoints) { + if (GeoPoints.isCoordinatesEmpty(reference)) { + if (logger.isWarnEnabled()) { + logger.warn("Can't add geoPoint, no coordinates available " + + "at {}", reference.getRecordTime()); + } + } else { + getList().add(createGraphic(reference, reference, null)); + } } } + public <T> void setGeoPoints(Iterable<T> references, + Function<T, GeoPoint> toGeoPoint, + Function<T, String> toLabel) { + + setList(new OMGraphicList()); + + for (T reference : references) { + GeoPoint geoPoint = toGeoPoint.apply(reference); + String label = toLabel.apply(reference); + + if (GeoPoints.isCoordinatesEmpty(geoPoint)) { + if (logger.isWarnEnabled()) { + logger.warn("Can't add geoPoint, no coordinates available " + + "at {} (label={})", geoPoint.getRecordTime(), label); + } + } else { + getList().add(createGraphic(reference, geoPoint, label)); + } + } + } + public void addGeoPoint(GeoPoint geoPoint) { + putGeoPoint(geoPoint, geoPoint, null); + } - addGraphic(geoPoint); + public void setLabel(Object reference, String label) { + OMGraphic graphic = Iterables.find(getList(), withReference(reference), null); + if (graphic != null) { + setLabel(graphic, label); + applyChange(); + } + } - // Need to generate the projection to apply change - getList().generate(getProjection()); + public void putGeoPoint(Object reference, GeoPoint geoPoint, String label) { - // Refresh the view - repaint(); + int index = Iterables.indexOf(getList(), withReference(reference)); + + if (GeoPoints.isCoordinatesEmpty(geoPoint)) { + if (logger.isWarnEnabled()) { + logger.warn("Can't add geoPoint, no coordinates available " + + "(label={})", label); + } + + if (index != -1) { + if (logger.isDebugEnabled()) { + logger.debug("Remove geoPoint at index {} (label={})", index, label); + } + getList().remove(index); + } + + } else { + + OMGraphic graphic = createGraphic(reference, geoPoint, label); + + if (index != -1) { + if (logger.isDebugEnabled()) { + logger.debug("Update geoPoint at index {} (label={})", index, label); + } + getList().set(index, graphic); + + } else { + if (logger.isDebugEnabled() && label != null) { + logger.debug("Add geoPoint (label={})", label); + } + getList().add(graphic); + } + } + + applyChange(); } @Override @@ -82,12 +162,47 @@ return result; } - protected void addGraphic(GeoPoint geoPoint) { - OMGraphic graphic = newGraphic(geoPoint); - drawingAttributes.setTo(graphic); - graphic.setAppObject(geoPoint); - getList().add(graphic); + protected OMGraphic createGraphic(Object reference, GeoPoint geoPoint, String label) { + OMGraphic result = newGraphic(geoPoint); + if (label != null) { + setLabel(result, label); + } + drawingAttributes.setTo(result); + result.setAppObject(reference); + return result; } + protected void setLabel(OMGraphic graphic, String label) { + graphic.putAttribute(OMGraphicConstants.LABEL, + new OMTextLabeler(label, OMText.JUSTIFY_CENTER)); + } + + protected void applyChange() { + + // Need to generate the projection to apply change + getList().generate(getProjection()); + + // Refresh the view + repaint(); + } + protected abstract OMGraphic newGraphic(GeoPoint geoPoint); + + public static Predicate<OMGraphic> withReference(Object reference) { + return new WithReferencePredicate(reference); + } + + private static class WithReferencePredicate implements Predicate<OMGraphic> { + + protected Object reference; + + private WithReferencePredicate(Object reference) { + this.reference = reference; + } + + @Override + public boolean apply(OMGraphic input) { + return Objects.equal(input.getAppObject(), reference); + } + } } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java 2012-09-11 14:17:14 UTC (rev 571) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java 2012-09-12 11:52:18 UTC (rev 572) @@ -47,11 +47,20 @@ OMGraphic lastGraphic = Iterables.getLast(getList()); - GeoPoint previousPoint = (GeoPoint) lastGraphic.getAppObject(); + double lat, lon; + if (lastGraphic instanceof OMPoint) { + lat = ((OMPoint) lastGraphic).getLat(); + lon = ((OMPoint) lastGraphic).getLon(); + } else { + lat = ((OMLine) lastGraphic).getLL()[2]; + lon = ((OMLine) lastGraphic).getLL()[3]; + } +// GeoPoint previousPoint = (GeoPoint) lastGraphic.getAppObject(); + result = new OMLine( - previousPoint.getLatitude(), - previousPoint.getLongitude(), + lat, + lon, geoPoint.getLatitude(), geoPoint.getLongitude(), OMGraphicConstants.LINETYPE_GREATCIRCLE
participants (1)
-
fdesbois@users.forge.codelutin.com