Author: fdesbois Date: 2012-08-07 17:49:43 +0200 (Tue, 07 Aug 2012) New Revision: 362 Url: http://forge.codelutin.com/repositories/revision/sammoa/362 Log: fixes #1193 : - Improve FlightControllerListener - Resolve little issue with audio on close - Improve all layers - Create GeoPointLayer for flight tracking and observation Added: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerListener.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/ObservationEvent.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.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 trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/SimpleGeoPointLayer.java Removed: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseReferentialLayer.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/StrateLayer.java Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.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/flightController/FlightController.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerDefault.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/SammoaColors.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.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/FlightUIModel.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/TransectLayer.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-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-08-07 15:49:43 UTC (rev 362) @@ -32,6 +32,8 @@ import fr.ulr.sammoa.persistence.Campaign; import fr.ulr.sammoa.persistence.Flight; import fr.ulr.sammoa.persistence.FlightDAO; +import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.persistence.GeoPointDAO; import fr.ulr.sammoa.persistence.Observation; import fr.ulr.sammoa.persistence.ObservationDAO; import fr.ulr.sammoa.persistence.ObservationStatus; @@ -220,6 +222,26 @@ return result; } + + public List<GeoPoint> getFlightGeoPoints(Flight flight) { + + List<GeoPoint> result; + + TopiaContext transaction = persistence.beginTransaction(); + try { + GeoPointDAO dao = SammoaDAOHelper.getGeoPointDAO(transaction); + + result = dao.findAllByFlightOrderedByRecordTime(flight); + + } catch (TopiaException e) { + throw new TopiaRuntimeException(e); + + } finally { + persistence.endTransaction(transaction); + } + return result; + } + // // public void removeAllFlightObservers(Flight flight, List<Observer> observers) { // Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java 2012-08-07 15:49:43 UTC (rev 362) @@ -277,6 +277,8 @@ if (getState() != DeviceState.NO_DEVICE) { + logger.info("Stop audio line reading"); + // Destroy the thread if (lineReader != null) { lineReader.interrupt(); @@ -290,7 +292,7 @@ stop(); - if (dataLine != null && dataLine.isRunning()) { + if (dataLine != null/* && dataLine.isRunning()*/) { logger.info("Close the audio line"); 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-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-08-07 15:49:43 UTC (rev 362) @@ -74,6 +74,7 @@ public BaseGpsHandler(GpsConfig config) { this.config = config; this.state = DeviceState.NO_DEVICE; + this.deviceStateListeners = Sets.newHashSet(); this.gpsLocationListeners = Sets.newHashSet(); this.nbFailuresMax = (int) Math.ceil(config.getTimeout() / config.getCheckPeriod()); 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-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-08-07 15:49:43 UTC (rev 362) @@ -24,6 +24,7 @@ */ package fr.ulr.sammoa.application.device.gps; +import fr.ulr.sammoa.application.device.DeviceState; import fr.ulr.sammoa.application.device.DeviceTechnicalException; import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.persistence.GeoPointImpl; @@ -93,7 +94,7 @@ @Override public void open() throws DeviceTechnicalException { - // nothing to do + setState(DeviceState.READY); } @Override @@ -107,7 +108,7 @@ @Override public void close() throws DeviceTechnicalException { - // nothing to do + setState(DeviceState.NO_DEVICE); } @Override Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightController.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightController.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightController.java 2012-08-07 15:49:43 UTC (rev 362) @@ -274,12 +274,12 @@ boolean isRunning(); /** - * @param listener FlightControllerUpdateListener to add + * @param listener FlightControllerListener to add */ - void addListener(FlightControllerUpdateListener listener); + void addListener(FlightControllerListener listener); /** - * @param listener FlightControllerUpdateListener to remove + * @param listener FlightControllerListener to remove */ - void removeListener(FlightControllerUpdateListener listener); + void removeListener(FlightControllerListener listener); } Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerDefault.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerDefault.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerDefault.java 2012-08-07 15:49:43 UTC (rev 362) @@ -100,8 +100,10 @@ protected TransectFlight lastTransect; - protected Set<FlightControllerUpdateListener> listeners; + protected Set<FlightControllerListener> listeners; + protected GeoPoint lastLocation; + public FlightControllerDefault(SammoaContext context, Flight flight) { @@ -117,12 +119,12 @@ } @Override - public void addListener(FlightControllerUpdateListener listener) { + public void addListener(FlightControllerListener listener) { listeners.add(listener); } @Override - public void removeListener(FlightControllerUpdateListener listener) { + public void removeListener(FlightControllerListener listener) { listeners.remove(listener); } @@ -595,9 +597,7 @@ startTime = timeLog.log(startTime, "observation()", "Commited"); - for (FlightControllerUpdateListener listener : listeners) { - listener.onObservationAdded(observation); - } + fireObservationAdded(observation); timeLog.log(startTime, "observation()", "Fired"); @@ -729,7 +729,7 @@ // // if (fireEvents) { // // Fire transect changed -// for (FlightControllerUpdateListener listener : listeners) { +// for (FlightControllerListener listener : listeners) { // listener.onNextTransectChanged(nextTransect); // } // } @@ -808,6 +808,8 @@ } else { + lastLocation = geoPoint; + if (logger.isTraceEnabled()) { logger.trace("Create GPS Point : {}", geoPoint); } @@ -822,21 +824,27 @@ } return result; } + + protected void fireObservationAdded(Observation observation) { + for (FlightControllerListener listener : listeners) { + listener.onObservationAdded(new ObservationEvent(this, observation, lastLocation)); + } + } protected void fireStateChanged(FlightState state) { - for (FlightControllerUpdateListener listener : listeners) { + for (FlightControllerListener listener : listeners) { listener.onStateChanged(state); } } protected void fireRouteAdded(Route route) { - for (FlightControllerUpdateListener listener : listeners) { + for (FlightControllerListener listener : listeners) { listener.onRouteAdded(route); } } protected void fireNextTransectChanged(TransectFlight nextTransect) { - for (FlightControllerUpdateListener listener : listeners) { + for (FlightControllerListener listener : listeners) { listener.onNextTransectChanged(nextTransect); } } @@ -873,6 +881,7 @@ public void locationChanged(GpsLocationEvent event) { GeoPoint newLocation = event.getNewValue(); if (newLocation != null/* && newLocation.getTopiaId() == null*/) { + lastLocation = newLocation; newLocation.setFlight(flight); persistence.delayEntityCreation(newLocation); } Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerListener.java (from rev 361, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java) =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerListener.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerListener.java 2012-08-07 15:49:43 UTC (rev 362) @@ -0,0 +1,68 @@ +package fr.ulr.sammoa.application.flightController; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ulr.sammoa.persistence.Route; +import fr.ulr.sammoa.persistence.TransectFlight; + +/** + * Listener for all change of data in the {@link FlightController} + * + * Created: 12/07/12 + * + * @author fdesbois <desbois@codelutin.com> + * @see FlightController + */ +public interface FlightControllerListener { + + /** + * Fired when a new {@code route} has been created and added to the flight + * + * @param route The new route added + */ + void onRouteAdded(Route route); + + /** + * Fired when the next transect has been updated. + * + * @param nextTransect The next transect that will be used on + * {@link FlightController#begin()} action + */ + void onNextTransectChanged(TransectFlight nextTransect); + + /** + * Fired when controller change the {@code state} of the flight after + * each action. + * + * @param state The new state + */ + void onStateChanged(FlightState state); + + /** + * Fired when controller add a new observation + * + * @param event The event containing Observation and its associated GeoPoint + */ + void onObservationAdded(ObservationEvent event); +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java 2012-08-07 15:49:43 UTC (rev 362) @@ -1,69 +0,0 @@ -package fr.ulr.sammoa.application.flightController; -/* - * #%L - * SAMMOA :: Application - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ulr.sammoa.persistence.Observation; -import fr.ulr.sammoa.persistence.Route; -import fr.ulr.sammoa.persistence.TransectFlight; - -/** - * Listener for all change of data in the {@link FlightController} - * - * Created: 12/07/12 - * - * @author fdesbois <desbois@codelutin.com> - * @see FlightController - */ -public interface FlightControllerUpdateListener { - - /** - * Fired when a new {@code route} has been created and added to the flight - * - * @param route The new route added - */ - void onRouteAdded(Route route); - - /** - * Fired when the next transect has been updated. - * - * @param nextTransect The next transect that will be used on - * {@link FlightController#begin()} action - */ - void onNextTransectChanged(TransectFlight nextTransect); - - /** - * Fired when controller change the {@code state} of the flight after - * each action. - * - * @param state The new state - */ - void onStateChanged(FlightState state); - - /** - * Fired when controller add a new observation - * - * @param observation The new observation - */ - void onObservationAdded(Observation observation); -} Added: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/ObservationEvent.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/ObservationEvent.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/ObservationEvent.java 2012-08-07 15:49:43 UTC (rev 362) @@ -0,0 +1,61 @@ +package fr.ulr.sammoa.application.flightController; +/* + * #%L + * SAMMOA :: Application + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.persistence.Observation; + +/** + * Created: 06/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class ObservationEvent { + + protected FlightController source; + + protected Observation observation; + + protected GeoPoint geoPoint; + + public ObservationEvent(FlightController source, + Observation observation, + GeoPoint geoPoint) { + this.source = source; + this.observation = observation; + this.geoPoint = geoPoint; + } + + public FlightController getSource() { + return source; + } + + public Observation getObservation() { + return observation; + } + + public GeoPoint getGeoPoint() { + return geoPoint; + } +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/ObservationEvent.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java (rev 0) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java 2012-08-07 15:49:43 UTC (rev 362) @@ -0,0 +1,52 @@ +package fr.ulr.sammoa.persistence; +/* + * #%L + * SAMMOA :: Persistence + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaRuntimeException; + +import java.util.List; + +public class GeoPointDAOImpl<E extends GeoPoint> extends GeoPointDAOAbstract<E> { + + public List<GeoPoint> findAllByFlightOrderedByRecordTime(Flight flight) { + + List<GeoPoint> result; + + String ql = String.format("FROM %1$s WHERE %2$s = :flight ORDER BY %3$s", + GeoPointImpl.class.getSimpleName(), + GeoPoint.PROPERTY_FLIGHT, + GeoPoint.PROPERTY_RECORD_TIME + ); + + try { + result = context.findAll(ql, "flight", flight); + + } catch (TopiaException e) { + throw new TopiaRuntimeException(e); + } + return result; + } + +} //GeoPointDAOImpl<E extends GeoPoint> Property changes on: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPointDAOImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java =================================================================== --- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java (rev 0) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-08-07 15:49:43 UTC (rev 362) @@ -0,0 +1,167 @@ +package fr.ulr.sammoa.persistence; +/* + * #%L + * SAMMOA :: Persistence + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Lists; +import com.google.common.collect.Ordering; + +import java.util.Date; +import java.util.List; + +/** + * Created: 11/07/12 + * + * @author fdesbois <desbois@codelutin.com> + */ +public final class GeoPoints { + + private GeoPoints() { + // static class do not have instanciation + } + + public static List<GeoPoint> getClosestPoints(List<GeoPoint> geoPoints, Iterable<Date> dates) { + + List<GeoPoint> result = Lists.newArrayList(); + + List<Date> geoPointDates = FluentIterable + .from(geoPoints) + .transform(toDate()) + .toSortedImmutableList(Ordering.natural()); + + int index = 0; + for (Date date : dates) { + + // We continue starting from the previous index to avoid loop on all the date list + index = getClosestDateIndex(index > 0 ? index - 1 : 0, geoPointDates, date); + + result.add(geoPoints.get(index)); + } + return result; + } + + public static Function<GeoPoint, Date> toDate() { + return TO_DATE_FUNCTION; + } + + protected static Function<GeoPoint, Date> TO_DATE_FUNCTION = new Function<GeoPoint, Date>() { + + @Override + public Date apply(GeoPoint input) { + return input.getRecordTime(); + } + }; + +// protected static Date getClosestDate(List<Date> source, Date date) { +// int index = getClosestDateIndex(0, source, date); +// Date result = source.get(index); +// return result; +// } +// +// protected static Date getClosestDate(List<Date> source, Date date) { +// int size = source.size(); +// for (int index = 0; index < size; index++) { +// +// int nextIndex = index + 1; +// if (nextIndex < size) { +// +// Date before = source.get(index); +// Date after = source.get(nextIndex); +// +// // If the date is equal or before we take the current index +// if (date.equals(before) || date.before(before)) { +// return before; +// +// // If the date is before the next date, we check which one +// // of the before and after is the nearest value and we return +// // its index +// } else if (date.before(after)) { +// +// long diffBefore = date.getTime() - before.getTime(); +// long diffAfter = after.getTime() - date.getTime(); +// +// if (diffBefore <= diffAfter) { +// return before; +// +// } else { +// return after; +// } +// } +// } +// } +// // We loop over the whole list, so we return the last date +// return source.get(size - 1); +// } + + protected static int getClosestDateIndex(int startIndex, List<Date> source, Date date) { + int size = source.size(); + for (int index = startIndex; index < size; index++) { + + int nextIndex = index + 1; + if (nextIndex < size) { + + Date before = source.get(index); + Date after = source.get(nextIndex); + + // If the date is equal or before we take the current index + if (date.equals(before) || date.before(before)) { + return index; + + // If the date is before the next date, we check which one + // of the before and after is the nearest value and we return + // its index + } else if (date.before(after)) { + + long diffBefore = date.getTime() - before.getTime(); + long diffAfter = after.getTime() - date.getTime(); + + if (diffBefore <= diffAfter) { + return index; + + } else { + return nextIndex; + } + } + } + } + // We loop over the whole list, we return the last index + return size - 1; + } + +// protected static Date getNearestDate(List<Date> dates, Date currentDate) { +// long minDiff = -1; +// long currentTime = currentDate.getTime(); +// Date minDate = null; +// for (Date date : dates) { +// long diff = Math.abs(currentTime - date.getTime()); +// if ((minDiff == -1) || (diff < minDiff)) { +// minDiff = diff; +// minDate = date; +// } +// } +// return minDate; +// } + +} Property changes on: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native 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-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java 2012-08-07 15:49:43 UTC (rev 362) @@ -23,6 +23,7 @@ * #L% */ +import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import org.nuiton.util.DateUtil; @@ -39,6 +40,10 @@ private Observations() { // static class do not have instanciation } + + public static Function<Observation, Date> toDate() { + return TO_DATE_FUNCTION; + } public static boolean inRoute(Observation observation, Route route, Route nextRoute) { @@ -53,6 +58,14 @@ public static Predicate<Observation> inRoute(Route route, Route nextRoute) { return new ObservationInRoutePredicate(route, nextRoute); } + + protected static Function<Observation, Date> TO_DATE_FUNCTION = new Function<Observation, Date>() { + + @Override + public Date apply(Observation input) { + return input.getObservationTime(); + } + }; protected static class ObservationInRoutePredicate implements Predicate<Observation> { Added: trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.java =================================================================== --- trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.java (rev 0) +++ trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.java 2012-08-07 15:49:43 UTC (rev 362) @@ -0,0 +1,86 @@ +package fr.ulr.sammoa.persistence; +/* + * #%L + * SAMMOA :: Persistence + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import junit.framework.Assert; +import org.junit.Test; + +import java.util.Date; +import java.util.List; + +/** + * Created: 06/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class GeoPointsTest { + + @Test + public void testGetClosestPoints() throws Exception { + + List<GeoPoint> geoPoints = Lists.newArrayList(); + + for (int i = 0; i < 100; i++) { + + GeoPoint geoPoint = new GeoPointImpl(); + geoPoint.setRecordTime(new Date(i * 1000)); + geoPoints.add(geoPoint); + } + + List<Date> dates = Lists.newArrayList(new Date(4178), new Date(5824), new Date(85140)); + + List<GeoPoint> result = GeoPoints.getClosestPoints(geoPoints, dates); + + Assert.assertEquals(3, result.size()); + Assert.assertEquals(4000, result.get(0).getRecordTime().getTime()); + Assert.assertEquals(6000, result.get(1).getRecordTime().getTime()); + Assert.assertEquals(85000, result.get(2).getRecordTime().getTime()); + } + + @Test + public void testGetClosestPoints2() throws Exception { + + List<GeoPoint> geoPoints = Lists.newArrayList(); + { + GeoPoint geoPoint = new GeoPointImpl(); + geoPoint.setRecordTime(new Date(8000)); + geoPoints.add(geoPoint); + } + { + GeoPoint geoPoint = new GeoPointImpl(); + geoPoint.setRecordTime(new Date(15000)); + geoPoints.add(geoPoint); + } + + List<Date> dates = Lists.newArrayList(new Date(4178), new Date(8000), new Date(85140)); + + List<GeoPoint> result = GeoPoints.getClosestPoints(geoPoints, dates); + + Assert.assertEquals(3, result.size()); + Assert.assertEquals(8000, result.get(0).getRecordTime().getTime()); + Assert.assertEquals(8000, result.get(1).getRecordTime().getTime()); + Assert.assertEquals(15000, result.get(2).getRecordTime().getTime()); + } +} Property changes on: trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/GeoPointsTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/SammoaColors.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/SammoaColors.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/SammoaColors.java 2012-08-07 15:49:43 UTC (rev 362) @@ -54,8 +54,10 @@ public static final Color FLIGHT_TRACKING_LINE_COLOR = Color.RED; - public static final Color TRANSECT_LINE_COLOR = new Color(102, 0, 255); // #6600ff + public static final Color TRANSECT_LINE_COLOR = new Color(102, 0, 255); + public static final Color TRANSECT_SELECT_LINE_COLOR = new Color(255, 126, 0); + public static final Color TRANSECT_WITHOUT_GRAPHIC_BACKGROUND_COLOR = new Color(255,233,233); } Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-08-07 15:49:43 UTC (rev 362) @@ -56,6 +56,9 @@ getFlightController().getAudioRecorder().addDeviceStateListener(view.getAudioLED()); getFlightController().getGpsHandler().addDeviceStateListener(view.getGpsLED()); getFlightController().getGpsHandler().addGpsLocationListener(getModel()); + if (FlightState.OFF_EFFORT.equals(getFlightUIModel().getFlightState())) { + getModel().setEffortPanelColor(SammoaColors.ON_EFFORT_BACKGROUND_COLOR); + } } @Override 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-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-08-07 15:49:43 UTC (rev 362) @@ -37,7 +37,9 @@ import com.bbn.openmap.layer.shape.BufferedShapeLayer; import com.bbn.openmap.layer.shape.ShapeLayer; import com.bbn.openmap.omGraphics.DrawingAttributes; +import com.bbn.openmap.plugin.esri.EsriPlugIn; import com.bbn.openmap.proj.coords.LatLonPoint; +import com.bbn.openmap.util.PropUtils; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -55,18 +57,22 @@ import fr.ulr.sammoa.application.device.gps.GpsLocationListener; import fr.ulr.sammoa.application.flightController.FlightController; import fr.ulr.sammoa.application.flightController.FlightControllerDefault; -import fr.ulr.sammoa.application.flightController.FlightControllerUpdateListener; +import fr.ulr.sammoa.application.flightController.FlightControllerListener; import fr.ulr.sammoa.application.flightController.FlightState; +import fr.ulr.sammoa.application.flightController.ObservationEvent; import fr.ulr.sammoa.persistence.Campaign; import fr.ulr.sammoa.persistence.Flight; import fr.ulr.sammoa.persistence.GeoPoint; +import fr.ulr.sammoa.persistence.GeoPoints; import fr.ulr.sammoa.persistence.Observation; +import fr.ulr.sammoa.persistence.Observations; import fr.ulr.sammoa.persistence.Observer; import fr.ulr.sammoa.persistence.Route; import fr.ulr.sammoa.persistence.Strate; import fr.ulr.sammoa.persistence.Transect; import fr.ulr.sammoa.persistence.TransectFlight; import fr.ulr.sammoa.persistence.TransectFlights; +import fr.ulr.sammoa.ui.swing.SammoaColors; import fr.ulr.sammoa.ui.swing.SammoaDecoratorProvider; import fr.ulr.sammoa.ui.swing.SammoaUIContext; import fr.ulr.sammoa.ui.swing.SammoaUIHandler; @@ -81,8 +87,9 @@ import fr.ulr.sammoa.ui.swing.action.RightObservationAction; import fr.ulr.sammoa.ui.swing.action.StartAction; import fr.ulr.sammoa.ui.swing.action.StopAction; -import fr.ulr.sammoa.ui.swing.flight.layer.GpsTracingLayer; -import fr.ulr.sammoa.ui.swing.flight.layer.StrateLayer; +import fr.ulr.sammoa.ui.swing.flight.layer.BaseGeoPointLayer; +import fr.ulr.sammoa.ui.swing.flight.layer.LineGeoPointLayer; +import fr.ulr.sammoa.ui.swing.flight.layer.SimpleGeoPointLayer; import fr.ulr.sammoa.ui.swing.flight.layer.TransectLayer; import fr.ulr.sammoa.ui.swing.transect.TransectUI; import fr.ulr.sammoa.ui.swing.util.SammoaUtil; @@ -114,7 +121,7 @@ * * @author fdesbois <desbois@codelutin.com> */ -public class FlightUIHandler implements SammoaUIHandler, FlightControllerUpdateListener { +public class FlightUIHandler implements SammoaUIHandler, FlightControllerListener { private static final Logger logger = LoggerFactory.getLogger(FlightUIHandler.class); @@ -130,6 +137,10 @@ protected TransectUI transectUi; + protected BaseGeoPointLayer observationLayer; + + protected BaseGeoPointLayer flightLayer; + public FlightUIHandler(SammoaUIContext context, FlightUI ui) { this.context = context; @@ -195,6 +206,17 @@ List<Observer> observers = getFlightService().getFlightObserverForPositions(flight); List<Observation> observations = getFlightService().getObservations(flight); List<Route> routes = getFlightService().getRoutes(flight); + List<GeoPoint> geoPoints = getFlightService().getFlightGeoPoints(flight); + + if (logger.isDebugEnabled()) { + for (GeoPoint geoPoint : geoPoints) { + logger.debug(String.format("GeoPoint={%1$tH:%1$tM:%1$tS,%2$f,%3$f}", + geoPoint.getRecordTime(), + geoPoint.getLatitude(), + geoPoint.getLongitude()) + ); + } + } // List<Strate> strates = getReferentialService().getAllStrates(campaign); List<Transect> transects = getReferentialService().getAllTransects(campaign); @@ -225,6 +247,8 @@ } flightController.addListener(this); + flightController.getGpsHandler().addGpsLocationListener(gpsLocationListener); + flightController.init(); FlightUIModel model = new FlightUIModel(); @@ -234,6 +258,7 @@ model.setFlightObserverForPositions(observers); model.setObservations(observations); model.setRoutes(routes); + model.setGeoPoints(geoPoints); model.setStrates(prepareStrates(transects)); @@ -380,20 +405,6 @@ initMapHandler(); - getFlightController().getGpsHandler().addGpsLocationListener( - new GpsLocationListener() { - - @Override - public void locationChanged(GpsLocationEvent event) { - GeoPoint newLocation = event.getNewValue(); - if (newLocation != null && getModel().isMapFollow()) { - MapBean mapBean = getOverlayMapPanel().getMapBean(); - mapBean.setCenter(new LatLonPoint.Double(newLocation.getLatitude(), - newLocation.getLongitude())); - } - } - }); - timeLog.log(startTime, "afterInitUI", "map is initialized"); } @@ -431,8 +442,15 @@ } @Override - public void onObservationAdded(Observation observation) { + public void onObservationAdded(ObservationEvent event) { + Observation observation = event.getObservation(); getModel().addObservation(observation); + + // Add the GeoPoint to the layer + GeoPoint geoPoint = event.getGeoPoint(); + if (geoPoint != null) { + observationLayer.addGeoPoint(geoPoint); + } } public void selectStrate(StrateModel strate) { @@ -702,65 +720,131 @@ mapHandler.add(new OMMouseMode()); mapHandler.add(new ToolPanel()); - // Ajout du fond : carte politique du monde stockée dans un fichier shapefile - - File backgroundShapeFile = getConfig().getBackgroundShapeFile(); - if (backgroundShapeFile != null && backgroundShapeFile.exists()) { - - ShapeLayer shapeLayer = new BufferedShapeLayer(); - Properties properties = new Properties(); - properties.put("prettyName", "Political Solid"); - properties.put(DrawingAttributes.linePaintProperty, "ff000000"); - properties.put(DrawingAttributes.fillPaintProperty, "ffbdde83"); - String path = backgroundShapeFile.getAbsolutePath(); -// String path = SammoaConfig.SammoaConfigOption.BACKGROUND_SHAPE_FILE.getDefaultValue(); - properties.put(ShapeLayer.shapeFileProperty, path); - shapeLayer.setProperties(properties); - mapHandler.add(shapeLayer); + // BackgroundLayer + { + File backgroundShapeFile = getConfig().getBackgroundShapeFile(); + if (backgroundShapeFile != null && backgroundShapeFile.exists()) { + + Properties properties = new Properties(); + properties.put("prettyName", "Political Solid"); + properties.put(DrawingAttributes.linePaintProperty, "ff000000"); + properties.put(DrawingAttributes.fillPaintProperty, "ffbdde83"); + String path = backgroundShapeFile.getAbsolutePath(); + properties.put(ShapeLayer.shapeFileProperty, path); + + ShapeLayer shapeLayer = new BufferedShapeLayer(); + shapeLayer.setProperties(properties); + + mapHandler.add(shapeLayer); + } } -// File strateFile = getConfig().getStrateShapeFile(); String campaignId = getModel().getFlight().getCampaign().getTopiaId(); File mapDirectory = new File(new File(new File(getConfig().getDataDirectory(), "campaign"), campaignId), "map"); - File strateFile = new File(mapDirectory, "strates.shp"); - if (strateFile.exists()) { - mapHandler.add(new StrateLayer(strateFile, getModel())); - } else { - logger.warn("No strate file is defined, the file must be " + - "defined here: {}", strateFile.getAbsolutePath()); - } + // StrateLayer + { + File file = new File(mapDirectory, "strates.shp"); + if (file.exists()) { -// File transectFile = getConfig().getTransectShapeFile(); - File transectFile = new File(mapDirectory, "transects.shp"); - if (transectFile.exists()) { - mapHandler.add(new TransectLayer(transectFile, getModel())); + Properties properties = new Properties(); + properties.put("prettyName", "Strates"); + properties.put(ShapeLayer.shapeFileProperty, file.toURI().getPath()); +// properties.put(EsriPlugIn.PARAM_SHP, file.toURI().getPath()); - } else { - logger.warn("No transect file is defined, the file must be " + - "defined here: {}", transectFile.getAbsolutePath()); + ShapeLayer strateLayer = new BufferedShapeLayer(); + strateLayer.setProperties(properties); + +// EsriPlugIn esriPlugIn = new EsriPlugIn(); +// esriPlugIn.setProperties(properties); +// +// PlugInLayer strateLayer = new PlugInLayer(); +// strateLayer.setPlugIn(esriPlugIn); + + mapHandler.add(strateLayer); + + } else { + logger.warn("No strate file is defined, the file must be " + + "defined here: {}", file.getAbsolutePath()); + } } - // Ajout d'un layer pour représenter les points relevés par le GPS - GpsTracingLayer gpsTracingLayer = new GpsTracingLayer(); - getFlightController().getGpsHandler().addGpsLocationListener(gpsTracingLayer); - mapHandler.add(gpsTracingLayer); + // TransectLayer + { + File file = new File(mapDirectory, "transects.shp"); + if (file.exists()) { - InformationDelegator informationDelegator = new InformationDelegator(); - informationDelegator.setShowLights(false); + Properties properties = new Properties(); + properties.put("prettyName", "Transects"); + properties.put(EsriPlugIn.PARAM_SHP, file.toURI().getPath()); + String lineColor = PropUtils.getProperty(SammoaColors.TRANSECT_LINE_COLOR); + properties.put(DrawingAttributes.linePaintProperty, lineColor); + String selectColor = PropUtils.getProperty(SammoaColors.TRANSECT_SELECT_LINE_COLOR); + properties.put(DrawingAttributes.selectPaintProperty, selectColor); - // add combo box to informationDelegator - JCheckBox followMapCheckBox = new JCheckBox(_("sammoa.map.mapFollow")); - followMapCheckBox.addItemListener(new ItemListener() { + EsriPlugIn esriPlugIn = new EsriPlugIn(); + esriPlugIn.setProperties(properties); - @Override - public void itemStateChanged(ItemEvent e) { - getModel().setMapFollow(e.getStateChange() == ItemEvent.SELECTED); + TransectLayer transectLayer = new TransectLayer(); + transectLayer.setPlugIn(esriPlugIn); + transectLayer.init(getModel()); + + mapHandler.add(transectLayer); + + } else { + logger.warn("No transect file is defined, the file must be " + + "defined here: {}", file.getAbsolutePath()); } - }); - informationDelegator.add(followMapCheckBox); + } - mapHandler.add(informationDelegator); + // FlightLayer (used also for GPS tracking) + { + Properties properties = new Properties(); + String lineColor = PropUtils.getProperty(SammoaColors.FLIGHT_TRACKING_LINE_COLOR); + properties.put(DrawingAttributes.linePaintProperty, lineColor); + + flightLayer = new LineGeoPointLayer(); + flightLayer.setProperties(properties); + flightLayer.setGeoPoints(getModel().getGeoPoints()); + + mapHandler.add(flightLayer); + } + + // ObservationLayer + { + Properties properties = new Properties(); + properties.put(DrawingAttributes.PointOvalProperty, "true"); + + observationLayer = new SimpleGeoPointLayer(); + observationLayer.setProperties(properties); + + List<GeoPoint> geoPoints = GeoPoints.getClosestPoints( + getModel().getGeoPoints(), + Iterables.transform(getModel().getObservations(), Observations.toDate()) + ); + observationLayer.setGeoPoints(geoPoints); + + mapHandler.add(observationLayer); + } + + // InformationDelegator with JCheckBox for mapFollow property + { + InformationDelegator informationDelegator = new InformationDelegator(); + informationDelegator.setShowLights(false); + + // add combo box to informationDelegator + JCheckBox followMapCheckBox = new JCheckBox(_("sammoa.map.mapFollow")); + followMapCheckBox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + getModel().setMapFollow(e.getStateChange() == ItemEvent.SELECTED); + } + }); + informationDelegator.add(followMapCheckBox); + + mapHandler.add(informationDelegator); + } } protected PropertyChangeListener transectFlightListener = new PropertyChangeListener() { @@ -788,6 +872,30 @@ } }; + protected GpsLocationListener gpsLocationListener = new GpsLocationListener() { + + @Override + public void locationChanged(GpsLocationEvent event) { + + GeoPoint location = event.getNewValue(); + if (location != null) { + + // Add the GeoPoint to the layer + if (flightLayer != null) { + flightLayer.addGeoPoint(location); + } + + // Center the map on the location if mapFollow is activated + if (getModel().isMapFollow()) { + MapBean mapBean = getOverlayMapPanel().getMapBean(); + LatLonPoint center = new LatLonPoint.Double( + location.getLatitude(), location.getLongitude()); + mapBean.setCenter(center); + } + } + } + }; + protected ComponentListener transectUIListener = new ComponentListener() { @Override Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIModel.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIModel.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIModel.java 2012-08-07 15:49:43 UTC (rev 362) @@ -28,6 +28,7 @@ import com.google.common.collect.Lists; import fr.ulr.sammoa.application.flightController.FlightState; import fr.ulr.sammoa.persistence.Flight; +import fr.ulr.sammoa.persistence.GeoPoint; import fr.ulr.sammoa.persistence.Observation; import fr.ulr.sammoa.persistence.Observations; import fr.ulr.sammoa.persistence.Observer; @@ -83,6 +84,8 @@ public static final String PROPERTY_TRANSECT_SELECTION_EXISTS = "transectSelectionExists"; + public static final String PROPERTY_GEO_POINTS = "geoPoints"; + protected Flight flight; protected List<Observer> observers; @@ -137,6 +140,8 @@ protected List<TransectFlightModel> transectFlights; + protected List<GeoPoint> geoPoints; + protected SwingValidatorMessageTableModel validatorTableModel = new SwingValidatorMessageTableModel(); @@ -408,4 +413,17 @@ this.transectFlights = transectFlights; firePropertyChange(PROPERTY_TRANSECT_FLIGHTS, oldValue, transectFlights); } + + public List<GeoPoint> getGeoPoints() { + if (geoPoints == null) { + geoPoints = Lists.newArrayList(); + } + return geoPoints; + } + + public void setGeoPoints(List<GeoPoint> geoPoints) { + List<GeoPoint> oldValue = Lists.newArrayList(getGeoPoints()); + this.geoPoints = geoPoints; + firePropertyChange(PROPERTY_GEO_POINTS, oldValue, geoPoints); + } } Added: 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 (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java 2012-08-07 15:49:43 UTC (rev 362) @@ -0,0 +1,91 @@ +package fr.ulr.sammoa.ui.swing.flight.layer; +/* + * #%L + * SAMMOA :: UI Swing + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.bbn.openmap.layer.OMGraphicHandlerLayer; +import com.bbn.openmap.omGraphics.DrawingAttributes; +import com.bbn.openmap.omGraphics.OMGraphic; +import com.bbn.openmap.omGraphics.OMGraphicList; +import fr.ulr.sammoa.persistence.GeoPoint; + +import java.util.List; +import java.util.Properties; + +/** + * Created: 06/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public abstract class BaseGeoPointLayer extends OMGraphicHandlerLayer { + + protected DrawingAttributes drawingAttributes = DrawingAttributes.getDefaultClone(); + + public void setGeoPoints(List<GeoPoint> geoPoints) { + setList(new OMGraphicList()); + + for (GeoPoint geoPoint : geoPoints) { + addGraphic(geoPoint); + } + } + + public void addGeoPoint(GeoPoint geoPoint) { + + addGraphic(geoPoint); + + // Need to generate the projection to apply change + getList().generate(getProjection()); + + // Refresh the view + repaint(); + } + + @Override + public void setProperties(String prefix, Properties props) { + super.setProperties(prefix, props); + drawingAttributes.setProperties(prefix, props); + } + + @Override + public Properties getProperties(Properties props) { + Properties result = super.getProperties(props); + drawingAttributes.getProperties(result); + return result; + } + + @Override + public Properties getPropertyInfo(Properties list) { + Properties result = super.getPropertyInfo(list); + drawingAttributes.getPropertyInfo(list); + return result; + } + + protected void addGraphic(GeoPoint geoPoint) { + OMGraphic graphic = newGraphic(geoPoint); + drawingAttributes.setTo(graphic); + graphic.setAppObject(geoPoint); + getList().add(graphic); + } + + protected abstract OMGraphic newGraphic(GeoPoint geoPoint); +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseReferentialLayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseReferentialLayer.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseReferentialLayer.java 2012-08-07 15:49:43 UTC (rev 362) @@ -1,85 +0,0 @@ -/* - * #%L - * SAMMOA :: UI Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ulr.sammoa.ui.swing.flight.layer; - -import com.bbn.openmap.dataAccess.shape.EsriGraphicList; -import com.bbn.openmap.plugin.PlugInLayer; -import com.bbn.openmap.plugin.esri.EsriPlugIn; -import com.google.common.base.Preconditions; -import fr.ulr.sammoa.persistence.Campaign; -import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; - -import java.io.File; -import java.util.Properties; - -/** - * Created: 12/06/12 - * - * @author fdesbois <desbois@codelutin.com> - */ -public abstract class BaseReferentialLayer extends PlugInLayer { - - protected Campaign campaign; - - protected FlightUIModel model; - - public BaseReferentialLayer(String name, File shapeFile, FlightUIModel model) { - - Preconditions.checkNotNull(shapeFile); - Preconditions.checkArgument(shapeFile.exists(), - "Shape file " + shapeFile.getAbsolutePath() + " doesn't exist"); - - this.model = model; - this.campaign = model.getFlight().getCampaign(); - - EsriPlugIn esriPlugIn = new EsriPlugIn(); - Properties properties = new Properties(); - properties.put("prettyName", name); - String shapePath = shapeFile.toURI().getPath(); - properties.put(EsriPlugIn.PARAM_SHP, shapePath); - - onInitProperties(properties); - - esriPlugIn.setProperties(properties); - - setPlugIn(esriPlugIn); - setVisible(true); - } - - public FlightUIModel getModel() { - return model; - } - - @Override - public EsriGraphicList getList() { - return getEsriPlugin().getEsriGraphicList(); - } - protected EsriPlugIn getEsriPlugin() { - return (EsriPlugIn) getPlugIn(); - } - - protected abstract void onInitProperties(Properties properties); - -} Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java 2012-08-07 15:49:43 UTC (rev 362) @@ -1,90 +0,0 @@ -/* - * #%L - * SAMMOA :: Application - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ulr.sammoa.ui.swing.flight.layer; - -import com.bbn.openmap.layer.OMGraphicHandlerLayer; -import com.bbn.openmap.omGraphics.OMGraphic; -import com.bbn.openmap.omGraphics.OMGraphicConstants; -import com.bbn.openmap.omGraphics.OMGraphicList; -import com.bbn.openmap.omGraphics.OMLine; -import fr.ulr.sammoa.application.device.gps.GpsLocationEvent; -import fr.ulr.sammoa.application.device.gps.GpsLocationListener; -import fr.ulr.sammoa.persistence.GeoPoint; -import fr.ulr.sammoa.persistence.GeoPointImpl; -import fr.ulr.sammoa.ui.swing.SammoaColors; - -/** - * Un layer OpenMap qui affiche les points envoyés par le GPS. - */ -public class GpsTracingLayer extends OMGraphicHandlerLayer implements GpsLocationListener { - -// private static final Logger logger = LoggerFactory.getLogger(GpsTracingLayer.class); - - protected GeoPoint currentLocation; - - public GpsTracingLayer() { - - // Initialize the list - setList(new OMGraphicList()); - } - - @Override - public void locationChanged(GpsLocationEvent event) { -// OMGraphic point = new OMPoint(newLocation.getLatitude(), newLocation.getLongitude()); - - GeoPoint newLocation = event.getNewValue(); - - if (currentLocation == null) { - - // do not display the first location point - - } else if (newLocation != null) { - - // Create the line between the currentLocation and the new one - OMGraphic line = new OMLine( - currentLocation.getLatitude(), - currentLocation.getLongitude(), - newLocation.getLatitude(), - newLocation.getLongitude(), - OMGraphicConstants.LINETYPE_GREATCIRCLE - ); - line.setLinePaint(SammoaColors.FLIGHT_TRACKING_LINE_COLOR); - - // Add the new line to the GraphicList - getList().add(line); - - // Need to generate the projection to apply change - getList().generate(getProjection()); -// line.generate(getProjection()); - - // Refresh the view - repaint(); - } - - if (newLocation != null) { - currentLocation = new GeoPointImpl(newLocation.getLatitude(), newLocation.getLongitude()); - } - } -} Added: 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 (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java 2012-08-07 15:49:43 UTC (rev 362) @@ -0,0 +1,63 @@ +package fr.ulr.sammoa.ui.swing.flight.layer; +/* + * #%L + * SAMMOA :: UI Swing + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.bbn.openmap.omGraphics.OMGraphic; +import com.bbn.openmap.omGraphics.OMGraphicConstants; +import com.bbn.openmap.omGraphics.OMLine; +import com.bbn.openmap.omGraphics.OMPoint; +import com.google.common.collect.Iterables; +import fr.ulr.sammoa.persistence.GeoPoint; + +/** + * Created: 07/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class LineGeoPointLayer extends BaseGeoPointLayer { + + @Override + protected OMGraphic newGraphic(GeoPoint geoPoint) { + + OMGraphic result; + if (!getList().isEmpty()) { + + OMGraphic lastGraphic = Iterables.getLast(getList()); + + GeoPoint previousPoint = (GeoPoint) lastGraphic.getAppObject(); + + result = new OMLine( + previousPoint.getLatitude(), + previousPoint.getLongitude(), + geoPoint.getLatitude(), + geoPoint.getLongitude(), + OMGraphicConstants.LINETYPE_GREATCIRCLE + ); + + } else { + result = new OMPoint(geoPoint.getLatitude(), geoPoint.getLongitude()); + } + return result; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/SimpleGeoPointLayer.java (from rev 361, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/StrateLayer.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/SimpleGeoPointLayer.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/SimpleGeoPointLayer.java 2012-08-07 15:49:43 UTC (rev 362) @@ -0,0 +1,41 @@ +package fr.ulr.sammoa.ui.swing.flight.layer; +/* + * #%L + * SAMMOA :: UI Swing + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 UMS 3462, Code Lutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.bbn.openmap.omGraphics.OMPoint; +import fr.ulr.sammoa.persistence.GeoPoint; + +/** + * Created: 07/08/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public class SimpleGeoPointLayer extends BaseGeoPointLayer { + + @Override + protected OMPoint newGraphic(GeoPoint geoPoint) { + OMPoint result = new OMPoint(geoPoint.getLatitude(), geoPoint.getLongitude()); + return result; + } +} Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/SimpleGeoPointLayer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/StrateLayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/StrateLayer.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/StrateLayer.java 2012-08-07 15:49:43 UTC (rev 362) @@ -1,48 +0,0 @@ -/* - * #%L - * SAMMOA :: UI Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 UMS 3462, Code Lutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ulr.sammoa.ui.swing.flight.layer; - -import com.bbn.openmap.plugin.esri.EsriPlugIn; -import fr.ulr.sammoa.ui.swing.flight.FlightUIModel; - -import java.io.File; -import java.util.Properties; - -/** - * Created: 12/06/12 - * - * @author fdesbois <desbois@codelutin.com> - */ -public class StrateLayer extends BaseReferentialLayer { - - public StrateLayer(File shapeFile, FlightUIModel model) { - super("Strates", shapeFile, model); - } - - @Override - protected void onInitProperties(Properties properties) { - properties.put(EsriPlugIn.SHAPE_DBF_LINECOLOR, "ff000000"); - } -} Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/TransectLayer.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/TransectLayer.java 2012-08-07 15:49:18 UTC (rev 361) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/TransectLayer.java 2012-08-07 15:49:43 UTC (rev 362) @@ -24,7 +24,9 @@ */ package fr.ulr.sammoa.ui.swing.flight.layer; +import com.bbn.openmap.dataAccess.shape.EsriGraphicList; import com.bbn.openmap.omGraphics.OMGraphic; +import com.bbn.openmap.plugin.PlugInLayer; import com.bbn.openmap.plugin.esri.EsriPlugIn; import fr.ulr.sammoa.application.flightController.FlightState; import fr.ulr.sammoa.persistence.Route; @@ -37,26 +39,26 @@ import java.awt.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.Properties; /** * Created: 12/06/12 * * @author fdesbois <desbois@codelutin.com> */ -public class TransectLayer extends BaseReferentialLayer implements PropertyChangeListener { - - public TransectLayer(File shapeFile, - FlightUIModel model) { +public class TransectLayer extends PlugInLayer implements PropertyChangeListener { - super("Transects", shapeFile, model); - for (TransectModel transect : model.getTransects()) { + protected FlightUIModel model; + + public void init(FlightUIModel model) { + + this.model = model; + + for (TransectModel transect : getModel().getTransects()) { transect.addPropertyChangeListener(this); } - model.addPropertyChangeListener(FlightUIModel.PROPERTY_FLIGHT_STATE, this); - model.addPropertyChangeListener(FlightUIModel.PROPERTY_CURRENT_ROUTE, this); - model.addPropertyChangeListener(FlightUIModel.PROPERTY_NEXT_TRANSECT, this); + getModel().addPropertyChangeListener(FlightUIModel.PROPERTY_FLIGHT_STATE, this); + getModel().addPropertyChangeListener(FlightUIModel.PROPERTY_CURRENT_ROUTE, this); + getModel().addPropertyChangeListener(FlightUIModel.PROPERTY_NEXT_TRANSECT, this); // Visibility ensureVisible(); @@ -74,12 +76,18 @@ } } - @Override - protected void onInitProperties(Properties properties) { - properties.put(EsriPlugIn.SHAPE_DBF_LINECOLOR, "6600ff"); - properties.put(EsriPlugIn.SHAPE_DBF_SELECTCOLOR, "ff7e00"); + protected EsriGraphicList getEsriGraphicList() { + return getEsriPlugin().getEsriGraphicList(); } + protected EsriPlugIn getEsriPlugin() { + return (EsriPlugIn) getPlugIn(); + } + + protected FlightUIModel getModel() { + return model; + } + @Override public void propertyChange(PropertyChangeEvent evt) { @@ -94,7 +102,7 @@ if (graphicIndex != null) { - OMGraphic graphic = getList().get(graphicIndex); + OMGraphic graphic = getEsriGraphicList().get(graphicIndex); checkVisible(transect, getModel().getFlightState(), graphic); @@ -110,7 +118,7 @@ if (graphicIndex != null) { - OMGraphic graphic = getList().get(graphicIndex); + OMGraphic graphic = getEsriGraphicList().get(graphicIndex); boolean visible = checkVisible(transect, getModel().getFlightState(), graphic); @@ -138,7 +146,7 @@ if (graphicIndex != null) { - OMGraphic graphic = getList().get(graphicIndex); + OMGraphic graphic = getEsriGraphicList().get(graphicIndex); boolean value = (Boolean) evt.getNewValue(); graphic.setMatted(value); @@ -202,7 +210,7 @@ if (graphicIndex != null) { - OMGraphic graphic = getList().get(graphicIndex); + OMGraphic graphic = getEsriGraphicList().get(graphicIndex); if (colorChanged != null) { graphic.setLinePaint(colorChanged); @@ -222,7 +230,7 @@ if (graphicIndex != null) { - OMGraphic graphic = getList().get(graphicIndex); + OMGraphic graphic = getEsriGraphicList().get(graphicIndex); checkVisible(transect, getModel().getFlightState(), graphic); graphic.regenerate(getProjection());