Sammoa-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- 446 discussions
r365 - trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map
by tchemit@users.forge.codelutin.com 08 Aug '12
by tchemit@users.forge.codelutin.com 08 Aug '12
08 Aug '12
Author: tchemit
Date: 2012-08-08 14:36:48 +0200 (Wed, 08 Aug 2012)
New Revision: 365
Url: http://forge.codelutin.com/repositories/revision/sammoa/365
Log:
remove speciesTypes from ExportMapModel
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapModel.java
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapModel.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapModel.java 2012-08-08 12:36:20 UTC (rev 364)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapModel.java 2012-08-08 12:36:48 UTC (rev 365)
@@ -28,7 +28,6 @@
import fr.ulr.sammoa.persistence.RouteType;
import fr.ulr.sammoa.persistence.Species;
import fr.ulr.sammoa.persistence.Strate;
-import fr.ulr.sammoa.persistence.StringRef;
import java.io.File;
import java.io.Serializable;
@@ -52,8 +51,7 @@
Date endDate,
List<Strate> strates,
List<RouteType> routeTypes,
- List<Species> species,
- List<StringRef> speciesTypes) {
+ List<Species> species) {
ExportMapModel result = new ExportMapModel();
result.exportDirectory=exportDirectory;
result.exportFilename=exportFilename;
@@ -63,8 +61,6 @@
result.strates = strates;
result.routeTypes = routeTypes;
result.species = species;
- result.speciesTypes = speciesTypes;
-
return result;
}
@@ -80,8 +76,6 @@
protected List<Species> species;
- protected List<StringRef> speciesTypes;
-
protected File exportDirectory;
protected String exportFilename;
@@ -127,11 +121,4 @@
return species;
}
- public List<StringRef> getSpeciesTypes() {
- if (speciesTypes == null) {
- speciesTypes = Lists.newArrayList();
- }
- return speciesTypes;
- }
-
}
1
0
r364 - trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application
by tchemit@users.forge.codelutin.com 08 Aug '12
by tchemit@users.forge.codelutin.com 08 Aug '12
08 Aug '12
Author: tchemit
Date: 2012-08-08 14:36:20 +0200 (Wed, 08 Aug 2012)
New Revision: 364
Url: http://forge.codelutin.com/repositories/revision/sammoa/364
Log:
remove unused method
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ReferentialService.java
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ReferentialService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ReferentialService.java 2012-08-08 12:35:34 UTC (rev 363)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ReferentialService.java 2012-08-08 12:36:20 UTC (rev 364)
@@ -615,22 +615,6 @@
return result;
}
- public List<Species> getAllSpecies() {
- TopiaContext tx = persistence.beginTransaction();
- try {
-
- List<Species> result = SammoaDAOHelper.getSpeciesDAO(tx).findAll();
- return result;
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(tx);
- }
-
- }
-
public int importObservers(String campaignId, Reader reader) {
TopiaContext transaction = persistence.beginTransaction();
1
0
r363 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing
by tchemit@users.forge.codelutin.com 08 Aug '12
by tchemit@users.forge.codelutin.com 08 Aug '12
08 Aug '12
Author: tchemit
Date: 2012-08-08 14:35:34 +0200 (Wed, 08 Aug 2012)
New Revision: 363
Url: http://forge.codelutin.com/repositories/revision/sammoa/363
Log:
can edit gpsHandlerClass from config
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-08-07 15:49:43 UTC (rev 362)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-08-08 12:35:34 UTC (rev 363)
@@ -25,6 +25,7 @@
package fr.ulr.sammoa.application;
import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import fr.ulr.sammoa.application.device.gps.GpsConfig;
import fr.ulr.sammoa.persistence.AutoSaveListener;
@@ -36,7 +37,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.swing.*;
+import javax.swing.KeyStroke;
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -51,7 +52,7 @@
* @author sletellier <letellier(a)codelutin.com>
* @author fdesbois <fdesbois(a)codelutin.com>
*/
-public class SammoaConfig {
+public class SammoaConfig implements Supplier<ApplicationConfig> {
/**
* Logger.
@@ -78,10 +79,12 @@
public static final String PROPERTY_CIRCLE_BACK = "circleBack";
+ public static final String PROPERTY_GPS_CONFIG = "gpsConfig";
+
/**
* Delegate application config object containing configuration.
*/
- protected ApplicationConfig applicationConfig;
+ protected final ApplicationConfig applicationConfig;
protected GpsConfig gpsConfig;
@@ -109,6 +112,11 @@
logger.debug("parsed options in config file {}", applicationConfig.getOptions());
}
+ @Override
+ public ApplicationConfig get() {
+ return applicationConfig;
+ }
+
public ApplicationConfig getApplicationConfig() {
return applicationConfig;
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java 2012-08-07 15:49:43 UTC (rev 362)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java 2012-08-08 12:35:34 UTC (rev 363)
@@ -2,8 +2,8 @@
/*
* #%L
* SAMMOA :: Application
- * $Id:$
- * $HeadURL:$
+ * $Id$
+ * $HeadURL$
* %%
* Copyright (C) 2012 UMS 3462, Code Lutin
* %%
@@ -36,6 +36,8 @@
*/
public class GpsConfig {
+ public static final String PROPERTY_GPS_HNALDER_CLASS = "gpsHandlerClass";
+
protected ApplicationConfig applicationConfig;
public GpsConfig(ApplicationConfig applicationConfig) {
@@ -54,6 +56,16 @@
}
/**
+ * @param newValue new handler class to set in configuration
+ * @since 0.5
+ */
+ public void setGpsHandlerClass(Class<?> newValue) {
+ applicationConfig.setOption(
+ GpsConfig.GpsConfigOption.GPS_HANDLER.getKey(),
+ newValue.getName());
+ }
+
+ /**
* @return {@link GpsConfigOption#GPS_CHECK_PERIOD} value
*/
public int getCheckPeriod() {
@@ -90,7 +102,7 @@
/** Implementation class for GpsHandler */
GPS_HANDLER("gps.handler",
n_("sammoa.config.gps.handler"),
- "fr.ulr.sammoa.application.device.gps.GpsHandlerGpsylon",
+ GpsHandlerGpsylon.class.getName(),
Class.class
),
/** Period time in seconds for each check of the gps to update location */
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-07 15:49:43 UTC (rev 362)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-08 12:35:34 UTC (rev 363)
@@ -217,7 +217,7 @@
public void showConfig() {
SammoaConfig config = context.getConfig();
- ConfigUIHelper helper = new ConfigUIHelper(config.getApplicationConfig());
+ ConfigUIHelper helper = new ConfigUIHelper(config);
helper.registerCallBack(
"ui",
@@ -307,9 +307,10 @@
}
});
helper.addCategory(n_("sammoa.config.category.gps"),
- n_("sammoa.config.category.gps.description"));
-// helper.addOption(GpsConfig.GpsConfigOption.GPS_HANDLER);
-// helper.setOptionCallBack("gps");
+ n_("sammoa.config.category.gps.description"));
+ helper.addOption(GpsConfig.GpsConfigOption.GPS_HANDLER,
+ SammoaConfig.PROPERTY_GPS_CONFIG + "." + GpsConfig.PROPERTY_GPS_HNALDER_CLASS);
+ helper.setOptionCallBack("gps");
helper.addOption(GpsConfig.GpsConfigOption.GPS_DEVICE);
helper.setOptionCallBack("gps");
helper.addOption(GpsConfig.GpsConfigOption.GPS_SPEED);
1
0
07 Aug '12
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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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());
1
0
07 Aug '12
Author: fdesbois
Date: 2012-08-07 17:49:18 +0200 (Tue, 07 Aug 2012)
New Revision: 361
Url: http://forge.codelutin.com/repositories/revision/sammoa/361
Log:
refs #1193 : move FlightController in proper package
Added:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/
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-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightState.java
Removed:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerUpdateListener.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightState.java
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/BaseHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/SammoaUIContext.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/AddAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/BeginAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/EndAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ObservationAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StartAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StopAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/campaign/CampaignUI.jaxx
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx
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/FlightUI.jaxx
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
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.jaxx
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -1,285 +0,0 @@
-package fr.ulr.sammoa.application;
-/*
- * #%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.application.device.DeviceTechnicalException;
-import fr.ulr.sammoa.application.device.audio.AudioRecorder;
-import fr.ulr.sammoa.application.device.audio.AudioRecorderDefault;
-import fr.ulr.sammoa.application.device.gps.GpsConfig;
-import fr.ulr.sammoa.application.device.gps.GpsHandler;
-import fr.ulr.sammoa.persistence.GeoPoint;
-import fr.ulr.sammoa.persistence.Observation;
-import fr.ulr.sammoa.persistence.ObservationStatus;
-import fr.ulr.sammoa.persistence.Position;
-import fr.ulr.sammoa.persistence.Route;
-import fr.ulr.sammoa.persistence.RouteType;
-import fr.ulr.sammoa.persistence.TransectFlight;
-
-/**
- * The FlightController is the main service used to do all actions during a
- * flight. It is synchronized with the audio and GPS devices. It can be
- * initialized with a flight that already started, the actions allowed depends on
- * flight state.
- * <p/>
- * Created: 12/07/12
- *
- * @author fdesbois <desbois(a)codelutin.com>
- * @see FlightState
- */
-public interface FlightController {
-
- /**
- * @return the {@link FlightState}
- */
- FlightState getState();
-
- /**
- * @return the {@link AudioRecorderDefault} used to save audio files
- */
- AudioRecorder getAudioRecorder();
-
- /**
- * @return the {@link GpsHandler} used to retrieve GPS {@link GeoPoint} and
- * save them.
- */
- GpsHandler getGpsHandler();
-
- /**
- * @param config GpsConfig to initialize the Gps
- * @exception fr.ulr.sammoa.application.device.DeviceTechnicalException if the gps device can't be opened properly
- */
- void openGpsDevice(GpsConfig config) throws DeviceTechnicalException;
-
- /**
- * @exception DeviceTechnicalException if the audio device can't be opened properly
- */
- void openAudioDevice() throws DeviceTechnicalException;
-
- /**
- * @return The current {@link Route}
- */
- Route getCurrentRoute();
-
- /**
- * @return The next {@link TransectFlight}
- */
- TransectFlight getNextTransect();
-
- /**
- * Initialize all data of FlightController depends on the current flight state.
- * If the flight is running ({@link #isRunning()}), the devices will be started and
- * recording if necessary.
- * <p/>
- * You must call init method to ensure the {@link FlightState}.
- */
- void init();
-
- /**
- * Start operation. This will set the {@code beginDate} of the flight, then
- * a new {@link RouteType#TRANSIT} route is created. The state is now
- * {@link FlightState#OFF_EFFORT}.
- * <p/>
- * This operation is called when the plane take off, for the moment no
- * observation is done and the audio is not recording. The GPS is enabled
- * and will send data to display the plane tracking.
- * <p/>
- * After a start(), you can call :
- * <ul>
- * <li>{@link #begin()}</li>
- * <li>{@link #observation(Position)}</li>
- * <li>{@link #stop()}</li>
- * </ul>
- */
- void start();
-
- /**
- * Select a {@code nextTransect} to use for the next {@link RouteType#LEG}
- * when {@link #begin()} method is called.
- *
- * @param nextTransect the TransectFlight to use as next one
- */
- void setNextTransect(TransectFlight nextTransect);
-
- /**
- * Begin operation. A new {@link RouteType#LEG} is created based on GPS
- * current date and next transect that becomes the current one. The state
- * is now {@link FlightState#ON_EFFORT}.
- * <p/>
- * This operation is called when the plane arrives on a transect and observation
- * need to begin. Conditions could be set on the currentRoute (TRANSIT) and
- * will be copied on the new LEG. This operation is also called when a
- * CIRCLE_BACK is finished to resume effort on the current transect.
- * <p/>
- * After a begin(), you can call :
- * <ul>
- * <li>{@link #add()}</li>
- * <li>{@link #circleBack(Observation)}</li>
- * <li>{@link #next()}</li>
- * <li>{@link #observation(Position)}</li>
- * <li>{@link #end()}</li>
- * <li>{@link #stop()}</li>
- * </ul>
- */
- void begin();
-
- /**
- * Circle Back operation. A new {@link RouteType#CIRCLE_BACK} is created
- * based on GPS current date and attached to the {@code observation}. The
- * next transect will be the current one to allow begin() to not change the
- * transect. The state is now {@link FlightState#OFF_EFFORT}.
- * <p/>
- * This operation is called when an observation need to be checked again,
- * the plane will do a circle back. In this case, we are not on effort
- * anymore, but we can continue creating observations with the appropriate
- * status. The {@code observation} is marked as {@link ObservationStatus#CIRCLE_BACK}.
- * After the circle back, we use {@link #begin()} operation to continue effort
- * with a new LEG.
- * <p/>
- * After a circleBack(), you can call :
- * <ul>
- * <li>circleBack(Observation)</li>
- * <li>{@link #begin()}</li>
- * <li>{@link #observation(Position)}</li>
- * <li>{@link #stop()}</li>
- * </ul>
- *
- * @param observation The observation cause of the circle back
- * @see ObservationStatus
- */
- void circleBack(Observation observation);
-
- /**
- * Add operation. A new {@link RouteType#LEG} is created based on GPS current
- * date and current transect. The next transect and state doesn't change.
- * <p/>
- * This operation is called when the observation conditions has changed,
- * to mark this, a LEG is created with a GPS point and a new audio file. *
- * <p/>
- * After a add(), you can call :
- * <ul>
- * <li>add()</li>
- * <li>{@link #circleBack(Observation)}</li>
- * <li>{@link #next()}</li>
- * <li>{@link #observation(Position)}</li>
- * <li>{@link #end()}</li>
- * <li>{@link #stop()}</li>
- * </ul>
- */
- void add();
-
- /**
- * Next operation. It's a shortcut to end the previous effort and begin the
- * next one on the next transect. This will call {@link #end()} if necessary
- * and then {@link #begin()}.
- * <p/>
- * After a next(), you can call :
- * <ul>
- * <li>add()</li>
- * <li>{@link #circleBack(Observation)}</li>
- * <li>{@link #next()}</li>
- * <li>{@link #observation(Position)}</li>
- * <li>{@link #end()}</li>
- * <li>{@link #stop()}</li>
- * </ul>
- */
- void next();
-
- /**
- * Observation operation. It's the creation of an observation for the
- * given {@code position}. The observer will be retrieved from the
- * current route and the time is synchronized with the GPS or with the
- * system if not responding.
- *
- * @param position Position of the observer that make the observation
- */
- void observation(Position position);
-
- /**
- * End operation. This will create a new {@link RouteType#TRANSIT} route and
- * put the next transect depends on the plane list. The audio is still
- * recording for a few minutes and the state becomes {@link FlightState#OFF_EFFORT}
- * <p/>
- * This operation is called when an effort/transect is finished.
- * <p/>
- * After a end(), you can call :
- * <ul>
- * <li>{@link #begin()}</li>
- * <li>{@link #observation(Position)}</li>
- * <li>{@link #stop()}</li>
- * </ul>
- */
- void end();
-
- /**
- * Stop operation. This will stop the flight (by creating the end date) and
- * stop all devices (GPS and Audio). Current route and next transect are
- * reset (set to null). The state becomes {@link FlightState#ENDED}
- * <p/>
- * This operation is called when the plane is landing.
- * <p/>
- * You can't do anything after a stop.
- */
- void stop();
-
- /**
- * Close operation. This is used to close properly the controller even if
- * the flight is not finished.
- */
- void close();
-
- /**
- * @return true if {@link FlightState#WAITING}
- */
- boolean isWaiting();
-
- /**
- * @return true if {@link FlightState#ENDED}
- */
- boolean isEnded();
-
- /**
- * @return true if {@link FlightState#ON_EFFORT}
- */
- boolean isOnEffort();
-
- /**
- * @return true if {@link FlightState#OFF_EFFORT}
- */
- boolean isOffEffort();
-
- /**
- * @return true if {@link FlightState#OFF_EFFORT} or {@link FlightState#ON_EFFORT}
- */
- boolean isRunning();
-
- /**
- * @param listener FlightControllerUpdateListener to add
- */
- void addListener(FlightControllerUpdateListener listener);
-
- /**
- * @param listener FlightControllerUpdateListener to remove
- */
- void removeListener(FlightControllerUpdateListener listener);
-}
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -1,879 +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.application;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Supplier;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Sets;
-import fr.ulr.sammoa.application.device.DeviceManager;
-import fr.ulr.sammoa.application.device.DeviceStateListener;
-import fr.ulr.sammoa.application.device.DeviceTechnicalException;
-import fr.ulr.sammoa.application.device.audio.AudioRecorder;
-import fr.ulr.sammoa.application.device.audio.AudioRecorderDefault;
-import fr.ulr.sammoa.application.device.gps.GpsConfig;
-import fr.ulr.sammoa.application.device.gps.GpsHandler;
-import fr.ulr.sammoa.application.device.gps.GpsLocationEvent;
-import fr.ulr.sammoa.application.device.gps.GpsLocationListener;
-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;
-import fr.ulr.sammoa.persistence.ObserverPosition;
-import fr.ulr.sammoa.persistence.Position;
-import fr.ulr.sammoa.persistence.Route;
-import fr.ulr.sammoa.persistence.RouteType;
-import fr.ulr.sammoa.persistence.SammoaDAOHelper;
-import fr.ulr.sammoa.persistence.SammoaPersistence;
-import fr.ulr.sammoa.persistence.TransectFlight;
-import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.TopiaRuntimeException;
-import org.nuiton.util.TimeLog;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Date;
-import java.util.Set;
-
-/**
- * Created: 11/06/12
- *
- * @author fdesbois <desbois(a)codelutin.com>
- */
-public class FlightControllerDefault implements GpsLocationListener, FlightController {
-
- private static final Logger logger = LoggerFactory.getLogger(FlightControllerDefault.class);
-
- private static final TimeLog timeLog = new TimeLog(FlightControllerDefault.class, 500, 1000);
-
- protected SammoaContext context;
-
- protected SammoaPersistence persistence;
-
- protected FlightService service;
-
- protected AudioRecorder audioRecorder;
-
- protected GpsHandler gpsHandler;
-
- protected boolean initialized;
-
- protected FlightState state;
-
- protected Flight flight;
-
- protected Route currentRoute;
-
- protected TransectFlight nextTransect;
-
- protected TransectFlight lastTransect;
-
- protected Set<FlightControllerUpdateListener> listeners;
-
- public FlightControllerDefault(SammoaContext context,
- Flight flight) {
-
- this.context = context;
- this.flight = flight;
-
- this.persistence = context.getPersistence();
- this.service = context.getFlightService();
-
- this.currentRoute = service.getLastRoute(flight);
- this.lastTransect = service.getLastTransectDone(flight);
- this.listeners = Sets.newHashSet();
- }
-
- @Override
- public void addListener(FlightControllerUpdateListener listener) {
- listeners.add(listener);
- }
-
- @Override
- public void removeListener(FlightControllerUpdateListener listener) {
- listeners.remove(listener);
- }
-
- @Override
- public FlightState getState() {
- return state;
- }
-
- @Override
- public AudioRecorder getAudioRecorder() {
- return audioRecorder;
- }
-
- @Override
- public Route getCurrentRoute() {
- return currentRoute;
- }
-
- @Override
- public TransectFlight getNextTransect() {
- return nextTransect;
- }
-
- @Override
- public GpsHandler getGpsHandler() {
- return gpsHandler;
- }
-
- @Override
- public void openGpsDevice(final GpsConfig config) throws DeviceTechnicalException {
-
- Set<GpsLocationListener> locationListeners;
- if (gpsHandler != null) {
-
- // Remove all existing listeners and keep them for the new instance
- locationListeners = Sets.newHashSet(gpsHandler.getGpsLocationListeners());
- for (GpsLocationListener listener : locationListeners) {
- gpsHandler.removeGpsLocationListener(listener);
- }
-
- } else {
- locationListeners = Sets.newHashSet();
- }
-
- gpsHandler = newDeviceManager(gpsHandler, new Supplier<GpsHandler>() {
-
- @Override
- public GpsHandler get() {
-
- // Instanciate the GpsHandler
- Class<? extends GpsHandler> gpsHandlerClass = config.getGpsHandlerClass();
- try {
-
- Constructor<? extends GpsHandler> constructor =
- gpsHandlerClass.getConstructor(GpsConfig.class);
-
- GpsHandler result = constructor.newInstance(config);
- result.addGpsLocationListener(FlightControllerDefault.this);
- return result;
-
- } catch (InstantiationException e) {
- throw Throwables.propagate(e);
- } catch (IllegalAccessException e) {
- throw Throwables.propagate(e);
- } catch (NoSuchMethodException e) {
- throw Throwables.propagate(e);
- } catch (InvocationTargetException e) {
- throw Throwables.propagate(e);
- }
- }
- });
-
- for (GpsLocationListener listener : locationListeners) {
- gpsHandler.addGpsLocationListener(listener);
- }
-
- if (initialized && isRunning()) {
- gpsHandler.start();
- } else {
- gpsHandler.open();
- }
- }
-
- @Override
- public void openAudioDevice() throws DeviceTechnicalException {
-
- audioRecorder = newDeviceManager(audioRecorder, new Supplier<AudioRecorder>() {
-
- @Override
- public AudioRecorder get() {
- return new AudioRecorderDefault();
- }
- });
-
- if (initialized && isRunning()) {
- audioRecorder.start();
- } else {
- audioRecorder.open();
- }
- }
-
- @Override
- public boolean isWaiting() {
- return state == FlightState.WAITING;
- }
-
- @Override
- public boolean isEnded() {
- return state == FlightState.ENDED;
- }
-
- @Override
- public boolean isOnEffort() {
- return state == FlightState.ON_EFFORT;
- }
-
- @Override
- public boolean isOffEffort() {
- return state == FlightState.OFF_EFFORT;
- }
-
- @Override
- public boolean isRunning() {
- return isOnEffort() || isOffEffort();
- }
-
- @Override
- public void init() {
-
- Preconditions.checkState(gpsHandler != null,
- "The GpsHandler must be created using #openGpsDevice");
-
- Preconditions.checkState(audioRecorder != null,
- "The AudioRecorder must be created using #openAudioDevice");
-
- if (initialized) {
- if (logger.isWarnEnabled()) {
- logger.warn("The FlightController is already initialized");
- }
- return;
- }
-
- if (logger.isInfoEnabled()) {
- logger.info("Initialize the FlightController for flight " + flight.getFlightNumber());
- }
-
- initialized = true;
-
- // Note that a flight can't finished by a leg, so effort not null
- // implies that the flight is started and not ended
- if (currentRoute != null
- && currentRoute.getRouteType() == RouteType.LEG) {
-
- state = FlightState.ON_EFFORT;
-
- } else if (currentRoute != null
- && flight.getBeginDate() != null
- && flight.getEndDate() == null) {
-
- state = FlightState.OFF_EFFORT;
-
- } else if (flight.getEndDate() != null) {
-
- state = FlightState.ENDED;
-
- } else {
- state = FlightState.WAITING;
- }
-
- if (isRunning()) {
-
- gpsHandler.start();
-
- audioRecorder.start();
-
- // Selection of the nextTransect, keep the last one for circleBack
- if (currentRoute.getRouteType() == RouteType.CIRCLE_BACK) {
- nextTransect = lastTransect;
-
- } else {
- nextTransect = flight.getNextTransectFlightFrom(lastTransect);
- }
-
- // Restart recording audio if onEffort or circleBack
- if (state == FlightState.ON_EFFORT
- || currentRoute.getRouteType() == RouteType.CIRCLE_BACK) {
-
- saveAudio(0);
- }
- }
- }
-
- @Override
- public void start() {
-
- long startTime = TimeLog.getTime();
-
- Preconditions.checkState(initialized,
- "The controller must be initialized before calling any action");
-
- Preconditions.checkState(
- isWaiting(), "You can call start() only if flight is waiting (not started, not ended)");
-
- gpsHandler.start();
-
- audioRecorder.start();
-
- TopiaContext transaction = persistence.beginTransaction();
- try {
-
- Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
-
- setFlightBeginDate(transaction, flight, currentDate);
-
- if (logger.isInfoEnabled()) {
- logger.info("Start Flight {} at {}", flight.getFlightNumber(), flight.getBeginDate());
- }
-
- // Start with TRANSIT route
- if (logger.isInfoEnabled()) {
- logger.info(String.format("Create TRANSIT [START] at %1$tH:%1$tM:%1$tS", currentDate));
- }
- currentRoute = service.createTransit(transaction, flight, currentDate, currentRoute);
-
- // Auto selection of the next transect starting from the begining
- nextTransect = flight.getNextTransectFlightFrom(null);
-
- state = FlightState.OFF_EFFORT;
-
- transaction.commitTransaction();
-
- startTime = timeLog.log(startTime, "start()", "Commited");
-
- // Fire events after commit
- fireRouteAdded(currentRoute);
- fireNextTransectChanged(nextTransect);
- fireStateChanged(state);
-
- timeLog.log(startTime, "start()", "Fired");
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(transaction);
- }
- }
-
- @Override
- public void setNextTransect(TransectFlight nextTransect) {
-
- long startTime = TimeLog.getTime();
-
- Preconditions.checkState(initialized,
- "The controller must be initialized before calling any action");
-
- Preconditions.checkState(
- nextTransect == null || !nextTransect.isDeleted(), "You can't use a deleted transect as next value");
-
- this.nextTransect = nextTransect;
-
- // Fire transect changed
- fireNextTransectChanged(nextTransect);
-
- timeLog.log(startTime, "setNextTransect()", "Fired");
- }
-
- @Override
- public void begin() {
-
- long startTime = TimeLog.getTime();
-
- Preconditions.checkState(initialized,
- "The controller must be initialized before calling any action");
-
- Preconditions.checkState(
- isOffEffort(), "You can call begin() only if flight is running (started, not ended, not on effort)");
-
- Preconditions.checkState(
- nextTransect != null, "You can't call begin() if no transect is selected. " +
- "Call setNextTransect() method first");
-
- TopiaContext transaction = persistence.beginTransaction();
- try {
-
- Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
-
- // The next transect becomes the last one (or current in this case)
- lastTransect = nextTransect;
-
- // Create new LEG route
- if (logger.isInfoEnabled()) {
- logger.info(String.format("Create LEG [BEGIN] at %1$tH:%1$tM:%1$tS", currentDate));
- }
- currentRoute = service.createLeg(transaction, flight, currentDate, currentRoute, lastTransect);
-
- // automatic selection of the next transect
- nextTransect = flight.getNextTransectFlightFrom(lastTransect);
-
- state = FlightState.ON_EFFORT;
-
- // Record the audio for the current LEG
- saveAudio(3);
-
- transaction.commitTransaction();
-
- startTime = timeLog.log(startTime, "begin()", "Commited");
-
- // Fire events after commit
- fireRouteAdded(currentRoute);
- fireNextTransectChanged(nextTransect);
- fireStateChanged(state);
-
- timeLog.log(startTime, "begin()", "Fired");
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(transaction);
- }
- }
-
- @Override
- public void circleBack(Observation observation) {
-
- long startTime = TimeLog.getTime();
-
- Preconditions.checkState(initialized,
- "The controller must be initialized before calling any action");
-
- Preconditions.checkState(
- currentRoute != null
- && currentRoute.getRouteType() != RouteType.TRANSIT,
- "You can't call circleBack() during TRANSIT");
-
-
- TopiaContext transaction = persistence.beginTransaction();
- try {
-
- Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
-
- setObservationStatus(transaction, observation, ObservationStatus.CIRCLE_BACK);
-
- // Create CIRCLE_BACK
- if (logger.isInfoEnabled()) {
- logger.info(String.format("Create CIRCLE_BACK at %1$tH:%1$tM:%1$tS", currentDate));
- }
-
- currentRoute = service.createCircleBack(transaction, flight, currentDate, currentRoute, observation);
-
- nextTransect = lastTransect;
-
- state = FlightState.OFF_EFFORT;
-
- // Record the audio of the LEG in an other file
- saveAudio(3);
-
- transaction.commitTransaction();
-
- startTime = timeLog.log(startTime, "circleBack()", "Commited");
-
- // Fire events after commit
- fireRouteAdded(currentRoute);
- fireNextTransectChanged(nextTransect);
- fireStateChanged(state);
-
- timeLog.log(startTime, "circleBack()", "Fired");
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(transaction);
- }
- }
-
- @Override
- public void add() {
-
- long startTime = TimeLog.getTime();
-
- Preconditions.checkState(initialized,
- "The controller must be initialized before calling any action");
-
- Preconditions.checkState(
- isOnEffort(), "You can call add() only if flight is on effort (started, not ended, on effort)");
-
- TopiaContext transaction = persistence.beginTransaction();
- try {
- Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
-
- // Create new LEG route
- if (logger.isInfoEnabled()) {
- logger.info(String.format("Create LEG [ADD] at %1$tH:%1$tM:%1$tS", currentDate));
- }
- currentRoute = service.createLeg(transaction, flight, currentDate, currentRoute, lastTransect);
-
- // Record the audio of the LEG in an other file
- saveAudio(3);
-
- transaction.commitTransaction();
-
- startTime = timeLog.log(startTime, "add()", "Commited");
-
- // Fire events after commit
- fireRouteAdded(currentRoute);
-
- timeLog.log(startTime, "add()", "Fired");
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(transaction);
- }
- }
-
- @Override
- public void next() {
-
- long startTime = TimeLog.getTime();
-
- if (isOnEffort()) {
- doEndWithAudioDelay(3);
- }
-
- begin();
-
- timeLog.log(startTime, "next()");
- }
-
- @Override
- public void observation(Position position) {
-
- long startTime = TimeLog.getTime();
-
- Preconditions.checkState(initialized,
- "The controller must be initialized before calling any action");
-
- Preconditions.checkState(
- isRunning(), "You can call observation() only if flight is running (started, not ended)");
-
- TopiaContext transaction = persistence.beginTransaction();
- try {
-
- Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
-
- ObserverPosition observer;
- if (currentRoute == null) {
-
- // problem we don't have any observerPosition
- observer = null;
-
- } else {
- observer = currentRoute.getObserverPositionByPosition(position);
- }
-
- if (logger.isInfoEnabled()) {
- logger.info(String.format("Create Observation %2$s at %1$tH:%1$tM:%1$tS (observer = %3$s)",
- currentDate,
- position,
- observer != null && observer.getObserver() != null
- ? observer.getObserver().getInitials() : "")
- );
- }
- Observation observation = service.createObservation(transaction, flight, currentDate, observer);
-
- transaction.commitTransaction();
-
- startTime = timeLog.log(startTime, "observation()", "Commited");
-
- for (FlightControllerUpdateListener listener : listeners) {
- listener.onObservationAdded(observation);
- }
-
- timeLog.log(startTime, "observation()", "Fired");
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(transaction);
- }
- }
-
- @Override
- public void end() {
-
- long startTime = TimeLog.getTime();
-
- // Stop recording after 2 minutes (120 seconds)
- doEndWithAudioDelay(120);
-
- timeLog.log(startTime, "end()");
- }
-
- @Override
- public void stop() {
-
- long startTime = TimeLog.getTime();
-
- Preconditions.checkState(initialized,
- "The controller must be initialized before calling any action");
-
- Preconditions.checkState(
- isOffEffort(), "You can call stop() only if flight is running (started, not ended, not on effort)");
-
- TopiaContext transaction = persistence.beginTransaction();
- try {
- Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
-
- if (logger.isInfoEnabled()) {
- logger.info(String.format("Stop flight %2$d at %1$tH:%1$tM:%1$tS",
- currentDate,
- flight.getFlightNumber())
- );
- }
- setFlightEndDate(transaction, flight, currentDate);
-
- // Stop audio
- getAudioRecorder().stop();
-
- // Stop gps
- getGpsHandler().stop();
-
- currentRoute = null;
-
- nextTransect = null;
-
- state = FlightState.ENDED;
-
- transaction.commitTransaction();
-
- startTime = timeLog.log(startTime, "stop()", "Commited");
-
- // Fire events after commit
- fireRouteAdded(currentRoute);
- fireNextTransectChanged(nextTransect);
- fireStateChanged(state);
-
- timeLog.log(startTime, "stop()", "Fired");
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(transaction);
- }
- }
-
- @Override
- public void close() {
-
- audioRecorder.close();
- audioRecorder = null;
-
- gpsHandler.close();
- gpsHandler = null;
-
- persistence.stopAutoSaveListener();
- }
-
- protected void doEndWithAudioDelay(long audioDelay) {
-
- Preconditions.checkState(initialized,
- "The controller must be initialized before calling any action");
-
- Preconditions.checkState(
- isOnEffort(), "You can call end() only if flight is on effort (started, not ended, on effort)");
-
- TopiaContext transaction = persistence.beginTransaction();
- try {
- Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
-
- // Create new TRANSIT route
- if (logger.isInfoEnabled()) {
- logger.info(String.format("Create TRANSIT [END] at %1$tH:%1$tM:%1$tS", currentDate));
- }
- currentRoute = service.createTransit(transaction, flight, currentDate, currentRoute);
-
- audioRecorder.stopRecord(audioDelay);
-
- state = FlightState.OFF_EFFORT;
-
- transaction.commitTransaction();
-
- // Fire events after commit
- fireRouteAdded(currentRoute);
- fireNextTransectChanged(nextTransect);
- fireStateChanged(state);
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(transaction);
- }
- }
-
-// protected void setNextTransect(TransectFlight nextTransect, boolean fireEvents) {
-//
-// this.nextTransect = nextTransect;
-//
-// if (fireEvents) {
-// // Fire transect changed
-// for (FlightControllerUpdateListener listener : listeners) {
-// listener.onNextTransectChanged(nextTransect);
-// }
-// }
-// }
-//
-// protected void setNextTransectFrom(TransectFlight transect, boolean fireEvents) {
-//
-// TransectFlight nextTransect =
-// flight.getNextTransectFlightFrom(transect);
-//
-// setNextTransect(nextTransect, fireEvents);
-// }
-
- protected void setFlightBeginDate(TopiaContext transaction,
- Flight flight,
- Date beginDate)
- throws TopiaException {
-
- FlightDAO flightDAO = SammoaDAOHelper.getFlightDAO(transaction);
- flight.setBeginDate(beginDate);
- flightDAO.update(flight);
- }
-
- protected void setFlightEndDate(TopiaContext transaction,
- Flight flight,
- Date endDate)
- throws TopiaException {
-
- FlightDAO flightDAO = SammoaDAOHelper.getFlightDAO(transaction);
- flight.setEndDate(endDate);
- flightDAO.update(flight);
- }
-
- protected void setObservationStatus(TopiaContext transaction,
- Observation observation,
- ObservationStatus status)
- throws TopiaException {
-
- ObservationDAO observationDAO =
- SammoaDAOHelper.getObservationDAO(transaction);
- observation.setObservationStatus(status);
- observationDAO.update(observation);
- }
-
- protected void saveAudio(long delay) {
-
- String fileName = String.format(
- "%1$tF-%1$tH-%1$tM-%1$tS.%2$s.%3$s",
- currentRoute.getBeginTime(),
- currentRoute.getTopiaId(),
- getAudioRecorder().getOutputType().getExtension()
- );
-
- File audioDir = context.getConfig().getAudioDirectory();
-
- File audioFile = new File(audioDir, fileName);
-
- try {
- getAudioRecorder().record(audioFile, delay);
- } catch (IOException e) {
- throw Throwables.propagate(e);
- }
- }
-
- protected Date saveGPS(TopiaContext transaction,
- GeoPoint geoPoint,
- Flight flight)
- throws TopiaException {
-
- Date result;
- if (geoPoint == null) {
- result = new Date();
- if (logger.isWarnEnabled()) {
- logger.warn("No GPS point at {}", result);
- }
-
- } else {
-
- if (logger.isTraceEnabled()) {
- logger.trace("Create GPS Point : {}", geoPoint);
- }
-
- result = geoPoint.getRecordTime();
-
- GeoPointDAO dao = SammoaDAOHelper.getGeoPointDAO(transaction);
-
- geoPoint.setFlight(flight);
-
- dao.create(geoPoint);
- }
- return result;
- }
-
- protected void fireStateChanged(FlightState state) {
- for (FlightControllerUpdateListener listener : listeners) {
- listener.onStateChanged(state);
- }
- }
-
- protected void fireRouteAdded(Route route) {
- for (FlightControllerUpdateListener listener : listeners) {
- listener.onRouteAdded(route);
- }
- }
-
- protected void fireNextTransectChanged(TransectFlight nextTransect) {
- for (FlightControllerUpdateListener listener : listeners) {
- listener.onNextTransectChanged(nextTransect);
- }
- }
-
- protected <T extends DeviceManager> T newDeviceManager(T oldInstance, Supplier<T> supplier)
- throws DeviceTechnicalException {
-
- Set<DeviceStateListener> stateListeners;
- if (oldInstance != null) {
-
- // Remove all existing listeners and keep them for the new instance
- stateListeners = Sets.newHashSet(oldInstance.getDeviceStateListeners());
- for (DeviceStateListener listener : stateListeners) {
- oldInstance.removeDeviceStateListener(listener);
- }
-
- oldInstance.close();
-
- } else {
- stateListeners = Sets.newHashSet();
- }
-
- T result = supplier.get();
-
- // Attach all updateListener
- for (DeviceStateListener listener : stateListeners) {
- result.addDeviceStateListener(listener);
- }
-
- return result;
- }
-
- @Override
- public void locationChanged(GpsLocationEvent event) {
- GeoPoint newLocation = event.getNewValue();
- if (newLocation != null/* && newLocation.getTopiaId() == null*/) {
- newLocation.setFlight(flight);
- persistence.delayEntityCreation(newLocation);
- }
- }
-
-}
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerUpdateListener.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerUpdateListener.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerUpdateListener.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -1,69 +0,0 @@
-package fr.ulr.sammoa.application;
-/*
- * #%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(a)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);
-}
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:48:54 UTC (rev 360)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -506,10 +506,10 @@
return result;
}
- protected Observation createObservation(TopiaContext transaction,
- Flight flight,
- Date beginTime,
- ObserverPosition observer)
+ public Observation createObservation(TopiaContext transaction,
+ Flight flight,
+ Date beginTime,
+ ObserverPosition observer)
throws TopiaException {
Observation result;
@@ -525,22 +525,22 @@
return result;
}
-
- protected Route createTransit(TopiaContext transaction,
- Flight flight,
- Date beginTime,
- Route previousRoute)
+
+ public Route createTransit(TopiaContext transaction,
+ Flight flight,
+ Date beginTime,
+ Route previousRoute)
throws TopiaException {
Route result = createRoute(transaction, flight, beginTime, RouteType.TRANSIT, previousRoute, null);
return result;
}
- protected Route createLeg(TopiaContext transaction,
- Flight flight,
- Date beginTime,
- Route previousRoute,
- TransectFlight transectFlight)
+ public Route createLeg(TopiaContext transaction,
+ Flight flight,
+ Date beginTime,
+ Route previousRoute,
+ TransectFlight transectFlight)
throws TopiaException {
Preconditions.checkArgument(transectFlight != null, "You can't create a leg without any transect");
@@ -557,11 +557,11 @@
return result;
}
- protected Route createCircleBack(TopiaContext transaction,
- Flight flight,
- Date beginTime,
- Route previousRoute,
- Observation circleBackCause)
+ public Route createCircleBack(TopiaContext transaction,
+ Flight flight,
+ Date beginTime,
+ Route previousRoute,
+ Observation circleBackCause)
throws TopiaException {
Preconditions.checkArgument(circleBackCause != null, "You can't create a route without any observation cause");
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightState.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightState.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightState.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -1,57 +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.application;
-
-/**
- * Created: 20/06/12
- *
- * @author fdesbois <desbois(a)codelutin.com>
- */
-public enum FlightState {
- /**
- * The WAITING state is when the flight is not started and not ended.
- * It appends when the flight is not really in used.
- */
- WAITING,
-
- /**
- * The OFF_EFFORT state is when the flight is started but not ended,
- * and also if the current route is not an effort.
- * It appends generally when the flight is in TRANSIT or CIRCLE_BACK.
- */
- OFF_EFFORT,
-
- /**
- * The ON_EFFORT state is when the flight is started, not ended but in
- * current effort. It appends when a LEG is currently in progress.
- */
- ON_EFFORT,
-
- /**
- * The ENDED state is when the flight is ended.
- * It appends when the current effort is finished and when no more route
- * need to be registered.
- */
- ENDED
-}
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightController.java (from rev 360, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightController.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightController.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -0,0 +1,285 @@
+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.application.device.DeviceTechnicalException;
+import fr.ulr.sammoa.application.device.audio.AudioRecorder;
+import fr.ulr.sammoa.application.device.audio.AudioRecorderDefault;
+import fr.ulr.sammoa.application.device.gps.GpsConfig;
+import fr.ulr.sammoa.application.device.gps.GpsHandler;
+import fr.ulr.sammoa.persistence.GeoPoint;
+import fr.ulr.sammoa.persistence.Observation;
+import fr.ulr.sammoa.persistence.ObservationStatus;
+import fr.ulr.sammoa.persistence.Position;
+import fr.ulr.sammoa.persistence.Route;
+import fr.ulr.sammoa.persistence.RouteType;
+import fr.ulr.sammoa.persistence.TransectFlight;
+
+/**
+ * The FlightController is the main service used to do all actions during a
+ * flight. It is synchronized with the audio and GPS devices. It can be
+ * initialized with a flight that already started, the actions allowed depends on
+ * flight state.
+ * <p/>
+ * Created: 12/07/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ * @see FlightState
+ */
+public interface FlightController {
+
+ /**
+ * @return the {@link FlightState}
+ */
+ FlightState getState();
+
+ /**
+ * @return the {@link AudioRecorderDefault} used to save audio files
+ */
+ AudioRecorder getAudioRecorder();
+
+ /**
+ * @return the {@link GpsHandler} used to retrieve GPS {@link GeoPoint} and
+ * save them.
+ */
+ GpsHandler getGpsHandler();
+
+ /**
+ * @param config GpsConfig to initialize the Gps
+ * @exception fr.ulr.sammoa.application.device.DeviceTechnicalException if the gps device can't be opened properly
+ */
+ void openGpsDevice(GpsConfig config) throws DeviceTechnicalException;
+
+ /**
+ * @exception DeviceTechnicalException if the audio device can't be opened properly
+ */
+ void openAudioDevice() throws DeviceTechnicalException;
+
+ /**
+ * @return The current {@link Route}
+ */
+ Route getCurrentRoute();
+
+ /**
+ * @return The next {@link TransectFlight}
+ */
+ TransectFlight getNextTransect();
+
+ /**
+ * Initialize all data of FlightController depends on the current flight state.
+ * If the flight is running ({@link #isRunning()}), the devices will be started and
+ * recording if necessary.
+ * <p/>
+ * You must call init method to ensure the {@link FlightState}.
+ */
+ void init();
+
+ /**
+ * Start operation. This will set the {@code beginDate} of the flight, then
+ * a new {@link RouteType#TRANSIT} route is created. The state is now
+ * {@link FlightState#OFF_EFFORT}.
+ * <p/>
+ * This operation is called when the plane take off, for the moment no
+ * observation is done and the audio is not recording. The GPS is enabled
+ * and will send data to display the plane tracking.
+ * <p/>
+ * After a start(), you can call :
+ * <ul>
+ * <li>{@link #begin()}</li>
+ * <li>{@link #observation(Position)}</li>
+ * <li>{@link #stop()}</li>
+ * </ul>
+ */
+ void start();
+
+ /**
+ * Select a {@code nextTransect} to use for the next {@link RouteType#LEG}
+ * when {@link #begin()} method is called.
+ *
+ * @param nextTransect the TransectFlight to use as next one
+ */
+ void setNextTransect(TransectFlight nextTransect);
+
+ /**
+ * Begin operation. A new {@link RouteType#LEG} is created based on GPS
+ * current date and next transect that becomes the current one. The state
+ * is now {@link FlightState#ON_EFFORT}.
+ * <p/>
+ * This operation is called when the plane arrives on a transect and observation
+ * need to begin. Conditions could be set on the currentRoute (TRANSIT) and
+ * will be copied on the new LEG. This operation is also called when a
+ * CIRCLE_BACK is finished to resume effort on the current transect.
+ * <p/>
+ * After a begin(), you can call :
+ * <ul>
+ * <li>{@link #add()}</li>
+ * <li>{@link #circleBack(Observation)}</li>
+ * <li>{@link #next()}</li>
+ * <li>{@link #observation(Position)}</li>
+ * <li>{@link #end()}</li>
+ * <li>{@link #stop()}</li>
+ * </ul>
+ */
+ void begin();
+
+ /**
+ * Circle Back operation. A new {@link RouteType#CIRCLE_BACK} is created
+ * based on GPS current date and attached to the {@code observation}. The
+ * next transect will be the current one to allow begin() to not change the
+ * transect. The state is now {@link FlightState#OFF_EFFORT}.
+ * <p/>
+ * This operation is called when an observation need to be checked again,
+ * the plane will do a circle back. In this case, we are not on effort
+ * anymore, but we can continue creating observations with the appropriate
+ * status. The {@code observation} is marked as {@link ObservationStatus#CIRCLE_BACK}.
+ * After the circle back, we use {@link #begin()} operation to continue effort
+ * with a new LEG.
+ * <p/>
+ * After a circleBack(), you can call :
+ * <ul>
+ * <li>circleBack(Observation)</li>
+ * <li>{@link #begin()}</li>
+ * <li>{@link #observation(Position)}</li>
+ * <li>{@link #stop()}</li>
+ * </ul>
+ *
+ * @param observation The observation cause of the circle back
+ * @see ObservationStatus
+ */
+ void circleBack(Observation observation);
+
+ /**
+ * Add operation. A new {@link RouteType#LEG} is created based on GPS current
+ * date and current transect. The next transect and state doesn't change.
+ * <p/>
+ * This operation is called when the observation conditions has changed,
+ * to mark this, a LEG is created with a GPS point and a new audio file. *
+ * <p/>
+ * After a add(), you can call :
+ * <ul>
+ * <li>add()</li>
+ * <li>{@link #circleBack(Observation)}</li>
+ * <li>{@link #next()}</li>
+ * <li>{@link #observation(Position)}</li>
+ * <li>{@link #end()}</li>
+ * <li>{@link #stop()}</li>
+ * </ul>
+ */
+ void add();
+
+ /**
+ * Next operation. It's a shortcut to end the previous effort and begin the
+ * next one on the next transect. This will call {@link #end()} if necessary
+ * and then {@link #begin()}.
+ * <p/>
+ * After a next(), you can call :
+ * <ul>
+ * <li>add()</li>
+ * <li>{@link #circleBack(Observation)}</li>
+ * <li>{@link #next()}</li>
+ * <li>{@link #observation(Position)}</li>
+ * <li>{@link #end()}</li>
+ * <li>{@link #stop()}</li>
+ * </ul>
+ */
+ void next();
+
+ /**
+ * Observation operation. It's the creation of an observation for the
+ * given {@code position}. The observer will be retrieved from the
+ * current route and the time is synchronized with the GPS or with the
+ * system if not responding.
+ *
+ * @param position Position of the observer that make the observation
+ */
+ void observation(Position position);
+
+ /**
+ * End operation. This will create a new {@link RouteType#TRANSIT} route and
+ * put the next transect depends on the plane list. The audio is still
+ * recording for a few minutes and the state becomes {@link FlightState#OFF_EFFORT}
+ * <p/>
+ * This operation is called when an effort/transect is finished.
+ * <p/>
+ * After a end(), you can call :
+ * <ul>
+ * <li>{@link #begin()}</li>
+ * <li>{@link #observation(Position)}</li>
+ * <li>{@link #stop()}</li>
+ * </ul>
+ */
+ void end();
+
+ /**
+ * Stop operation. This will stop the flight (by creating the end date) and
+ * stop all devices (GPS and Audio). Current route and next transect are
+ * reset (set to null). The state becomes {@link FlightState#ENDED}
+ * <p/>
+ * This operation is called when the plane is landing.
+ * <p/>
+ * You can't do anything after a stop.
+ */
+ void stop();
+
+ /**
+ * Close operation. This is used to close properly the controller even if
+ * the flight is not finished.
+ */
+ void close();
+
+ /**
+ * @return true if {@link FlightState#WAITING}
+ */
+ boolean isWaiting();
+
+ /**
+ * @return true if {@link FlightState#ENDED}
+ */
+ boolean isEnded();
+
+ /**
+ * @return true if {@link FlightState#ON_EFFORT}
+ */
+ boolean isOnEffort();
+
+ /**
+ * @return true if {@link FlightState#OFF_EFFORT}
+ */
+ boolean isOffEffort();
+
+ /**
+ * @return true if {@link FlightState#OFF_EFFORT} or {@link FlightState#ON_EFFORT}
+ */
+ boolean isRunning();
+
+ /**
+ * @param listener FlightControllerUpdateListener to add
+ */
+ void addListener(FlightControllerUpdateListener listener);
+
+ /**
+ * @param listener FlightControllerUpdateListener to remove
+ */
+ void removeListener(FlightControllerUpdateListener listener);
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightController.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerDefault.java (from rev 360, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerDefault.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerDefault.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -0,0 +1,881 @@
+/*
+ * #%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.application.flightController;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Sets;
+import fr.ulr.sammoa.application.FlightService;
+import fr.ulr.sammoa.application.SammoaContext;
+import fr.ulr.sammoa.application.device.DeviceManager;
+import fr.ulr.sammoa.application.device.DeviceStateListener;
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+import fr.ulr.sammoa.application.device.audio.AudioRecorder;
+import fr.ulr.sammoa.application.device.audio.AudioRecorderDefault;
+import fr.ulr.sammoa.application.device.gps.GpsConfig;
+import fr.ulr.sammoa.application.device.gps.GpsHandler;
+import fr.ulr.sammoa.application.device.gps.GpsLocationEvent;
+import fr.ulr.sammoa.application.device.gps.GpsLocationListener;
+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;
+import fr.ulr.sammoa.persistence.ObserverPosition;
+import fr.ulr.sammoa.persistence.Position;
+import fr.ulr.sammoa.persistence.Route;
+import fr.ulr.sammoa.persistence.RouteType;
+import fr.ulr.sammoa.persistence.SammoaDAOHelper;
+import fr.ulr.sammoa.persistence.SammoaPersistence;
+import fr.ulr.sammoa.persistence.TransectFlight;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.TopiaRuntimeException;
+import org.nuiton.util.TimeLog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Date;
+import java.util.Set;
+
+/**
+ * Created: 11/06/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public class FlightControllerDefault implements GpsLocationListener, FlightController {
+
+ private static final Logger logger = LoggerFactory.getLogger(FlightControllerDefault.class);
+
+ private static final TimeLog timeLog = new TimeLog(FlightControllerDefault.class, 500, 1000);
+
+ protected SammoaContext context;
+
+ protected SammoaPersistence persistence;
+
+ protected FlightService service;
+
+ protected AudioRecorder audioRecorder;
+
+ protected GpsHandler gpsHandler;
+
+ protected boolean initialized;
+
+ protected FlightState state;
+
+ protected Flight flight;
+
+ protected Route currentRoute;
+
+ protected TransectFlight nextTransect;
+
+ protected TransectFlight lastTransect;
+
+ protected Set<FlightControllerUpdateListener> listeners;
+
+ public FlightControllerDefault(SammoaContext context,
+ Flight flight) {
+
+ this.context = context;
+ this.flight = flight;
+
+ this.persistence = context.getPersistence();
+ this.service = context.getFlightService();
+
+ this.currentRoute = service.getLastRoute(flight);
+ this.lastTransect = service.getLastTransectDone(flight);
+ this.listeners = Sets.newHashSet();
+ }
+
+ @Override
+ public void addListener(FlightControllerUpdateListener listener) {
+ listeners.add(listener);
+ }
+
+ @Override
+ public void removeListener(FlightControllerUpdateListener listener) {
+ listeners.remove(listener);
+ }
+
+ @Override
+ public FlightState getState() {
+ return state;
+ }
+
+ @Override
+ public AudioRecorder getAudioRecorder() {
+ return audioRecorder;
+ }
+
+ @Override
+ public Route getCurrentRoute() {
+ return currentRoute;
+ }
+
+ @Override
+ public TransectFlight getNextTransect() {
+ return nextTransect;
+ }
+
+ @Override
+ public GpsHandler getGpsHandler() {
+ return gpsHandler;
+ }
+
+ @Override
+ public void openGpsDevice(final GpsConfig config) throws DeviceTechnicalException {
+
+ Set<GpsLocationListener> locationListeners;
+ if (gpsHandler != null) {
+
+ // Remove all existing listeners and keep them for the new instance
+ locationListeners = Sets.newHashSet(gpsHandler.getGpsLocationListeners());
+ for (GpsLocationListener listener : locationListeners) {
+ gpsHandler.removeGpsLocationListener(listener);
+ }
+
+ } else {
+ locationListeners = Sets.newHashSet();
+ }
+
+ gpsHandler = newDeviceManager(gpsHandler, new Supplier<GpsHandler>() {
+
+ @Override
+ public GpsHandler get() {
+
+ // Instanciate the GpsHandler
+ Class<? extends GpsHandler> gpsHandlerClass = config.getGpsHandlerClass();
+ try {
+
+ Constructor<? extends GpsHandler> constructor =
+ gpsHandlerClass.getConstructor(GpsConfig.class);
+
+ GpsHandler result = constructor.newInstance(config);
+ result.addGpsLocationListener(FlightControllerDefault.this);
+ return result;
+
+ } catch (InstantiationException e) {
+ throw Throwables.propagate(e);
+ } catch (IllegalAccessException e) {
+ throw Throwables.propagate(e);
+ } catch (NoSuchMethodException e) {
+ throw Throwables.propagate(e);
+ } catch (InvocationTargetException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+ });
+
+ for (GpsLocationListener listener : locationListeners) {
+ gpsHandler.addGpsLocationListener(listener);
+ }
+
+ if (initialized && isRunning()) {
+ gpsHandler.start();
+ } else {
+ gpsHandler.open();
+ }
+ }
+
+ @Override
+ public void openAudioDevice() throws DeviceTechnicalException {
+
+ audioRecorder = newDeviceManager(audioRecorder, new Supplier<AudioRecorder>() {
+
+ @Override
+ public AudioRecorder get() {
+ return new AudioRecorderDefault();
+ }
+ });
+
+ if (initialized && isRunning()) {
+ audioRecorder.start();
+ } else {
+ audioRecorder.open();
+ }
+ }
+
+ @Override
+ public boolean isWaiting() {
+ return state == FlightState.WAITING;
+ }
+
+ @Override
+ public boolean isEnded() {
+ return state == FlightState.ENDED;
+ }
+
+ @Override
+ public boolean isOnEffort() {
+ return state == FlightState.ON_EFFORT;
+ }
+
+ @Override
+ public boolean isOffEffort() {
+ return state == FlightState.OFF_EFFORT;
+ }
+
+ @Override
+ public boolean isRunning() {
+ return isOnEffort() || isOffEffort();
+ }
+
+ @Override
+ public void init() {
+
+ Preconditions.checkState(gpsHandler != null,
+ "The GpsHandler must be created using #openGpsDevice");
+
+ Preconditions.checkState(audioRecorder != null,
+ "The AudioRecorder must be created using #openAudioDevice");
+
+ if (initialized) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("The FlightController is already initialized");
+ }
+ return;
+ }
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Initialize the FlightController for flight " + flight.getFlightNumber());
+ }
+
+ initialized = true;
+
+ // Note that a flight can't finished by a leg, so effort not null
+ // implies that the flight is started and not ended
+ if (currentRoute != null
+ && currentRoute.getRouteType() == RouteType.LEG) {
+
+ state = FlightState.ON_EFFORT;
+
+ } else if (currentRoute != null
+ && flight.getBeginDate() != null
+ && flight.getEndDate() == null) {
+
+ state = FlightState.OFF_EFFORT;
+
+ } else if (flight.getEndDate() != null) {
+
+ state = FlightState.ENDED;
+
+ } else {
+ state = FlightState.WAITING;
+ }
+
+ if (isRunning()) {
+
+ gpsHandler.start();
+
+ audioRecorder.start();
+
+ // Selection of the nextTransect, keep the last one for circleBack
+ if (currentRoute.getRouteType() == RouteType.CIRCLE_BACK) {
+ nextTransect = lastTransect;
+
+ } else {
+ nextTransect = flight.getNextTransectFlightFrom(lastTransect);
+ }
+
+ // Restart recording audio if onEffort or circleBack
+ if (state == FlightState.ON_EFFORT
+ || currentRoute.getRouteType() == RouteType.CIRCLE_BACK) {
+
+ saveAudio(0);
+ }
+ }
+ }
+
+ @Override
+ public void start() {
+
+ long startTime = TimeLog.getTime();
+
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
+ Preconditions.checkState(
+ isWaiting(), "You can call start() only if flight is waiting (not started, not ended)");
+
+ gpsHandler.start();
+
+ audioRecorder.start();
+
+ TopiaContext transaction = persistence.beginTransaction();
+ try {
+
+ Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
+
+ setFlightBeginDate(transaction, flight, currentDate);
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Start Flight {} at {}", flight.getFlightNumber(), flight.getBeginDate());
+ }
+
+ // Start with TRANSIT route
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format("Create TRANSIT [START] at %1$tH:%1$tM:%1$tS", currentDate));
+ }
+ currentRoute = service.createTransit(transaction, flight, currentDate, currentRoute);
+
+ // Auto selection of the next transect starting from the begining
+ nextTransect = flight.getNextTransectFlightFrom(null);
+
+ state = FlightState.OFF_EFFORT;
+
+ transaction.commitTransaction();
+
+ startTime = timeLog.log(startTime, "start()", "Commited");
+
+ // Fire events after commit
+ fireRouteAdded(currentRoute);
+ fireNextTransectChanged(nextTransect);
+ fireStateChanged(state);
+
+ timeLog.log(startTime, "start()", "Fired");
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+
+ } finally {
+ persistence.endTransaction(transaction);
+ }
+ }
+
+ @Override
+ public void setNextTransect(TransectFlight nextTransect) {
+
+ long startTime = TimeLog.getTime();
+
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
+ Preconditions.checkState(
+ nextTransect == null || !nextTransect.isDeleted(), "You can't use a deleted transect as next value");
+
+ this.nextTransect = nextTransect;
+
+ // Fire transect changed
+ fireNextTransectChanged(nextTransect);
+
+ timeLog.log(startTime, "setNextTransect()", "Fired");
+ }
+
+ @Override
+ public void begin() {
+
+ long startTime = TimeLog.getTime();
+
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
+ Preconditions.checkState(
+ isOffEffort(), "You can call begin() only if flight is running (started, not ended, not on effort)");
+
+ Preconditions.checkState(
+ nextTransect != null, "You can't call begin() if no transect is selected. " +
+ "Call setNextTransect() method first");
+
+ TopiaContext transaction = persistence.beginTransaction();
+ try {
+
+ Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
+
+ // The next transect becomes the last one (or current in this case)
+ lastTransect = nextTransect;
+
+ // Create new LEG route
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format("Create LEG [BEGIN] at %1$tH:%1$tM:%1$tS", currentDate));
+ }
+ currentRoute = service.createLeg(transaction, flight, currentDate, currentRoute, lastTransect);
+
+ // automatic selection of the next transect
+ nextTransect = flight.getNextTransectFlightFrom(lastTransect);
+
+ state = FlightState.ON_EFFORT;
+
+ // Record the audio for the current LEG
+ saveAudio(3);
+
+ transaction.commitTransaction();
+
+ startTime = timeLog.log(startTime, "begin()", "Commited");
+
+ // Fire events after commit
+ fireRouteAdded(currentRoute);
+ fireNextTransectChanged(nextTransect);
+ fireStateChanged(state);
+
+ timeLog.log(startTime, "begin()", "Fired");
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+
+ } finally {
+ persistence.endTransaction(transaction);
+ }
+ }
+
+ @Override
+ public void circleBack(Observation observation) {
+
+ long startTime = TimeLog.getTime();
+
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
+ Preconditions.checkState(
+ currentRoute != null
+ && currentRoute.getRouteType() != RouteType.TRANSIT,
+ "You can't call circleBack() during TRANSIT");
+
+
+ TopiaContext transaction = persistence.beginTransaction();
+ try {
+
+ Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
+
+ setObservationStatus(transaction, observation, ObservationStatus.CIRCLE_BACK);
+
+ // Create CIRCLE_BACK
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format("Create CIRCLE_BACK at %1$tH:%1$tM:%1$tS", currentDate));
+ }
+
+ currentRoute = service.createCircleBack(transaction, flight, currentDate, currentRoute, observation);
+
+ nextTransect = lastTransect;
+
+ state = FlightState.OFF_EFFORT;
+
+ // Record the audio of the LEG in an other file
+ saveAudio(3);
+
+ transaction.commitTransaction();
+
+ startTime = timeLog.log(startTime, "circleBack()", "Commited");
+
+ // Fire events after commit
+ fireRouteAdded(currentRoute);
+ fireNextTransectChanged(nextTransect);
+ fireStateChanged(state);
+
+ timeLog.log(startTime, "circleBack()", "Fired");
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+
+ } finally {
+ persistence.endTransaction(transaction);
+ }
+ }
+
+ @Override
+ public void add() {
+
+ long startTime = TimeLog.getTime();
+
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
+ Preconditions.checkState(
+ isOnEffort(), "You can call add() only if flight is on effort (started, not ended, on effort)");
+
+ TopiaContext transaction = persistence.beginTransaction();
+ try {
+ Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
+
+ // Create new LEG route
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format("Create LEG [ADD] at %1$tH:%1$tM:%1$tS", currentDate));
+ }
+ currentRoute = service.createLeg(transaction, flight, currentDate, currentRoute, lastTransect);
+
+ // Record the audio of the LEG in an other file
+ saveAudio(3);
+
+ transaction.commitTransaction();
+
+ startTime = timeLog.log(startTime, "add()", "Commited");
+
+ // Fire events after commit
+ fireRouteAdded(currentRoute);
+
+ timeLog.log(startTime, "add()", "Fired");
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+
+ } finally {
+ persistence.endTransaction(transaction);
+ }
+ }
+
+ @Override
+ public void next() {
+
+ long startTime = TimeLog.getTime();
+
+ if (isOnEffort()) {
+ doEndWithAudioDelay(3);
+ }
+
+ begin();
+
+ timeLog.log(startTime, "next()");
+ }
+
+ @Override
+ public void observation(Position position) {
+
+ long startTime = TimeLog.getTime();
+
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
+ Preconditions.checkState(
+ isRunning(), "You can call observation() only if flight is running (started, not ended)");
+
+ TopiaContext transaction = persistence.beginTransaction();
+ try {
+
+ Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
+
+ ObserverPosition observer;
+ if (currentRoute == null) {
+
+ // problem we don't have any observerPosition
+ observer = null;
+
+ } else {
+ observer = currentRoute.getObserverPositionByPosition(position);
+ }
+
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format("Create Observation %2$s at %1$tH:%1$tM:%1$tS (observer = %3$s)",
+ currentDate,
+ position,
+ observer != null && observer.getObserver() != null
+ ? observer.getObserver().getInitials() : "")
+ );
+ }
+ Observation observation = service.createObservation(transaction, flight, currentDate, observer);
+
+ transaction.commitTransaction();
+
+ startTime = timeLog.log(startTime, "observation()", "Commited");
+
+ for (FlightControllerUpdateListener listener : listeners) {
+ listener.onObservationAdded(observation);
+ }
+
+ timeLog.log(startTime, "observation()", "Fired");
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+
+ } finally {
+ persistence.endTransaction(transaction);
+ }
+ }
+
+ @Override
+ public void end() {
+
+ long startTime = TimeLog.getTime();
+
+ // Stop recording after 2 minutes (120 seconds)
+ doEndWithAudioDelay(120);
+
+ timeLog.log(startTime, "end()");
+ }
+
+ @Override
+ public void stop() {
+
+ long startTime = TimeLog.getTime();
+
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
+ Preconditions.checkState(
+ isOffEffort(), "You can call stop() only if flight is running (started, not ended, not on effort)");
+
+ TopiaContext transaction = persistence.beginTransaction();
+ try {
+ Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
+
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format("Stop flight %2$d at %1$tH:%1$tM:%1$tS",
+ currentDate,
+ flight.getFlightNumber())
+ );
+ }
+ setFlightEndDate(transaction, flight, currentDate);
+
+ // Stop audio
+ getAudioRecorder().stop();
+
+ // Stop gps
+ getGpsHandler().stop();
+
+ currentRoute = null;
+
+ nextTransect = null;
+
+ state = FlightState.ENDED;
+
+ transaction.commitTransaction();
+
+ startTime = timeLog.log(startTime, "stop()", "Commited");
+
+ // Fire events after commit
+ fireRouteAdded(currentRoute);
+ fireNextTransectChanged(nextTransect);
+ fireStateChanged(state);
+
+ timeLog.log(startTime, "stop()", "Fired");
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+
+ } finally {
+ persistence.endTransaction(transaction);
+ }
+ }
+
+ @Override
+ public void close() {
+
+ audioRecorder.close();
+ audioRecorder = null;
+
+ gpsHandler.close();
+ gpsHandler = null;
+
+ persistence.stopAutoSaveListener();
+ }
+
+ protected void doEndWithAudioDelay(long audioDelay) {
+
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
+ Preconditions.checkState(
+ isOnEffort(), "You can call end() only if flight is on effort (started, not ended, on effort)");
+
+ TopiaContext transaction = persistence.beginTransaction();
+ try {
+ Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
+
+ // Create new TRANSIT route
+ if (logger.isInfoEnabled()) {
+ logger.info(String.format("Create TRANSIT [END] at %1$tH:%1$tM:%1$tS", currentDate));
+ }
+ currentRoute = service.createTransit(transaction, flight, currentDate, currentRoute);
+
+ audioRecorder.stopRecord(audioDelay);
+
+ state = FlightState.OFF_EFFORT;
+
+ transaction.commitTransaction();
+
+ // Fire events after commit
+ fireRouteAdded(currentRoute);
+ fireNextTransectChanged(nextTransect);
+ fireStateChanged(state);
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+
+ } finally {
+ persistence.endTransaction(transaction);
+ }
+ }
+
+// protected void setNextTransect(TransectFlight nextTransect, boolean fireEvents) {
+//
+// this.nextTransect = nextTransect;
+//
+// if (fireEvents) {
+// // Fire transect changed
+// for (FlightControllerUpdateListener listener : listeners) {
+// listener.onNextTransectChanged(nextTransect);
+// }
+// }
+// }
+//
+// protected void setNextTransectFrom(TransectFlight transect, boolean fireEvents) {
+//
+// TransectFlight nextTransect =
+// flight.getNextTransectFlightFrom(transect);
+//
+// setNextTransect(nextTransect, fireEvents);
+// }
+
+ protected void setFlightBeginDate(TopiaContext transaction,
+ Flight flight,
+ Date beginDate)
+ throws TopiaException {
+
+ FlightDAO flightDAO = SammoaDAOHelper.getFlightDAO(transaction);
+ flight.setBeginDate(beginDate);
+ flightDAO.update(flight);
+ }
+
+ protected void setFlightEndDate(TopiaContext transaction,
+ Flight flight,
+ Date endDate)
+ throws TopiaException {
+
+ FlightDAO flightDAO = SammoaDAOHelper.getFlightDAO(transaction);
+ flight.setEndDate(endDate);
+ flightDAO.update(flight);
+ }
+
+ protected void setObservationStatus(TopiaContext transaction,
+ Observation observation,
+ ObservationStatus status)
+ throws TopiaException {
+
+ ObservationDAO observationDAO =
+ SammoaDAOHelper.getObservationDAO(transaction);
+ observation.setObservationStatus(status);
+ observationDAO.update(observation);
+ }
+
+ protected void saveAudio(long delay) {
+
+ String fileName = String.format(
+ "%1$tF-%1$tH-%1$tM-%1$tS.%2$s.%3$s",
+ currentRoute.getBeginTime(),
+ currentRoute.getTopiaId(),
+ getAudioRecorder().getOutputType().getExtension()
+ );
+
+ File audioDir = context.getConfig().getAudioDirectory();
+
+ File audioFile = new File(audioDir, fileName);
+
+ try {
+ getAudioRecorder().record(audioFile, delay);
+ } catch (IOException e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ protected Date saveGPS(TopiaContext transaction,
+ GeoPoint geoPoint,
+ Flight flight)
+ throws TopiaException {
+
+ Date result;
+ if (geoPoint == null) {
+ result = new Date();
+ if (logger.isWarnEnabled()) {
+ logger.warn("No GPS point at {}", result);
+ }
+
+ } else {
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("Create GPS Point : {}", geoPoint);
+ }
+
+ result = geoPoint.getRecordTime();
+
+ GeoPointDAO dao = SammoaDAOHelper.getGeoPointDAO(transaction);
+
+ geoPoint.setFlight(flight);
+
+ dao.create(geoPoint);
+ }
+ return result;
+ }
+
+ protected void fireStateChanged(FlightState state) {
+ for (FlightControllerUpdateListener listener : listeners) {
+ listener.onStateChanged(state);
+ }
+ }
+
+ protected void fireRouteAdded(Route route) {
+ for (FlightControllerUpdateListener listener : listeners) {
+ listener.onRouteAdded(route);
+ }
+ }
+
+ protected void fireNextTransectChanged(TransectFlight nextTransect) {
+ for (FlightControllerUpdateListener listener : listeners) {
+ listener.onNextTransectChanged(nextTransect);
+ }
+ }
+
+ protected <T extends DeviceManager> T newDeviceManager(T oldInstance, Supplier<T> supplier)
+ throws DeviceTechnicalException {
+
+ Set<DeviceStateListener> stateListeners;
+ if (oldInstance != null) {
+
+ // Remove all existing listeners and keep them for the new instance
+ stateListeners = Sets.newHashSet(oldInstance.getDeviceStateListeners());
+ for (DeviceStateListener listener : stateListeners) {
+ oldInstance.removeDeviceStateListener(listener);
+ }
+
+ oldInstance.close();
+
+ } else {
+ stateListeners = Sets.newHashSet();
+ }
+
+ T result = supplier.get();
+
+ // Attach all updateListener
+ for (DeviceStateListener listener : stateListeners) {
+ result.addDeviceStateListener(listener);
+ }
+
+ return result;
+ }
+
+ @Override
+ public void locationChanged(GpsLocationEvent event) {
+ GeoPoint newLocation = event.getNewValue();
+ if (newLocation != null/* && newLocation.getTopiaId() == null*/) {
+ newLocation.setFlight(flight);
+ persistence.delayEntityCreation(newLocation);
+ }
+ }
+
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerDefault.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java (from rev 360, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerUpdateListener.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -0,0 +1,69 @@
+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(a)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);
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerUpdateListener.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightState.java (from rev 360, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightState.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightState.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightState.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -0,0 +1,57 @@
+/*
+ * #%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.application.flightController;
+
+/**
+ * Created: 20/06/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public enum FlightState {
+ /**
+ * The WAITING state is when the flight is not started and not ended.
+ * It appends when the flight is not really in used.
+ */
+ WAITING,
+
+ /**
+ * The OFF_EFFORT state is when the flight is started but not ended,
+ * and also if the current route is not an effort.
+ * It appends generally when the flight is in TRANSIT or CIRCLE_BACK.
+ */
+ OFF_EFFORT,
+
+ /**
+ * The ON_EFFORT state is when the flight is started, not ended but in
+ * current effort. It appends when a LEG is currently in progress.
+ */
+ ON_EFFORT,
+
+ /**
+ * The ENDED state is when the flight is ended.
+ * It appends when the current effort is finished and when no more route
+ * need to be registered.
+ */
+ ENDED
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightState.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/BaseHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/BaseHandler.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/BaseHandler.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -24,8 +24,8 @@
*/
package fr.ulr.sammoa.ui.swing;
-import fr.ulr.sammoa.application.FlightController;
import fr.ulr.sammoa.application.SammoaContext;
+import fr.ulr.sammoa.application.flightController.FlightController;
import fr.ulr.sammoa.ui.swing.flight.FlightUIModel;
/**
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -24,11 +24,11 @@
*/
package fr.ulr.sammoa.ui.swing;
-import fr.ulr.sammoa.application.FlightState;
import fr.ulr.sammoa.application.SammoaConfig;
import fr.ulr.sammoa.application.SammoaContext;
import fr.ulr.sammoa.application.device.DeviceTechnicalException;
import fr.ulr.sammoa.application.device.gps.GpsConfig;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.persistence.Campaign;
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.ui.swing.campaign.CampaignUI;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/SammoaUIContext.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/SammoaUIContext.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/SammoaUIContext.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -25,9 +25,9 @@
package fr.ulr.sammoa.ui.swing;
import com.google.common.base.Preconditions;
-import fr.ulr.sammoa.application.FlightController;
import fr.ulr.sammoa.application.SammoaConfig;
import fr.ulr.sammoa.application.SammoaContext;
+import fr.ulr.sammoa.application.flightController.FlightController;
import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler;
import fr.ulr.sammoa.ui.swing.flight.FlightUIModel;
import org.nuiton.widget.SwingSession;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/AddAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/AddAction.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/AddAction.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,7 +23,7 @@
*/
package fr.ulr.sammoa.ui.swing.action;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
import org.nuiton.util.Resource;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/BeginAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/BeginAction.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/BeginAction.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,7 +23,7 @@
*/
package fr.ulr.sammoa.ui.swing.action;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.persistence.RouteType;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
import org.nuiton.util.Resource;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/EndAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/EndAction.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/EndAction.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,7 +23,7 @@
*/
package fr.ulr.sammoa.ui.swing.action;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
import org.nuiton.util.Resource;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextAction.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/NextAction.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,7 +23,7 @@
*/
package fr.ulr.sammoa.ui.swing.action;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
import org.nuiton.util.Resource;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ObservationAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ObservationAction.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/ObservationAction.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,7 +23,7 @@
*/
package fr.ulr.sammoa.ui.swing.action;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.persistence.Position;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/SammoaAction.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,8 +23,8 @@
*/
package fr.ulr.sammoa.ui.swing.action;
-import fr.ulr.sammoa.application.FlightController;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightController;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.persistence.Route;
import fr.ulr.sammoa.persistence.TransectFlight;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StartAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StartAction.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StartAction.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,7 +23,7 @@
*/
package fr.ulr.sammoa.ui.swing.action;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
import org.nuiton.util.Resource;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StopAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StopAction.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/action/StopAction.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,7 +23,7 @@
*/
package fr.ulr.sammoa.ui.swing.action;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
import org.nuiton.util.Resource;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/campaign/CampaignUI.jaxx
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/campaign/CampaignUI.jaxx 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/campaign/CampaignUI.jaxx 2012-08-07 15:49:18 UTC (rev 361)
@@ -26,7 +26,7 @@
implements='fr.ulr.sammoa.ui.swing.SammoaUI<CampaignUIHandler>'>
<import>
- fr.ulr.sammoa.application.FlightState
+ fr.ulr.sammoa.application.flightController.FlightState
fr.ulr.sammoa.persistence.Region
fr.ulr.sammoa.persistence.Campaign
fr.ulr.sammoa.ui.swing.SammoaUIContext
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx 2012-08-07 15:49:18 UTC (rev 361)
@@ -28,7 +28,7 @@
javax.swing.BoxLayout
javax.swing.SwingConstants
jaxx.runtime.swing.ClockWidget
- fr.ulr.sammoa.application.FlightState
+ fr.ulr.sammoa.application.flightController.FlightState
</import>
<script><![CDATA[
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:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -24,7 +24,7 @@
*/
package fr.ulr.sammoa.ui.swing.flight;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.persistence.Route;
import fr.ulr.sammoa.ui.swing.BaseHandler;
import fr.ulr.sammoa.ui.swing.SammoaColors;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUI.jaxx 2012-08-07 15:49:18 UTC (rev 361)
@@ -40,7 +40,7 @@
fr.ulr.sammoa.persistence.Flight
fr.ulr.sammoa.persistence.Observer
fr.ulr.sammoa.persistence.Strate
- fr.ulr.sammoa.application.FlightState
+ fr.ulr.sammoa.application.flightController.FlightState
fr.ulr.sammoa.ui.swing.SammoaUIContext
fr.ulr.sammoa.ui.swing.ValidationTable
fr.ulr.sammoa.ui.swing.observations.EffortPanel
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:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -46,17 +46,17 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
-import fr.ulr.sammoa.application.FlightController;
-import fr.ulr.sammoa.application.FlightControllerDefault;
-import fr.ulr.sammoa.application.FlightControllerUpdateListener;
import fr.ulr.sammoa.application.FlightService;
-import fr.ulr.sammoa.application.FlightState;
import fr.ulr.sammoa.application.ReferentialService;
import fr.ulr.sammoa.application.SammoaConfig;
import fr.ulr.sammoa.application.SammoaContext;
import fr.ulr.sammoa.application.device.DeviceTechnicalException;
import fr.ulr.sammoa.application.device.gps.GpsLocationEvent;
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.FlightState;
import fr.ulr.sammoa.persistence.Campaign;
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.persistence.GeoPoint;
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:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIModel.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -26,7 +26,7 @@
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Lists;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.persistence.Observation;
import fr.ulr.sammoa.persistence.Observations;
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:48:54 UTC (rev 360)
+++ 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)
@@ -26,7 +26,7 @@
import com.bbn.openmap.omGraphics.OMGraphic;
import com.bbn.openmap.plugin.esri.EsriPlugIn;
-import fr.ulr.sammoa.application.FlightState;
+import fr.ulr.sammoa.application.flightController.FlightState;
import fr.ulr.sammoa.persistence.Route;
import fr.ulr.sammoa.persistence.Transect;
import fr.ulr.sammoa.persistence.TransectFlight;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.jaxx
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.jaxx 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.jaxx 2012-08-07 15:49:18 UTC (rev 361)
@@ -25,7 +25,7 @@
implements='fr.ulr.sammoa.ui.swing.SammoaUI<ExportMapUIHandler>'>
<import>
- fr.ulr.sammoa.application.FlightState
+ fr.ulr.sammoa.application.flightController.FlightState
fr.ulr.sammoa.persistence.Campaign
fr.ulr.sammoa.persistence.RouteType
fr.ulr.sammoa.persistence.Strate
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-07 15:48:54 UTC (rev 360)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-07 15:49:18 UTC (rev 361)
@@ -23,11 +23,11 @@
* #L%
*/
-import fr.ulr.sammoa.application.FlightController;
import fr.ulr.sammoa.application.FlightService;
import fr.ulr.sammoa.application.device.DeviceState;
import fr.ulr.sammoa.application.device.DeviceStateEvent;
import fr.ulr.sammoa.application.device.DeviceStateListener;
+import fr.ulr.sammoa.application.flightController.FlightController;
import fr.ulr.sammoa.persistence.Observation;
import fr.ulr.sammoa.persistence.ObservationStatus;
import fr.ulr.sammoa.persistence.Observations;
1
0
07 Aug '12
Author: fdesbois
Date: 2012-08-07 17:48:54 +0200 (Tue, 07 Aug 2012)
New Revision: 360
Url: http://forge.codelutin.com/repositories/revision/sammoa/360
Log:
refs #1378 : Clean listeners and create package device
Added:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateEvent.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.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/audio/AudioRecorderMock.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/
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/GpsConfig.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.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/device/gps/GpsLocationEvent.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java
Removed:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java
trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java
trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.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/FlightBarModel.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/layer/GpsTracingLayer.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -1,80 +0,0 @@
-package fr.ulr.sammoa.application;
-/*
- * #%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 java.util.Set;
-
-/**
- * Created: 06/08/12
- *
- * @author fdesbois <florian.desbois(a)codelutin.com>
- */
-public interface DeviceManager<L extends DeviceUpdateListener> {
-
- /**
- * Open the device
- *
- * @throws DeviceTechnicalException for errors on open
- */
- void open() throws DeviceTechnicalException;
-
- /**
- * Start the device session (recording, reading, ...) and try opening it if necessary. The open
- * could be tried several times to permit a proper start.
- */
- void start();
-
- /**
- * Stop the device session
- */
- void stop();
-
- /**
- * Close the device and stop it if necessary
- *
- * @throws DeviceTechnicalException for errors on close
- */
- void close() throws DeviceTechnicalException;
-
- /**
- * @return the DeviceState
- */
- DeviceState getState();
-
- /**
- * @param listener DeviceUpdateListener to add
- */
- void addUpdateListener(L listener);
-
- /**
- * @param listener DeviceUpdateListener to remove
- */
- void removeUpdateListener(L listener);
-
- /**
- * @return all the listeners
- */
- Set<L> getUpdateListeners();
-
-}
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -1,41 +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.application;
-
-/**
- * Enumeration to represent device (gps, audio) state.
- *
- * @author echatellier
- */
-public enum DeviceState {
- /** voyant gris : pas de peripherique */
- NO_DEVICE,
- /** voyant bleu : peripherique prêt */
- READY,
- /** voyant vert : reception de données */
- RECORDING,
- /** voyant rouge clignotant : périphirique prêt mais aucune données */
- NO_DATA
-}
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -1,49 +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.application;
-
-/**
- * @author fdesbois <fdesbois(a)codelutin.com>
- */
-public class DeviceTechnicalException extends RuntimeException {
-
- private static final long serialVersionUID = 1L;
-
- protected DeviceManager source;
-
- public DeviceTechnicalException(DeviceManager source, String message) {
- super(message);
- this.source = source;
- }
-
- public DeviceTechnicalException(DeviceManager source, String message, Throwable cause) {
- super(message, cause);
- this.source = source;
- }
-
- public DeviceManager getSource() {
- return source;
- }
-}
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -1,56 +0,0 @@
-package fr.ulr.sammoa.application;
-/*
- * #%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%
- */
-
-/**
- * Created: 06/08/12
- *
- * @author fdesbois <florian.desbois(a)codelutin.com>
- */
-public class DeviceUpdateEvent<T> {
-
- protected DeviceManager source;
-
- protected T oldValue;
-
- protected T newValue;
-
- public DeviceUpdateEvent(DeviceManager source, T oldValue, T newValue) {
- this.source = source;
- this.oldValue = oldValue;
- this.newValue = newValue;
- }
-
- public DeviceManager getSource() {
- return source;
- }
-
- public T getOldValue() {
- return oldValue;
- }
-
- public T getNewValue() {
- return newValue;
- }
-}
\ No newline at end of file
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -1,39 +0,0 @@
-package fr.ulr.sammoa.application;
-/*
- * #%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%
- */
-
-/**
- * Created: 06/08/12
- *
- * @author fdesbois <florian.desbois(a)codelutin.com>
- */
-public interface DeviceUpdateListener {
-
- /**
- * Update device state.
- *
- * @param event new event
- */
- void onStateChanged(DeviceUpdateEvent<DeviceState> event);
-}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -23,10 +23,11 @@
* #L%
*/
-import fr.ulr.sammoa.application.audio.AudioRecorder;
-import fr.ulr.sammoa.application.audio.AudioRecorderDefault;
-import fr.ulr.sammoa.application.gps.GpsConfig;
-import fr.ulr.sammoa.application.gps.GpsHandler;
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+import fr.ulr.sammoa.application.device.audio.AudioRecorder;
+import fr.ulr.sammoa.application.device.audio.AudioRecorderDefault;
+import fr.ulr.sammoa.application.device.gps.GpsConfig;
+import fr.ulr.sammoa.application.device.gps.GpsHandler;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.persistence.Observation;
import fr.ulr.sammoa.persistence.ObservationStatus;
@@ -66,7 +67,7 @@
/**
* @param config GpsConfig to initialize the Gps
- * @exception DeviceTechnicalException if the gps device can't be opened properly
+ * @exception fr.ulr.sammoa.application.device.DeviceTechnicalException if the gps device can't be opened properly
*/
void openGpsDevice(GpsConfig config) throws DeviceTechnicalException;
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -28,11 +28,15 @@
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.Sets;
-import fr.ulr.sammoa.application.audio.AudioRecorder;
-import fr.ulr.sammoa.application.audio.AudioRecorderDefault;
-import fr.ulr.sammoa.application.gps.GpsConfig;
-import fr.ulr.sammoa.application.gps.GpsHandler;
-import fr.ulr.sammoa.application.gps.GpsUpdateListener;
+import fr.ulr.sammoa.application.device.DeviceManager;
+import fr.ulr.sammoa.application.device.DeviceStateListener;
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+import fr.ulr.sammoa.application.device.audio.AudioRecorder;
+import fr.ulr.sammoa.application.device.audio.AudioRecorderDefault;
+import fr.ulr.sammoa.application.device.gps.GpsConfig;
+import fr.ulr.sammoa.application.device.gps.GpsHandler;
+import fr.ulr.sammoa.application.device.gps.GpsLocationEvent;
+import fr.ulr.sammoa.application.device.gps.GpsLocationListener;
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.persistence.FlightDAO;
import fr.ulr.sammoa.persistence.GeoPoint;
@@ -66,7 +70,7 @@
*
* @author fdesbois <desbois(a)codelutin.com>
*/
-public class FlightControllerDefault implements GpsUpdateListener, FlightController {
+public class FlightControllerDefault implements GpsLocationListener, FlightController {
private static final Logger logger = LoggerFactory.getLogger(FlightControllerDefault.class);
@@ -148,6 +152,19 @@
@Override
public void openGpsDevice(final GpsConfig config) throws DeviceTechnicalException {
+ Set<GpsLocationListener> locationListeners;
+ if (gpsHandler != null) {
+
+ // Remove all existing listeners and keep them for the new instance
+ locationListeners = Sets.newHashSet(gpsHandler.getGpsLocationListeners());
+ for (GpsLocationListener listener : locationListeners) {
+ gpsHandler.removeGpsLocationListener(listener);
+ }
+
+ } else {
+ locationListeners = Sets.newHashSet();
+ }
+
gpsHandler = newDeviceManager(gpsHandler, new Supplier<GpsHandler>() {
@Override
@@ -161,7 +178,7 @@
gpsHandlerClass.getConstructor(GpsConfig.class);
GpsHandler result = constructor.newInstance(config);
- result.addUpdateListener(FlightControllerDefault.this);
+ result.addGpsLocationListener(FlightControllerDefault.this);
return result;
} catch (InstantiationException e) {
@@ -176,6 +193,10 @@
}
});
+ for (GpsLocationListener listener : locationListeners) {
+ gpsHandler.addGpsLocationListener(listener);
+ }
+
if (initialized && isRunning()) {
gpsHandler.start();
} else {
@@ -821,33 +842,33 @@
protected <T extends DeviceManager> T newDeviceManager(T oldInstance, Supplier<T> supplier)
throws DeviceTechnicalException {
- Set<DeviceUpdateListener> updateListeners;
+ Set<DeviceStateListener> stateListeners;
if (oldInstance != null) {
// Remove all existing listeners and keep them for the new instance
- updateListeners = Sets.newHashSet(oldInstance.getUpdateListeners());
- for (DeviceUpdateListener listener : updateListeners) {
- oldInstance.removeUpdateListener(listener);
+ stateListeners = Sets.newHashSet(oldInstance.getDeviceStateListeners());
+ for (DeviceStateListener listener : stateListeners) {
+ oldInstance.removeDeviceStateListener(listener);
}
oldInstance.close();
} else {
- updateListeners = Sets.newHashSet();
+ stateListeners = Sets.newHashSet();
}
T result = supplier.get();
// Attach all updateListener
- for (DeviceUpdateListener listener : updateListeners) {
- result.addUpdateListener(listener);
+ for (DeviceStateListener listener : stateListeners) {
+ result.addDeviceStateListener(listener);
}
return result;
}
@Override
- public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ public void locationChanged(GpsLocationEvent event) {
GeoPoint newLocation = event.getNewValue();
if (newLocation != null/* && newLocation.getTopiaId() == null*/) {
newLocation.setFlight(flight);
@@ -855,9 +876,4 @@
}
}
- @Override
- public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
- // nothing to do
- }
-
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -26,7 +26,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
-import fr.ulr.sammoa.application.gps.GpsConfig;
+import fr.ulr.sammoa.application.device.gps.GpsConfig;
import fr.ulr.sammoa.persistence.AutoSaveListener;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.nuiton.util.ApplicationConfig;
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,80 @@
+package fr.ulr.sammoa.application.device;
+/*
+ * #%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 java.util.Set;
+
+/**
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public interface DeviceManager {
+
+ /**
+ * Open the device
+ *
+ * @throws DeviceTechnicalException for errors on open
+ */
+ void open() throws DeviceTechnicalException;
+
+ /**
+ * Start the device session (recording, reading, ...) and try opening it if necessary. The open
+ * could be tried several times to permit a proper start.
+ */
+ void start();
+
+ /**
+ * Stop the device session
+ */
+ void stop();
+
+ /**
+ * Close the device and stop it if necessary
+ *
+ * @throws DeviceTechnicalException for errors on close
+ */
+ void close() throws DeviceTechnicalException;
+
+ /**
+ * @return the DeviceState
+ */
+ DeviceState getState();
+
+ /**
+ * @param listener DeviceStateListener to add
+ */
+ void addDeviceStateListener(DeviceStateListener listener);
+
+ /**
+ * @param listener DeviceStateListener to remove
+ */
+ void removeDeviceStateListener(DeviceStateListener listener);
+
+ /**
+ * @return all the listeners
+ */
+ Set<DeviceStateListener> getDeviceStateListeners();
+
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManager.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceState.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,41 @@
+/*
+ * #%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.application.device;
+
+/**
+ * Enumeration to represent device (gps, audio) state.
+ *
+ * @author echatellier
+ */
+public enum DeviceState {
+ /** voyant gris : pas de peripherique */
+ NO_DEVICE,
+ /** voyant bleu : peripherique prêt */
+ READY,
+ /** voyant vert : reception de données */
+ RECORDING,
+ /** voyant rouge clignotant : périphirique prêt mais aucune données */
+ NO_DATA
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceState.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateEvent.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateEvent.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateEvent.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,56 @@
+package fr.ulr.sammoa.application.device;
+/*
+ * #%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%
+ */
+
+/**
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public class DeviceStateEvent {
+
+ protected DeviceManager source;
+
+ protected DeviceState oldValue;
+
+ protected DeviceState newValue;
+
+ public DeviceStateEvent(DeviceManager source, DeviceState oldValue, DeviceState newValue) {
+ this.source = source;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ public DeviceManager getSource() {
+ return source;
+ }
+
+ public DeviceState getOldValue() {
+ return oldValue;
+ }
+
+ public DeviceState getNewValue() {
+ return newValue;
+ }
+}
\ No newline at end of file
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,39 @@
+package fr.ulr.sammoa.application.device;
+/*
+ * #%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%
+ */
+
+/**
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public interface DeviceStateListener {
+
+ /**
+ * Update device state.
+ *
+ * @param event new event
+ */
+ void stateChanged(DeviceStateEvent event);
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceStateListener.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,49 @@
+/*
+ * #%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.application.device;
+
+/**
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ */
+public class DeviceTechnicalException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ protected DeviceManager source;
+
+ public DeviceTechnicalException(DeviceManager source, String message) {
+ super(message);
+ this.source = source;
+ }
+
+ public DeviceTechnicalException(DeviceManager source, String message, Throwable cause) {
+ super(message, cause);
+ this.source = source;
+ }
+
+ public DeviceManager getSource() {
+ return source;
+ }
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceTechnicalException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorder.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,64 @@
+package fr.ulr.sammoa.application.device.audio;
+/*
+ * #%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.application.device.DeviceManager;
+
+import javax.sound.sampled.AudioFileFormat;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Recorder of audio files. Two recorder are used and a delay between recording
+ * could be customized.
+ * <p/>
+ * Created: 12/07/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public interface AudioRecorder extends DeviceManager {
+
+ /**
+ * @return the {@link AudioFileFormat.Type} used (default is WAV)
+ */
+ AudioFileFormat.Type getOutputType();
+
+ /**
+ * Record the audio line and save the data in given {@code outputFile}. The
+ * previous recording will be stopped in {@code delaySeconds}. The delay is
+ * useful to avoid recording lost or too quick between two files.
+ *
+ * @param outputFile File to record
+ * @param delaySeconds Delay for previous recording
+ * @throws IOException for recording issues on the file
+ */
+ void record(File outputFile, long delaySeconds) throws IOException;
+
+ /**
+ * Stop the current recording after {@code delaySeconds}.
+ *
+ * @param delaySeconds Delay for current recording
+ */
+ void stopRecord(long delaySeconds);
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorder.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderDefault.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,516 @@
+/*
+ * #%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.application.device.audio;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import fr.ulr.sammoa.application.device.DeviceState;
+import fr.ulr.sammoa.application.device.DeviceStateEvent;
+import fr.ulr.sammoa.application.device.DeviceStateListener;
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.TargetDataLine;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * Created: 16/05/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public class AudioRecorderDefault implements AudioRecorder {
+
+ private static final Logger logger = LoggerFactory.getLogger(AudioRecorderDefault.class);
+
+ private static final AudioFormat.Encoding DEFAULT_ENCODING = AudioFormat.Encoding.PCM_SIGNED;
+
+ private static final float DEFAULT_SAMPLE_RATE = 44100.0F;
+
+ private static final int DEFAULT_SAMPLE_SIZE_IN_BITS = 16;
+
+ private static final int DEFAULT_CHANNELS = 2;
+
+ private static final int DEFAULT_FRAME_SIZE = 4;
+
+ private static final float DEFAULT_FRAME_RATE = 44100.0F;
+
+ private static final boolean DEFAULT_BIG_ENDIAN = false;
+
+ private static final AudioFileFormat.Type DEFAULT_OUTPUT_TYPE = AudioFileFormat.Type.WAVE;
+
+ protected AudioFormat audioFormat;
+
+ protected AudioFileFormat.Type outputType;
+
+ protected TargetDataLine dataLine;
+
+ protected DataLineReader lineReader;
+
+ private Recorder recorder1;
+
+ private Recorder recorder2;
+
+ protected Recorder currentRecorder;
+
+// // For debug purpose
+// private int count;
+
+ protected DeviceState state;
+
+ protected Set<DeviceStateListener> listeners;
+
+ public AudioRecorderDefault() {
+ this(new AudioFormat(
+ DEFAULT_ENCODING,
+ DEFAULT_SAMPLE_RATE,
+ DEFAULT_SAMPLE_SIZE_IN_BITS,
+ DEFAULT_CHANNELS,
+ DEFAULT_FRAME_SIZE,
+ DEFAULT_FRAME_RATE,
+ DEFAULT_BIG_ENDIAN
+
+ ), DEFAULT_OUTPUT_TYPE);
+ }
+
+ public AudioRecorderDefault(AudioFormat audioFormat,
+ AudioFileFormat.Type outputType) {
+
+ this.audioFormat = audioFormat;
+ this.outputType = outputType;
+ this.listeners = Sets.newHashSet();
+ this.state = DeviceState.NO_DEVICE;
+ }
+
+ @Override
+ public DeviceState getState() {
+ return state;
+ }
+
+ protected void setState(DeviceState state) {
+ DeviceState oldValue = getState();
+ this.state = state;
+
+ // Fire on listeners
+ for (DeviceStateListener listener : listeners) {
+ listener.stateChanged(new DeviceStateEvent(this, oldValue, state));
+ }
+ }
+
+ @Override
+ public AudioFileFormat.Type getOutputType() {
+ return outputType;
+ }
+
+ @Override
+ public void addDeviceStateListener(DeviceStateListener listener) {
+ listeners.add(listener);
+ }
+
+ @Override
+ public void removeDeviceStateListener(DeviceStateListener listener) {
+ listeners.remove(listener);
+ }
+
+ @Override
+ public Set<DeviceStateListener> getDeviceStateListeners() {
+ return listeners;
+ }
+
+ @Override
+ public void open() throws DeviceTechnicalException {
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Open the audio line");
+ }
+
+ DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
+ try {
+ dataLine = (TargetDataLine) AudioSystem.getLine(info);
+ dataLine.open(audioFormat);
+
+ // Start using the line for recording
+ dataLine.start();
+
+ setState(DeviceState.READY);
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Audio line is ready");
+ }
+
+ } catch (IllegalArgumentException e) {
+ setState(DeviceState.NO_DEVICE);
+ throw new DeviceTechnicalException(this, "Can't open audio device", e);
+
+ } catch (IllegalStateException e) {
+ setState(DeviceState.NO_DEVICE);
+ throw new DeviceTechnicalException(this, "Can't open audio device", e);
+
+ } catch (SecurityException e) {
+ setState(DeviceState.NO_DEVICE);
+ throw new DeviceTechnicalException(this, "Can't open audio device", e);
+
+ } catch (LineUnavailableException e) {
+ setState(DeviceState.NO_DEVICE);
+ throw new DeviceTechnicalException(this, "Can't open audio device", e);
+ }
+ }
+
+ @Override
+ public void start() {
+
+ if (getState() == DeviceState.READY) {
+
+ // Stop previous recording
+ stop();
+
+ logger.info("Start reading audio line");
+
+ lineReader = new DataLineReader();
+ lineReader.start();
+ }
+ }
+
+ @Override
+ public void record(File outputFile, long delaySeconds) throws IOException {
+
+ if (DeviceState.NO_DATA == state) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Can't record " + outputFile.getAbsolutePath() + ", no available dataLine");
+ }
+
+ // XXX-fdesbois-2012-08-03 : try to start the line again ?
+
+ return;
+ }
+
+ Preconditions.checkArgument(outputFile != null);
+ Preconditions.checkState(dataLine != null,
+ "You must start the AudioRecorder to initialize " +
+ "the audio line before call record method");
+
+
+ // Start recorder1
+ if (currentRecorder == null) {
+ recorder1 = new Recorder(outputFile, audioFormat, outputType, lineReader);
+ currentRecorder = recorder1;
+
+ // Stop recorder1 if recording and start recorder2
+ } else if (currentRecorder == recorder1) {
+
+ if (recorder1.isRecording()) {
+ recorder1.stop(delaySeconds);
+ }
+
+ if (recorder2 != null && recorder2.isRecording()) {
+ recorder2.stop();
+ }
+ recorder2 = new Recorder(outputFile, audioFormat, outputType, lineReader);
+ currentRecorder = recorder2;
+
+ // Stop recorder2 if recording and start recorder1
+ } else if (currentRecorder == recorder2) {
+
+ if (recorder2.isRecording()) {
+ recorder2.stop(delaySeconds);
+ }
+
+ if (recorder1.isRecording()) {
+ recorder1.stop();
+ }
+ recorder1 = new Recorder(outputFile, audioFormat, outputType, lineReader);
+ currentRecorder = recorder1;
+ }
+ }
+
+ @Override
+ public void stopRecord(long delaySeconds) {
+ if (currentRecorder != null) {
+ currentRecorder.stop(delaySeconds);
+ }
+ }
+
+ @Override
+ public void stop() {
+
+ if (getState() != DeviceState.NO_DEVICE) {
+
+ // Destroy the thread
+ if (lineReader != null) {
+ lineReader.interrupt();
+ }
+ lineReader = null;
+ }
+ }
+
+ @Override
+ public void close() throws DeviceTechnicalException {
+
+ stop();
+
+ if (dataLine != null && dataLine.isRunning()) {
+
+ logger.info("Close the audio line");
+
+ dataLine.stop();
+ dataLine.drain();
+ dataLine.close();
+ dataLine = null;
+
+ setState(DeviceState.NO_DEVICE);
+ }
+ }
+
+ protected class DataLineReader extends Thread {
+
+ private List<Recorder> recorders = Collections.synchronizedList(Lists.<Recorder>newArrayList());
+
+ public void addRecorder(Recorder recorder) {
+ recorders.add(recorder);
+ }
+
+ public void removeRecorder(Recorder recorder) {
+ recorders.remove(recorder);
+ }
+
+ @Override
+ public void run() {
+
+ int frameSize = audioFormat.getFrameSize();
+ int bufferLengthInFrames = dataLine.getBufferSize() / 8;
+ int bufferSize = bufferLengthInFrames * frameSize;
+ byte[] buffer = new byte[bufferSize];
+
+ // Start reading the line
+ int numBytesRead;
+ while (lineReader != null) {
+
+ if (!recorders.isEmpty()) {
+
+ setState(DeviceState.RECORDING);
+
+ numBytesRead = dataLine.read(buffer, 0, bufferSize);
+ synchronized (recorders) {
+ for (Recorder recorder : recorders) {
+ recorder.write(buffer, 0, numBytesRead);
+ }
+ }
+
+ } else {
+ setState(DeviceState.READY);
+ }
+ }
+
+ logger.debug("Stop all recorders (" + recorders.size() + ")");
+
+ List<Recorder> list;
+ synchronized (recorders) {
+ list = Lists.newArrayList(recorders);
+ }
+ for (Recorder recorder : list) {
+ recorder.stop();
+ }
+ }
+ }
+
+ protected static class Recorder {
+
+ protected AudioFormat audioFormat;
+
+ protected AudioFileFormat.Type outputType;
+
+ protected ByteArrayOutputStream bufferStream;
+
+ protected String outputFilePath;
+
+ protected OutputStream outputStream;
+
+ protected DataLineReader lineReader;
+
+ protected boolean stop;
+
+ protected boolean stopScheduled;
+
+ protected TimerTask saveTask = new SaveTask();
+
+ protected TimerTask stopRecording = new StopTask();
+
+ protected class SaveTask extends TimerTask {
+
+ @Override
+ public void run() {
+ save();
+ }
+ }
+
+ protected class StopTask extends TimerTask {
+
+ @Override
+ public void run() {
+ doStop();
+ }
+ }
+
+ public Recorder(File outputFile,
+ AudioFormat audioFormat,
+ AudioFileFormat.Type outputType,
+ DataLineReader lineReader) throws IOException {
+
+ this.outputFilePath = outputFile.getAbsolutePath();
+ boolean newFile = outputFile.createNewFile();
+ if (newFile) {
+ logger.info("Record a new audio file '{}'", outputFilePath);
+ } else {
+ logger.info("Use existing file '{}' to continue recording", outputFilePath);
+ }
+ this.bufferStream = new ByteArrayOutputStream();
+ this.outputStream = new BufferedOutputStream(new FileOutputStream(outputFile, true));
+ this.audioFormat = audioFormat;
+ this.outputType = outputType;
+ this.lineReader = lineReader;
+ this.lineReader.addRecorder(this);
+
+ // Save the audio file every 3 seconds
+ new Timer().schedule(saveTask, 0, 3000);
+ }
+
+ public boolean isRecording() {
+ return !stop;
+ }
+
+ public void write(byte[] buffer, int offset, int length) {
+
+ if (stop) {
+ logger.debug("File is already saved ({})", outputFilePath);
+ return;
+ }
+ synchronized (bufferStream) {
+ bufferStream.write(buffer, offset, length);
+ }
+ }
+
+ public void stop(long delay) {
+
+ if (stop) {
+ logger.debug("File is already saved ({})", outputFilePath);
+ return;
+ }
+
+ if (stopScheduled) {
+ logger.debug("Stop is already scheduled ({})", outputFilePath);
+ return;
+ }
+ long delayMilliseconds = delay * 1000;
+ logger.debug("Call stop recording ({}) with delay = {} ms", outputFilePath, delayMilliseconds);
+ new Timer().schedule(stopRecording, delayMilliseconds);
+ stopScheduled = true;
+ }
+
+ public void stop() {
+
+ if (stop) {
+ logger.debug("File is already saved ({})", outputFilePath);
+ return;
+ }
+
+ stopRecording.cancel();
+ doStop();
+ }
+
+ protected void doStop() {
+
+ logger.debug("Stop recording ({})", outputFilePath);
+ lineReader.removeRecorder(this);
+ saveTask.cancel();
+ save();
+ stop = true;
+ try {
+
+ bufferStream.flush();
+ bufferStream.close();
+
+ } catch (IOException e) {
+ Throwables.propagate(e);
+
+ } finally {
+ IOUtils.closeQuietly(bufferStream);
+ }
+ }
+
+ protected void save() {
+
+ // reset the buffer stream
+ byte[] bytes;
+ synchronized (bufferStream) {
+ bytes = bufferStream.toByteArray();
+ bufferStream.reset();
+ }
+
+ // prepare AudioStream
+ AudioInputStream audioStream = new AudioInputStream(
+ new ByteArrayInputStream(bytes),
+ audioFormat,
+ bytes.length / audioFormat.getFrameSize()
+ );
+
+ try {
+ logger.debug("Save in file {}", outputFilePath);
+
+ AudioSystem.write(audioStream, outputType, outputStream);
+
+ } catch (IOException e) {
+ logger.error("Can't record file {}", outputFilePath, e);
+
+ } finally {
+ try {
+ audioStream.close();
+ } catch (IOException e) {
+ logger.error("Can't close file {}", outputFilePath, e);
+ }
+ }
+ }
+ }
+
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderMock.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,99 @@
+package fr.ulr.sammoa.application.device.audio;
+/*
+ * #%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 com.google.common.collect.Sets;
+import fr.ulr.sammoa.application.device.DeviceState;
+import fr.ulr.sammoa.application.device.DeviceStateListener;
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+
+import javax.sound.sampled.AudioFileFormat;
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+
+/**
+ * Mock for {@link AudioRecorder} that record nothing.
+ * <p/>
+ * Created: 12/07/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public class AudioRecorderMock implements AudioRecorder {
+
+ @Override
+ public DeviceState getState() {
+ return DeviceState.NO_DEVICE;
+ }
+
+ @Override
+ public AudioFileFormat.Type getOutputType() {
+ return AudioFileFormat.Type.WAVE;
+ }
+
+ @Override
+ public void open() throws DeviceTechnicalException {
+ // do nothing
+ }
+
+ @Override
+ public void start() {
+ // do nothing
+ }
+
+ @Override
+ public void record(File outputFile, long delaySeconds) throws IOException {
+ // do nothing
+ }
+
+ @Override
+ public void stopRecord(long delaySeconds) {
+ // do nothing
+ }
+
+ @Override
+ public void stop() {
+ // do nothing
+ }
+
+ @Override
+ public void close() throws DeviceTechnicalException {
+ // do nothing
+ }
+
+ @Override
+ public void addDeviceStateListener(DeviceStateListener listener) {
+ // do nothing
+ }
+
+ @Override
+ public void removeDeviceStateListener(DeviceStateListener listener) {
+ // do nothing
+ }
+
+ @Override
+ public Set<DeviceStateListener> getDeviceStateListeners() {
+ return Sets.newHashSet();
+ }
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderMock.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/BaseGpsHandler.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,224 @@
+/*
+ * #%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.application.device.gps;
+
+import com.google.common.collect.Sets;
+import fr.ulr.sammoa.application.device.DeviceState;
+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.GeoPoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * Base class for {@link GpsHandler} interface. This class contains common behaviour
+ * for automatic check on a given {@code period}. For that, this class contains
+ * a {@link TimerTask} scheduled from {@link #start()}. The {@link #open()} method
+ * will be called on start if state is still {@link DeviceState#NO_DEVICE}.
+ * The method {@link #getCurrentLocation()} must return null if the location doesn't
+ * change or the GPS is down.
+ *
+ * Created: 02/07/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ * @since 0.2
+ * @see FakeGpsHandler
+ * @see GpsHandlerGpsylon
+ */
+public abstract class BaseGpsHandler implements GpsHandler {
+
+ private static final Logger logger = LoggerFactory.getLogger(BaseGpsHandler.class);
+
+ protected Set<DeviceStateListener> deviceStateListeners;
+ protected Set<GpsLocationListener> gpsLocationListeners;
+
+ /** To test if connection to device is effective. */
+ protected DeviceState state;
+
+ protected GpsConfig config;
+
+ protected Timer timer;
+
+ /**
+ * Value to check the number of timer update failures before the DeviceState
+ * becomes {@link DeviceState#NO_DATA}
+ */
+ protected int nbFailuresMax;
+
+ public BaseGpsHandler(GpsConfig config) {
+ this.config = config;
+ this.state = DeviceState.NO_DEVICE;
+ this.gpsLocationListeners = Sets.newHashSet();
+ this.nbFailuresMax =
+ (int) Math.ceil(config.getTimeout() / config.getCheckPeriod());
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("GPS NbFailuresMax = " + nbFailuresMax);
+ }
+ }
+
+ public GpsConfig getConfig() {
+ return config;
+ }
+
+ @Override
+ public DeviceState getState() {
+ return state;
+ }
+
+ @Override
+ public void start() throws DeviceTechnicalException {
+
+ long periodMilliseconds = config.getCheckPeriod() * 1000;
+
+ if (getState() == DeviceState.READY) {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Start scheduling GpsHandler every "
+ + periodMilliseconds + " milliseconds");
+ }
+
+ timer = new Timer();
+ timer.schedule(recordTask, 0, periodMilliseconds);
+
+ } else {
+
+ timer = new Timer();
+ timer.schedule(openTask, 0, periodMilliseconds);
+ }
+ }
+
+ @Override
+ public void stop() {
+ timer.cancel();
+ timer = null;
+ }
+
+ @Override
+ public void addDeviceStateListener(DeviceStateListener deviceStateListener) {
+ deviceStateListeners.add(deviceStateListener);
+ }
+
+ @Override
+ public void removeDeviceStateListener(DeviceStateListener deviceStateListener) {
+ deviceStateListeners.remove(deviceStateListener);
+ }
+
+ @Override
+ public Set<DeviceStateListener> getDeviceStateListeners() {
+ return deviceStateListeners;
+ }
+
+ @Override
+ public void addGpsLocationListener(GpsLocationListener gpsLocationListener) {
+ gpsLocationListeners.add(gpsLocationListener);
+ }
+
+ @Override
+ public void removeGpsLocationListener(GpsLocationListener gpsLocationListener) {
+ gpsLocationListeners.remove(gpsLocationListener);
+ }
+
+ @Override
+ public Set<GpsLocationListener> getGpsLocationListeners() {
+ return gpsLocationListeners;
+ }
+
+ protected void setState(DeviceState state) {
+ DeviceState oldValue = getState();
+ this.state = state;
+
+ for (DeviceStateListener listener : deviceStateListeners) {
+ listener.stateChanged(new DeviceStateEvent(this, oldValue, state));
+ }
+ }
+
+ protected TimerTask openTask = new TimerTask() {
+
+ @Override
+ public void run() {
+ try {
+
+ open();
+
+ timer.cancel();
+ timer = null;
+
+ start();
+
+ } catch (DeviceTechnicalException ex) {
+
+ // We use NO_DATA, because this task is during start
+ setState(DeviceState.NO_DATA);
+
+ if (logger.isErrorEnabled()) {
+ logger.error("Can't open GPS device. Try again in "
+ + this.scheduledExecutionTime() + " milliseconds", ex);
+ }
+ }
+ }
+ };
+
+ protected TimerTask recordTask = new TimerTask() {
+
+ protected GeoPoint location;
+
+ protected int nbFailures;
+
+ @Override
+ public void run() {
+
+ GeoPoint lastLocation = location;
+
+ location = getCurrentLocation();
+
+ // reset nbFailures if currentLocation is defined
+ if (location != null) {
+ nbFailures = 0;
+ } else {
+ nbFailures++;
+ }
+
+ // Data is unavailable
+ if (location == null && nbFailures >= nbFailuresMax) {
+ setState(DeviceState.NO_DATA);
+
+ // GPS is recording
+ } else {
+
+ setState(DeviceState.RECORDING);
+
+ // Fire events for location change
+ for (GpsLocationListener listener : gpsLocationListeners) {
+ listener.locationChanged(new GpsLocationEvent(BaseGpsHandler.this, lastLocation, location));
+ }
+ }
+ }
+ };
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/FakeGpsHandler.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,168 @@
+/*
+ * #%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.application.device.gps;
+
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+import fr.ulr.sammoa.persistence.GeoPoint;
+import fr.ulr.sammoa.persistence.GeoPointImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Date;
+import java.util.Random;
+
+/**
+ * Un Fake pour {@link GpsHandler}, il simule un déplacement toute les secondes
+ * à partir du point 0, 0.
+ */
+public class FakeGpsHandler extends BaseGpsHandler {
+
+ private static final Logger logger = LoggerFactory.getLogger(FakeGpsHandler.class);
+
+ public static final int MAX_POINTS = 100;
+
+ protected GeoPoint startingPoint;
+
+ protected GeoPoint currentLocation;
+
+ protected Thread thread;
+
+ public FakeGpsHandler(GpsConfig config) {
+ this(config, new GeoPointImpl(46.164139,-1.150503));
+ }
+
+ public FakeGpsHandler(GpsConfig config, GeoPoint origin) {
+ super(config);
+
+ startingPoint = new GeoPointImpl(origin.getLatitude(), origin.getLongitude());
+//
+// // add new thread to simulate gps state change
+// Timer timer = new Timer();
+// timer.schedule(new TimerTask() {
+// protected Random r = new Random();
+// protected DeviceState currentState = DeviceState.NO_DEVICE;
+//
+// @Override
+// public void run() {
+// DeviceState newState = currentState;
+// if (r.nextInt(32) > 25) {
+// newState = DeviceState.NO_DEVICE;
+// } else {
+// if (started) {
+// if (r.nextInt(32) > 25) {
+// newState = DeviceState.NO_DATA;
+// } else {
+// newState = DeviceState.RECORDING;
+// }
+// } else {
+// newState = DeviceState.READY;
+// }
+// }
+//
+// if (!newState.equals(currentState)) {
+// currentState = newState;
+// for (GpsLocationListener locationUpdateListener : gpsLocationListeners) {
+// locationUpdateListener.stateChanged(currentState);
+// }
+// }
+// }
+// }, 10000, 10000);
+ }
+
+ @Override
+ public void open() throws DeviceTechnicalException {
+ // nothing to do
+ }
+
+ @Override
+ public void start() {
+ if (thread == null) {
+ thread = new Thread(new GpsPointGenerator());
+ thread.start();
+ }
+ super.start();
+ }
+
+ @Override
+ public void close() throws DeviceTechnicalException {
+ // nothing to do
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+
+ if (thread != null) {
+ thread.interrupt();
+ thread = null;
+ }
+
+ super.finalize();
+ }
+
+ @Override
+ public GeoPoint getCurrentLocation() {
+ GeoPoint result;
+ // Location already saved, return null (i.e. no new location)
+ if (currentLocation == null || currentLocation.getTopiaId() != null) {
+ result = null;
+
+ } else {
+ result = currentLocation;
+ }
+ return result;
+ }
+
+ protected class GpsPointGenerator implements Runnable {
+
+ @Override
+ public void run() {
+
+ double latitude = startingPoint.getLatitude();
+ double longitude = startingPoint.getLongitude();
+
+ Random random = new Random(1337);
+
+ int count = MAX_POINTS;
+
+ while (true && count != 0) {
+
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ logger.debug("Interrupt sleeping, thread will be destroy", e);
+ }
+
+ latitude += random.nextDouble() - 0.5;
+ longitude += random.nextDouble() - 0.5;
+
+ currentLocation = new GeoPointImpl(latitude, longitude);
+ currentLocation.setRecordTime(new Date());
+
+ count--;
+ }
+ }
+ }
+
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsConfig.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,205 @@
+package fr.ulr.sammoa.application.device.gps;
+/*
+ * #%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 com.google.common.base.Preconditions;
+import org.nuiton.util.ApplicationConfig;
+
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Created: 18/06/12
+ *
+ * @author fdesbois <desbois(a)codelutin.com>
+ */
+public class GpsConfig {
+
+ protected ApplicationConfig applicationConfig;
+
+ public GpsConfig(ApplicationConfig applicationConfig) {
+ this.applicationConfig = applicationConfig;
+ this.applicationConfig.loadDefaultOptions(GpsConfigOption.values());
+ }
+
+ /**
+ * @return {@link GpsConfigOption#GPS_HANDLER} value
+ */
+ public Class<? extends GpsHandler> getGpsHandlerClass() {
+ Class<?> result = applicationConfig.getOptionAsClass(GpsConfigOption.GPS_HANDLER.key);
+ Preconditions.checkArgument(GpsHandler.class.isAssignableFrom(result),
+ "The class " + result.getSimpleName() + " is not a GpsHandler implementation");
+ return (Class<? extends GpsHandler>) result;
+ }
+
+ /**
+ * @return {@link GpsConfigOption#GPS_CHECK_PERIOD} value
+ */
+ public int getCheckPeriod() {
+ int result = applicationConfig.getOptionAsInt(GpsConfigOption.GPS_CHECK_PERIOD.key);
+ return result;
+ }
+
+ /**
+ * @return {@link GpsConfigOption#GPS_TIMEOUT} value
+ */
+ public int getTimeout() {
+ int result = applicationConfig.getOptionAsInt(GpsConfigOption.GPS_TIMEOUT.key);
+ return result;
+ }
+
+ /**
+ * @return {@link GpsConfigOption#GPS_DEVICE} value
+ */
+ public String getDevice() {
+ String result = applicationConfig.getOption(GpsConfigOption.GPS_DEVICE.key);
+ return result;
+ }
+
+ /**
+ * @return {@link GpsConfigOption#GPS_SPEED} value
+ */
+ public int getSpeed() {
+ int result = applicationConfig.getOptionAsInt(GpsConfigOption.GPS_SPEED.key);
+ return result;
+ }
+
+ public enum GpsConfigOption implements ApplicationConfig.OptionDef {
+
+ /** Implementation class for GpsHandler */
+ GPS_HANDLER("gps.handler",
+ n_("sammoa.config.gps.handler"),
+ "fr.ulr.sammoa.application.device.gps.GpsHandlerGpsylon",
+ Class.class
+ ),
+ /** Period time in seconds for each check of the gps to update location */
+ GPS_CHECK_PERIOD("gps.check.period",
+ n_("sammoa.config.gps.check.period"),
+ "2",
+ Integer.class
+ ),
+ /** Time in seconds before timeout (NO_DATA, NO_DEVICE) */
+ GPS_TIMEOUT("gps.timeout",
+ n_("sammoa.config.gps.timeout"),
+ "10",
+ Integer.class
+ ),
+ /** GPS Device name ex: /dev/ttyUSB0 or /dev/ttyS1 or COM5 */
+ GPS_DEVICE("gps.device",
+ n_("sammoa.config.gps.device"),
+ "COM1",
+ String.class
+ ),
+ /** GPS data speed */
+ GPS_SPEED("gps.speed",
+ n_("sammoa.config.gps.speed"),
+ "4800",
+ Integer.class
+ );
+
+ /** Configuration key. */
+ private final String key;
+
+ /** I18n key of option description */
+ private final String description;
+
+ /** Type of option */
+ private final Class<?> type;
+
+ /** Default value of option. */
+ private String defaultValue;
+
+ /** Flag to not keep option value on disk */
+ private boolean isTransient;
+
+ /** Flag to not allow option value modification */
+ private boolean isFinal;
+
+ GpsConfigOption(String key,
+ String description,
+ String defaultValue,
+ Class<?> type,
+ boolean isTransient,
+ boolean isFinal) {
+ this.key = key;
+ this.description = description;
+ this.defaultValue = defaultValue;
+ this.type = type;
+ this.isTransient = isTransient;
+ this.isFinal = isFinal;
+ }
+
+ GpsConfigOption(String key,
+ String description,
+ String defaultValue,
+ Class<?> type) {
+ this(key, description, defaultValue, type, false, false);
+ }
+
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public Class<?> getType() {
+ return type;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ @Override
+ public boolean isTransient() {
+ return isTransient;
+ }
+
+ @Override
+ public boolean isFinal() {
+ return isFinal;
+ }
+
+ @Override
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ @Override
+ public void setTransient(boolean newValue) {
+ // not used
+ }
+
+ @Override
+ public void setFinal(boolean newValue) {
+ // not used
+ }
+ }
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsConfig.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandler.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,59 @@
+/*
+ * #%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.application.device.gps;
+
+import fr.ulr.sammoa.application.device.DeviceManager;
+import fr.ulr.sammoa.persistence.GeoPoint;
+
+import java.util.Set;
+
+/**
+ * Représente l'accès à un périphérique GPS.
+ */
+public interface GpsHandler extends DeviceManager {
+
+ /**
+ * Retourne la position courante du GPS.
+ *
+ * @return la position courante selon le GPS ou {@code null} si elle ne peut
+ * pas être obtenue
+ */
+ GeoPoint getCurrentLocation();
+
+ /**
+ * @param gpsLocationListener GpsLocationListener to add
+ */
+ void addGpsLocationListener(GpsLocationListener gpsLocationListener);
+
+ /**
+ * @param gpsLocationListener GpsLocationListener to remove
+ */
+ void removeGpsLocationListener(GpsLocationListener gpsLocationListener);
+
+ /**
+ * @return all GpsLocationListener
+ */
+ Set<GpsLocationListener> getGpsLocationListeners();
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandler.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandlerGpsylon.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,236 @@
+/*
+ * #%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.application.device.gps;
+
+import com.google.common.base.Objects;
+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;
+import gnu.io.CommPortIdentifier;
+import org.dinopolis.gpstool.gpsinput.GPSDataProcessor;
+import org.dinopolis.gpstool.gpsinput.GPSDevice;
+import org.dinopolis.gpstool.gpsinput.GPSException;
+import org.dinopolis.gpstool.gpsinput.GPSPosition;
+import org.dinopolis.gpstool.gpsinput.GPSSerialDevice;
+import org.dinopolis.gpstool.gpsinput.nmea.GPSNmeaDataProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * Implementation de la gestion du GPS sur GPSylon.
+ *
+ * @author echatellier
+ */
+public class GpsHandlerGpsylon extends BaseGpsHandler {
+
+ private static final Logger logger = LoggerFactory.getLogger(GpsHandlerGpsylon.class);
+
+ protected GPSDataProcessor gpsDataProcessor;
+
+ protected GPSDevice gpsDevice;
+
+ protected GPSPosition lastPosition;
+
+ protected GPSPosition lastSendPosition;
+
+ protected float lastAltitude;
+
+ protected float lastSpeed;
+
+ protected boolean deviceInitialized;
+
+ public GpsHandlerGpsylon(GpsConfig config) {
+ super(config);
+ }
+
+ @Override
+ public void open() throws DeviceTechnicalException {
+
+ if (getState() == DeviceState.READY) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("GPS already opened");
+ }
+ return;
+ }
+
+ try {
+
+ if (!deviceInitialized) {
+
+ gpsDataProcessor = new GPSNmeaDataProcessor();
+
+ gpsDevice = new SammoaGPSSerialDevice();
+
+ Hashtable<String, Object> options = new Hashtable<String, Object>();
+ options.put(GPSSerialDevice.PORT_NAME_KEY, getConfig().getDevice());
+ options.put(GPSSerialDevice.PORT_SPEED_KEY, getConfig().getSpeed());
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("GPS options: " + options);
+ }
+
+ gpsDevice.init(options);
+ gpsDataProcessor.setGPSDevice(gpsDevice);
+
+ deviceInitialized = true;
+ }
+
+ if (logger.isTraceEnabled()) {
+ Enumeration portList = CommPortIdentifier.getPortIdentifiers();
+
+ while (portList.hasMoreElements()) {
+ CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
+ if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
+ logger.trace("Available SERIAL port : " + portId.getName());
+ }
+ }
+ }
+
+ gpsDataProcessor.open();
+
+ gpsDataProcessor.addGPSDataChangeListener(
+ GPSDataProcessor.LOCATION, gpsDataProcessorListener);
+ gpsDataProcessor.addGPSDataChangeListener(
+ GPSDataProcessor.ALTITUDE, gpsDataProcessorListener);
+ gpsDataProcessor.addGPSDataChangeListener(
+ GPSDataProcessor.SPEED, gpsDataProcessorListener);
+
+ logger.info("Connected to GPS device");
+
+ setState(DeviceState.READY);
+
+ } catch (GPSException ex) {
+
+ setState(DeviceState.NO_DEVICE);
+
+ throw new DeviceTechnicalException(this, "Can't open GPS device", ex);
+ }
+ }
+
+ @Override
+ public void close() {
+
+ stop();
+
+ if (gpsDataProcessor != null && getState() != DeviceState.NO_DEVICE) {
+
+ logger.info("Closing GPS device...");
+ try {
+
+ gpsDataProcessor.removeGPSDataChangeListener(
+ GPSDataProcessor.LOCATION, gpsDataProcessorListener);
+ gpsDataProcessor.removeGPSDataChangeListener(
+ GPSDataProcessor.ALTITUDE, gpsDataProcessorListener);
+ gpsDataProcessor.removeGPSDataChangeListener(
+ GPSDataProcessor.SPEED, gpsDataProcessorListener);
+
+ gpsDataProcessor.close();
+
+ logger.info("GPS device is closed");
+
+ setState(DeviceState.NO_DEVICE);
+
+ } catch (GPSException e) {
+ throw new DeviceTechnicalException(this, "Can't close GPS device", e);
+ }
+ }
+ }
+
+ @Override
+ public GeoPoint getCurrentLocation() {
+
+ GeoPoint result = null;
+
+ 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;
+ }
+ return result;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ close();
+ super.finalize();
+ }
+
+ /**
+ * 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
+ * {@code GPSDataChangeListener}.
+ *
+ * Properties available:
+ * <ul>
+ * <li>LOCATION: the value is a GPSPosition object
+ * <li>HEADING: the value is a Float
+ * <li>SPEED: the value is a Float and is in kilometers per hour
+ * <li>NUMBER_SATELLITES: the value is a Integer
+ * <li>ALTITUDE: the value is a Float and is in meters
+ * <li>SATELLITE_INFO: the value is a SatelliteInfo object.
+ * <li>DEPTH: the value is a Float and is in meters.
+ * <li>EPE: estimated position error, the value is a GPSPositionError object.
+ * <li>IDS_SATELLITES: An array of Integers holding the number of visible satellites.
+ * <li>PDOP: a Float indicating the quality of the gps signal.
+ * <li>HDOP: a Float indicating the quality of the gps signal in horizontal direction.
+ * <li>VDOP: a Float indicating the quality of the gps signal in vertical direction.
+ * </ul>
+ */
+ protected PropertyChangeListener gpsDataProcessorListener = new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+
+ String property = evt.getPropertyName();
+
+ logger.trace("Gps data received {} {}", property, evt.getNewValue());
+
+ if (GPSDataProcessor.LOCATION.equals(property)) {
+ lastPosition = (GPSPosition) evt.getNewValue();
+
+ } else if (GPSDataProcessor.ALTITUDE.equals(property)) {
+ lastAltitude = (Float) evt.getNewValue();
+
+ } else if (GPSDataProcessor.SPEED.equals(property)) {
+ lastSpeed = (Float) evt.getNewValue();
+ }
+ }
+ };
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,58 @@
+package fr.ulr.sammoa.application.device.gps;
+/*
+ * #%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;
+
+/**
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public class GpsLocationEvent {
+
+ protected GpsHandler source;
+
+ protected GeoPoint oldValue;
+
+ protected GeoPoint newValue;
+
+ public GpsLocationEvent(GpsHandler source, GeoPoint oldValue, GeoPoint newValue) {
+ this.source = source;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ public GpsHandler getSource() {
+ return source;
+ }
+
+ public GeoPoint getOldValue() {
+ return oldValue;
+ }
+
+ public GeoPoint getNewValue() {
+ return newValue;
+ }
+}
\ No newline at end of file
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationEvent.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsUpdateListener.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,38 @@
+/*
+ * #%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.application.device.gps;
+
+/**
+ * DP Observateur.
+ */
+public interface GpsLocationListener {
+
+ /**
+ * Update GPS location.
+ *
+ * @param event new event
+ */
+ void locationChanged(GpsLocationEvent event);
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsLocationListener.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java (from rev 359, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/SammoaGPSSerialDevice.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -0,0 +1,67 @@
+package fr.ulr.sammoa.application.device.gps;
+/*
+ * #%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 gnu.io.RXTXHack;
+import gnu.io.RXTXPort;
+import org.dinopolis.gpstool.gpsinput.GPSException;
+import org.dinopolis.gpstool.gpsinput.GPSSerialDevice;
+
+/**
+ * There is an issue with closing on {@link gnu.io.SerialPort}. See
+ * <a href="https://forums.oracle.com/forums/thread.jspa?threadID=1292323">
+ * https://forums.oracle.com/forums/thread.jspa?threadID=1292323
+ * </a>
+ *
+ * Note that only the {@link RXTXHack} works... Maybe the upgrade of rxtx.jar could
+ * works (not in maven repo).
+ * <p/>
+ * The issue is probably from {@link org.dinopolis.gpstool.gpsinput.nmea.GPSNmeaDataProcessor}
+ * that creates a daemon thread to read the serialPort InputStream. There is
+ * no way to kill properly this thread before closing serialPort.
+ *
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public class SammoaGPSSerialDevice extends GPSSerialDevice {
+
+ @Override
+ public void close() throws GPSException {
+ if (serial_port_ != null) {
+
+// serial_port_.removeEventListener();
+// try {
+// serial_port_.getOutputStream().flush();
+// serial_port_.getOutputStream().close();
+// serial_port_.getInputStream().close();
+// } catch (IOException e) {
+// throw Throwables.propagate(e);
+// }
+// serial_port_.close();
+
+ RXTXHack.closeRxtxPort((RXTXPort) serial_port_);
+ }
+ }
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/SammoaGPSSerialDevice.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java
===================================================================
--- trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -27,7 +27,7 @@
* Created: 06/08/12
*
* @author fdesbois <florian.desbois(a)codelutin.com>
- * @see fr.ulr.sammoa.application.gps.SammoaGPSSerialDevice for usage
+ * @see fr.ulr.sammoa.application.device.gps.SammoaGPSSerialDevice for usage
*/
public final class RXTXHack {
Modified: trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties
===================================================================
--- trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties 2012-08-07 15:48:54 UTC (rev 360)
@@ -10,7 +10,7 @@
sammoa.config.fly.mode=
sammoa.config.gps.check.period=Time in seconds between each GPS capture
sammoa.config.gps.device=GPS device port
-sammoa.config.gps.handler=GpsHandler class \: fr.ulr.sammoa.application.gps.GpsHandlerGpylon or fr.ulr.sammoa.application.gps.FakeGpsHandler
+sammoa.config.gps.handler=GpsHandler class \: fr.ulr.sammoa.application.device.gps.GpsHandlerGpylon or fr.ulr.sammoa.application.device.gps.FakeGpsHandler
sammoa.config.gps.speed=GPS speed for capture
sammoa.config.gps.timeout=Time in seconds before GPS going to timeout (always the same data is received for this laps of time) and return error
sammoa.config.log.file=Path for application log file
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -24,11 +24,11 @@
*/
package fr.ulr.sammoa.ui.swing;
-import fr.ulr.sammoa.application.DeviceTechnicalException;
import fr.ulr.sammoa.application.FlightState;
import fr.ulr.sammoa.application.SammoaConfig;
import fr.ulr.sammoa.application.SammoaContext;
-import fr.ulr.sammoa.application.gps.GpsConfig;
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+import fr.ulr.sammoa.application.device.gps.GpsConfig;
import fr.ulr.sammoa.persistence.Campaign;
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.ui.swing.campaign.CampaignUI;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -24,11 +24,9 @@
*/
package fr.ulr.sammoa.ui.swing.flight;
-import fr.ulr.sammoa.application.DeviceState;
-import fr.ulr.sammoa.application.DeviceUpdateEvent;
-import fr.ulr.sammoa.application.DeviceUpdateListener;
-import fr.ulr.sammoa.application.gps.GpsUpdateListener;
-import fr.ulr.sammoa.persistence.GeoPoint;
+import fr.ulr.sammoa.application.device.DeviceState;
+import fr.ulr.sammoa.application.device.DeviceStateEvent;
+import fr.ulr.sammoa.application.device.DeviceStateListener;
import org.nuiton.util.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,7 +47,7 @@
*
* @author chatellier
*/
-public class DeviceStateLED extends JLabel implements DeviceUpdateListener, GpsUpdateListener {
+public class DeviceStateLED extends JLabel implements DeviceStateListener {
/** serialVersionUID. */
private static final long serialVersionUID = 1L;
@@ -59,7 +57,7 @@
protected DeviceState state;
public DeviceStateLED() {
-// onStateChanged(DeviceState.NO_DEVICE);
+// stateChanged(DeviceState.NO_DEVICE);
}
protected static final ImageIcon NO_DEVICE_ICON = Resource.getIcon("/icons/device/nodevice.png");
@@ -68,7 +66,7 @@
protected static final ImageIcon NO_DATA_ICON = Resource.getIcon("/icons/device/nodata.gif");
@Override
- public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
+ public void stateChanged(DeviceStateEvent event) {
DeviceState oldValue = getState();
this.state = event.getNewValue();
@@ -97,9 +95,4 @@
public DeviceState getState() {
return state;
}
-
- @Override
- public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
- // nothing to do
- }
}
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 07:52:19 UTC (rev 359)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -53,9 +53,9 @@
public void init() {
getFlightUIModel().addPropertyChangeListener(this);
- getFlightController().getAudioRecorder().addUpdateListener(view.getAudioLED());
- getFlightController().getGpsHandler().addUpdateListener(view.getGpsLED());
- getFlightController().getGpsHandler().addUpdateListener(getModel());
+ getFlightController().getAudioRecorder().addDeviceStateListener(view.getAudioLED());
+ getFlightController().getGpsHandler().addDeviceStateListener(view.getGpsLED());
+ getFlightController().getGpsHandler().addGpsLocationListener(getModel());
}
@Override
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -24,9 +24,8 @@
*/
package fr.ulr.sammoa.ui.swing.flight;
-import fr.ulr.sammoa.application.DeviceState;
-import fr.ulr.sammoa.application.DeviceUpdateEvent;
-import fr.ulr.sammoa.application.gps.GpsUpdateListener;
+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.ui.swing.BaseModel;
@@ -37,7 +36,7 @@
/**
* @author sletellier <letellier(a)codelutin.com>
*/
-public class FlightBarModel extends BaseModel implements GpsUpdateListener {
+public class FlightBarModel extends BaseModel implements GpsLocationListener {
private static final long serialVersionUID = 1L;
@@ -82,16 +81,11 @@
}
@Override
- public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ public void locationChanged(GpsLocationEvent event) {
GeoPoint newLocation = event.getNewValue();
if (newLocation != null) {
setSpeed((float) newLocation.getSpeed());
setAlt((float) newLocation.getAltitude());
}
}
-
- @Override
- public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
- // nothing to do
- }
}
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 07:52:19 UTC (rev 359)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -46,9 +46,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
-import fr.ulr.sammoa.application.DeviceState;
-import fr.ulr.sammoa.application.DeviceTechnicalException;
-import fr.ulr.sammoa.application.DeviceUpdateEvent;
import fr.ulr.sammoa.application.FlightController;
import fr.ulr.sammoa.application.FlightControllerDefault;
import fr.ulr.sammoa.application.FlightControllerUpdateListener;
@@ -57,7 +54,9 @@
import fr.ulr.sammoa.application.ReferentialService;
import fr.ulr.sammoa.application.SammoaConfig;
import fr.ulr.sammoa.application.SammoaContext;
-import fr.ulr.sammoa.application.gps.GpsUpdateListener;
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+import fr.ulr.sammoa.application.device.gps.GpsLocationEvent;
+import fr.ulr.sammoa.application.device.gps.GpsLocationListener;
import fr.ulr.sammoa.persistence.Campaign;
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.persistence.GeoPoint;
@@ -381,11 +380,11 @@
initMapHandler();
- getFlightController().getGpsHandler().addUpdateListener(
- new GpsUpdateListener() {
+ getFlightController().getGpsHandler().addGpsLocationListener(
+ new GpsLocationListener() {
@Override
- public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ public void locationChanged(GpsLocationEvent event) {
GeoPoint newLocation = event.getNewValue();
if (newLocation != null && getModel().isMapFollow()) {
MapBean mapBean = getOverlayMapPanel().getMapBean();
@@ -393,11 +392,6 @@
newLocation.getLongitude()));
}
}
-
- @Override
- public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
- // nothing to do
- }
});
timeLog.log(startTime, "afterInitUI", "map is initialized");
@@ -749,7 +743,7 @@
// Ajout d'un layer pour représenter les points relevés par le GPS
GpsTracingLayer gpsTracingLayer = new GpsTracingLayer();
- getFlightController().getGpsHandler().addUpdateListener(gpsTracingLayer);
+ getFlightController().getGpsHandler().addGpsLocationListener(gpsTracingLayer);
mapHandler.add(gpsTracingLayer);
InformationDelegator informationDelegator = new InformationDelegator();
Modified: 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 07:52:19 UTC (rev 359)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -29,9 +29,8 @@
import com.bbn.openmap.omGraphics.OMGraphicConstants;
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.omGraphics.OMLine;
-import fr.ulr.sammoa.application.DeviceState;
-import fr.ulr.sammoa.application.DeviceUpdateEvent;
-import fr.ulr.sammoa.application.gps.GpsUpdateListener;
+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;
@@ -39,7 +38,7 @@
/**
* Un layer OpenMap qui affiche les points envoyés par le GPS.
*/
-public class GpsTracingLayer extends OMGraphicHandlerLayer implements GpsUpdateListener {
+public class GpsTracingLayer extends OMGraphicHandlerLayer implements GpsLocationListener {
// private static final Logger logger = LoggerFactory.getLogger(GpsTracingLayer.class);
@@ -52,7 +51,7 @@
}
@Override
- public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ public void locationChanged(GpsLocationEvent event) {
// OMGraphic point = new OMPoint(newLocation.getLatitude(), newLocation.getLongitude());
GeoPoint newLocation = event.getNewValue();
@@ -88,9 +87,4 @@
currentLocation = new GeoPointImpl(newLocation.getLatitude(), newLocation.getLongitude());
}
}
-
- @Override
- public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
- // nothing to do
- }
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -23,13 +23,11 @@
* #L%
*/
-import fr.ulr.sammoa.application.DeviceState;
-import fr.ulr.sammoa.application.DeviceUpdateEvent;
-import fr.ulr.sammoa.application.DeviceUpdateListener;
import fr.ulr.sammoa.application.FlightController;
import fr.ulr.sammoa.application.FlightService;
-import fr.ulr.sammoa.application.gps.GpsUpdateListener;
-import fr.ulr.sammoa.persistence.GeoPoint;
+import fr.ulr.sammoa.application.device.DeviceState;
+import fr.ulr.sammoa.application.device.DeviceStateEvent;
+import fr.ulr.sammoa.application.device.DeviceStateListener;
import fr.ulr.sammoa.persistence.Observation;
import fr.ulr.sammoa.persistence.ObservationStatus;
import fr.ulr.sammoa.persistence.Observations;
@@ -97,7 +95,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.4
*/
-public class EffortPanelHandler implements DeviceUpdateListener, GpsUpdateListener {
+public class EffortPanelHandler implements DeviceStateListener {
private static final Logger logger =
LoggerFactory.getLogger(EffortPanelHandler.class);
@@ -275,8 +273,8 @@
SammoaUIContext.getUIContext().getFlightUIHandler().getFlightController();
if (flightController != null) {
- flightController.getGpsHandler().addUpdateListener(this);
- flightController.getAudioRecorder().addUpdateListener(this);
+ flightController.getGpsHandler().addDeviceStateListener(this);
+ flightController.getAudioRecorder().addDeviceStateListener(this);
}
@@ -552,7 +550,7 @@
}
@Override
- public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
+ public void stateChanged(DeviceStateEvent event) {
DeviceState state = event.getNewValue();
if (DeviceState.NO_DATA == state) {
ui.getObservationTable().setBackground(DEVICE_ERROR_BACKGROUND_COLOR);
@@ -562,11 +560,6 @@
}
}
- @Override
- public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
- // nothing to do
- }
-
public DecoratorProvider getDecoratorProvider() {
return SammoaUIContext.getUIContext().getDecoratorProvider();
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-08-07 07:52:19 UTC (rev 359)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-08-07 15:48:54 UTC (rev 360)
@@ -26,7 +26,7 @@
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
-import fr.ulr.sammoa.application.DeviceTechnicalException;
+import fr.ulr.sammoa.application.device.DeviceTechnicalException;
import jaxx.runtime.JAXXUtil;
import jaxx.runtime.SwingUtil;
import org.apache.commons.beanutils.NestedNullException;
@@ -38,10 +38,7 @@
import org.slf4j.LoggerFactory;
import javax.swing.*;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Cursor;
-import java.awt.Dimension;
+import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
1
0
Author: tchemit
Date: 2012-08-07 09:52:19 +0200 (Tue, 07 Aug 2012)
New Revision: 359
Url: http://forge.codelutin.com/repositories/revision/sammoa/359
Log:
updates to mavenpom 3.3.5
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-06 15:19:20 UTC (rev 358)
+++ trunk/pom.xml 2012-08-07 07:52:19 UTC (rev 359)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.3.5-SNAPSHOT</version>
+ <version>3.3.5</version>
</parent>
<groupId>fr.ulr</groupId>
1
0
Author: tchemit
Date: 2012-08-06 17:19:20 +0200 (Mon, 06 Aug 2012)
New Revision: 358
Url: http://forge.codelutin.com/repositories/revision/sammoa/358
Log:
back to hibernate 3.6.10 3.6.11 still does not exist...(
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-06 14:33:43 UTC (rev 357)
+++ trunk/pom.xml 2012-08-06 15:19:20 UTC (rev 358)
@@ -117,7 +117,7 @@
<topiaVersion>2.6.11</topiaVersion>
<!--<hibernateVersion>4.1.3.Final</hibernateVersion>-->
<!--<geronimoJpaSpecVersion>1.1</geronimoJpaSpecVersion>-->
- <hibernateVersion>3.6.11.Final</hibernateVersion>
+ <hibernateVersion>3.6.10.Final</hibernateVersion>
<h2Version>1.3.168</h2Version>
<postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion>
1
0
06 Aug '12
Author: fdesbois
Date: 2012-08-06 16:33:43 +0200 (Mon, 06 Aug 2012)
New Revision: 357
Url: http://forge.codelutin.com/repositories/revision/sammoa/357
Log:
refs #1378 : Improve Device management for GPS and Audio, use proper API and errors
Added:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/SammoaGPSSerialDevice.java
trunk/sammoa-application/src/main/java/gnu/
trunk/sammoa-application/src/main/java/gnu/io/
trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java
Removed:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioUpdateListener.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/AudioStateLED.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/GpsStateLED.java
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaContext.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorder.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderDefault.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderMock.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/BaseGpsHandler.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/FakeGpsHandler.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandler.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandlerGpsylon.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsUpdateListener.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx
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/FlightBarModel.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/layer/GpsTracingLayer.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java
Added: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -0,0 +1,80 @@
+package fr.ulr.sammoa.application;
+/*
+ * #%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 java.util.Set;
+
+/**
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public interface DeviceManager<L extends DeviceUpdateListener> {
+
+ /**
+ * Open the device
+ *
+ * @throws DeviceTechnicalException for errors on open
+ */
+ void open() throws DeviceTechnicalException;
+
+ /**
+ * Start the device session (recording, reading, ...) and try opening it if necessary. The open
+ * could be tried several times to permit a proper start.
+ */
+ void start();
+
+ /**
+ * Stop the device session
+ */
+ void stop();
+
+ /**
+ * Close the device and stop it if necessary
+ *
+ * @throws DeviceTechnicalException for errors on close
+ */
+ void close() throws DeviceTechnicalException;
+
+ /**
+ * @return the DeviceState
+ */
+ DeviceState getState();
+
+ /**
+ * @param listener DeviceUpdateListener to add
+ */
+ void addUpdateListener(L listener);
+
+ /**
+ * @param listener DeviceUpdateListener to remove
+ */
+ void removeUpdateListener(L listener);
+
+ /**
+ * @return all the listeners
+ */
+ Set<L> getUpdateListeners();
+
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceManager.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java (from rev 356, trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/AudioStateLED.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -0,0 +1,49 @@
+/*
+ * #%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.application;
+
+/**
+ * @author fdesbois <fdesbois(a)codelutin.com>
+ */
+public class DeviceTechnicalException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ protected DeviceManager source;
+
+ public DeviceTechnicalException(DeviceManager source, String message) {
+ super(message);
+ this.source = source;
+ }
+
+ public DeviceTechnicalException(DeviceManager source, String message, Throwable cause) {
+ super(message, cause);
+ this.source = source;
+ }
+
+ public DeviceManager getSource() {
+ return source;
+ }
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceTechnicalException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java (from rev 356, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioUpdateListener.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateEvent.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -0,0 +1,56 @@
+package fr.ulr.sammoa.application;
+/*
+ * #%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%
+ */
+
+/**
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public class DeviceUpdateEvent<T> {
+
+ protected DeviceManager source;
+
+ protected T oldValue;
+
+ protected T newValue;
+
+ public DeviceUpdateEvent(DeviceManager source, T oldValue, T newValue) {
+ this.source = source;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ public DeviceManager getSource() {
+ return source;
+ }
+
+ public T getOldValue() {
+ return oldValue;
+ }
+
+ public T getNewValue() {
+ return newValue;
+ }
+}
\ No newline at end of file
Copied: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java (from rev 356, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioUpdateListener.java)
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DeviceUpdateListener.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -0,0 +1,39 @@
+package fr.ulr.sammoa.application;
+/*
+ * #%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%
+ */
+
+/**
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public interface DeviceUpdateListener {
+
+ /**
+ * Update device state.
+ *
+ * @param event new event
+ */
+ void onStateChanged(DeviceUpdateEvent<DeviceState> event);
+}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightController.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -66,10 +66,16 @@
/**
* @param config GpsConfig to initialize the Gps
+ * @exception DeviceTechnicalException if the gps device can't be opened properly
*/
- void initGpsHandler(GpsConfig config);
+ void openGpsDevice(GpsConfig config) throws DeviceTechnicalException;
/**
+ * @exception DeviceTechnicalException if the audio device can't be opened properly
+ */
+ void openAudioDevice() throws DeviceTechnicalException;
+
+ /**
* @return The current {@link Route}
*/
Route getCurrentRoute();
@@ -80,6 +86,15 @@
TransectFlight getNextTransect();
/**
+ * Initialize all data of FlightController depends on the current flight state.
+ * If the flight is running ({@link #isRunning()}), the devices will be started and
+ * recording if necessary.
+ * <p/>
+ * You must call init method to ensure the {@link FlightState}.
+ */
+ void init();
+
+ /**
* Start operation. This will set the {@code beginDate} of the flight, then
* a new {@link RouteType#TRANSIT} route is created. The state is now
* {@link FlightState#OFF_EFFORT}.
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightControllerDefault.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -25,9 +25,11 @@
package fr.ulr.sammoa.application;
import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.Sets;
import fr.ulr.sammoa.application.audio.AudioRecorder;
+import fr.ulr.sammoa.application.audio.AudioRecorderDefault;
import fr.ulr.sammoa.application.gps.GpsConfig;
import fr.ulr.sammoa.application.gps.GpsHandler;
import fr.ulr.sammoa.application.gps.GpsUpdateListener;
@@ -66,7 +68,7 @@
*/
public class FlightControllerDefault implements GpsUpdateListener, FlightController {
- private static final Logger logger = LoggerFactory.getLogger(FlightService.class);
+ private static final Logger logger = LoggerFactory.getLogger(FlightControllerDefault.class);
private static final TimeLog timeLog = new TimeLog(FlightControllerDefault.class, 500, 1000);
@@ -80,6 +82,8 @@
protected GpsHandler gpsHandler;
+ protected boolean initialized;
+
protected FlightState state;
protected Flight flight;
@@ -98,19 +102,12 @@
this.context = context;
this.flight = flight;
- GpsConfig gpsConfig = context.getConfig().getGpsConfig();
- initGpsHandler(gpsConfig);
-
- this.audioRecorder = context.getAudioRecorder();
-
this.persistence = context.getPersistence();
this.service = context.getFlightService();
this.currentRoute = service.getLastRoute(flight);
this.lastTransect = service.getLastTransectDone(flight);
this.listeners = Sets.newHashSet();
-
- init();
}
@Override
@@ -149,49 +146,59 @@
}
@Override
- public void initGpsHandler(GpsConfig config) {
+ public void openGpsDevice(final GpsConfig config) throws DeviceTechnicalException {
- Set<GpsUpdateListener> updateListeners;
- if (gpsHandler != null) {
+ gpsHandler = newDeviceManager(gpsHandler, new Supplier<GpsHandler>() {
- // Remove all existing listeners and keep them for the new instance
- updateListeners = Sets.newHashSet(gpsHandler.getGpsUpdateListeners());
- for (GpsUpdateListener listener : updateListeners) {
- gpsHandler.removeGpsUpdateListener(listener);
+ @Override
+ public GpsHandler get() {
+
+ // Instanciate the GpsHandler
+ Class<? extends GpsHandler> gpsHandlerClass = config.getGpsHandlerClass();
+ try {
+
+ Constructor<? extends GpsHandler> constructor =
+ gpsHandlerClass.getConstructor(GpsConfig.class);
+
+ GpsHandler result = constructor.newInstance(config);
+ result.addUpdateListener(FlightControllerDefault.this);
+ return result;
+
+ } catch (InstantiationException e) {
+ throw Throwables.propagate(e);
+ } catch (IllegalAccessException e) {
+ throw Throwables.propagate(e);
+ } catch (NoSuchMethodException e) {
+ throw Throwables.propagate(e);
+ } catch (InvocationTargetException e) {
+ throw Throwables.propagate(e);
+ }
}
+ });
+ if (initialized && isRunning()) {
+ gpsHandler.start();
} else {
- updateListeners = Sets.<GpsUpdateListener>newHashSet(this);
+ gpsHandler.open();
}
+ }
- // Instanciate the GpsHandler
- Class<? extends GpsHandler> gpsHandlerClass = config.getGpsHandlerClass();
- try {
+ @Override
+ public void openAudioDevice() throws DeviceTechnicalException {
- Constructor<? extends GpsHandler> constructor =
- gpsHandlerClass.getConstructor(GpsConfig.class);
+ audioRecorder = newDeviceManager(audioRecorder, new Supplier<AudioRecorder>() {
- gpsHandler = constructor.newInstance(config);
+ @Override
+ public AudioRecorder get() {
+ return new AudioRecorderDefault();
+ }
+ });
- } catch (InstantiationException e) {
- throw Throwables.propagate(e);
- } catch (IllegalAccessException e) {
- throw Throwables.propagate(e);
- } catch (NoSuchMethodException e) {
- throw Throwables.propagate(e);
- } catch (InvocationTargetException e) {
- throw Throwables.propagate(e);
+ if (initialized && isRunning()) {
+ audioRecorder.start();
+ } else {
+ audioRecorder.open();
}
-
- // Attach all updateListener
- for (GpsUpdateListener listener : updateListeners) {
- gpsHandler.addGpsUpdateListener(listener);
- }
-
- // Start the GpsHandler if Flight is running
- if (isRunning()) {
- gpsHandler.start();
- }
}
@Override
@@ -220,22 +227,89 @@
}
@Override
+ public void init() {
+
+ Preconditions.checkState(gpsHandler != null,
+ "The GpsHandler must be created using #openGpsDevice");
+
+ Preconditions.checkState(audioRecorder != null,
+ "The AudioRecorder must be created using #openAudioDevice");
+
+ if (initialized) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("The FlightController is already initialized");
+ }
+ return;
+ }
+
+ if (logger.isInfoEnabled()) {
+ logger.info("Initialize the FlightController for flight " + flight.getFlightNumber());
+ }
+
+ initialized = true;
+
+ // Note that a flight can't finished by a leg, so effort not null
+ // implies that the flight is started and not ended
+ if (currentRoute != null
+ && currentRoute.getRouteType() == RouteType.LEG) {
+
+ state = FlightState.ON_EFFORT;
+
+ } else if (currentRoute != null
+ && flight.getBeginDate() != null
+ && flight.getEndDate() == null) {
+
+ state = FlightState.OFF_EFFORT;
+
+ } else if (flight.getEndDate() != null) {
+
+ state = FlightState.ENDED;
+
+ } else {
+ state = FlightState.WAITING;
+ }
+
+ if (isRunning()) {
+
+ gpsHandler.start();
+
+ audioRecorder.start();
+
+ // Selection of the nextTransect, keep the last one for circleBack
+ if (currentRoute.getRouteType() == RouteType.CIRCLE_BACK) {
+ nextTransect = lastTransect;
+
+ } else {
+ nextTransect = flight.getNextTransectFlightFrom(lastTransect);
+ }
+
+ // Restart recording audio if onEffort or circleBack
+ if (state == FlightState.ON_EFFORT
+ || currentRoute.getRouteType() == RouteType.CIRCLE_BACK) {
+
+ saveAudio(0);
+ }
+ }
+ }
+
+ @Override
public void start() {
long startTime = TimeLog.getTime();
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
Preconditions.checkState(
isWaiting(), "You can call start() only if flight is waiting (not started, not ended)");
- // Start gps
- getGpsHandler().start();
+ gpsHandler.start();
- // Start audio
- getAudioRecorder().start();
+ audioRecorder.start();
TopiaContext transaction = persistence.beginTransaction();
try {
-
+
Date currentDate = saveGPS(transaction, gpsHandler.getCurrentLocation(), flight);
setFlightBeginDate(transaction, flight, currentDate);
@@ -265,10 +339,10 @@
fireStateChanged(state);
timeLog.log(startTime, "start()", "Fired");
-
+
} catch (TopiaException e) {
throw new TopiaRuntimeException(e);
-
+
} finally {
persistence.endTransaction(transaction);
}
@@ -279,6 +353,9 @@
long startTime = TimeLog.getTime();
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
Preconditions.checkState(
nextTransect == null || !nextTransect.isDeleted(), "You can't use a deleted transect as next value");
@@ -295,6 +372,9 @@
long startTime = TimeLog.getTime();
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
Preconditions.checkState(
isOffEffort(), "You can call begin() only if flight is running (started, not ended, not on effort)");
@@ -348,6 +428,9 @@
long startTime = TimeLog.getTime();
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
Preconditions.checkState(
currentRoute != null
&& currentRoute.getRouteType() != RouteType.TRANSIT,
@@ -399,6 +482,9 @@
long startTime = TimeLog.getTime();
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
Preconditions.checkState(
isOnEffort(), "You can call add() only if flight is on effort (started, not ended, on effort)");
@@ -451,6 +537,9 @@
long startTime = TimeLog.getTime();
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
Preconditions.checkState(
isRunning(), "You can call observation() only if flight is running (started, not ended)");
@@ -513,6 +602,9 @@
long startTime = TimeLog.getTime();
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
Preconditions.checkState(
isOffEffort(), "You can call stop() only if flight is running (started, not ended, not on effort)");
@@ -561,13 +653,21 @@
@Override
public void close() {
- getAudioRecorder().stop();
- getGpsHandler().stop();
+
+ audioRecorder.close();
+ audioRecorder = null;
+
+ gpsHandler.close();
+ gpsHandler = null;
+
persistence.stopAutoSaveListener();
}
protected void doEndWithAudioDelay(long audioDelay) {
+ Preconditions.checkState(initialized,
+ "The controller must be initialized before calling any action");
+
Preconditions.checkState(
isOnEffort(), "You can call end() only if flight is on effort (started, not ended, on effort)");
@@ -600,54 +700,6 @@
}
}
- protected void init() {
-
- // Note that a flight can't finished by a leg, so effort not null
- // implies that the flight is started and not ended
- if (currentRoute != null
- && currentRoute.getRouteType() == RouteType.LEG) {
-
- state = FlightState.ON_EFFORT;
-
- } else if (currentRoute != null
- && flight.getBeginDate() != null
- && flight.getEndDate() == null) {
-
- state = FlightState.OFF_EFFORT;
-
- } else if (flight.getEndDate() != null) {
-
- state = FlightState.ENDED;
-
- } else {
- state = FlightState.WAITING;
- }
-
- if (isRunning()) {
-
- // Start gps
- getGpsHandler().start();
-
- // Start audio
- getAudioRecorder().start();
-
- // Selection of the nextTransect, keep the last one for circleBack
- if (currentRoute.getRouteType() == RouteType.CIRCLE_BACK) {
- nextTransect = lastTransect;
-
- } else {
- nextTransect = flight.getNextTransectFlightFrom(lastTransect);
- }
-
- // Restart recording audio if onEffort or circleBack
- if (state == FlightState.ON_EFFORT
- || currentRoute.getRouteType() == RouteType.CIRCLE_BACK) {
-
- saveAudio(0);
- }
- }
- }
-
// protected void setNextTransect(TransectFlight nextTransect, boolean fireEvents) {
//
// this.nextTransect = nextTransect;
@@ -766,8 +818,37 @@
}
}
+ protected <T extends DeviceManager> T newDeviceManager(T oldInstance, Supplier<T> supplier)
+ throws DeviceTechnicalException {
+
+ Set<DeviceUpdateListener> updateListeners;
+ if (oldInstance != null) {
+
+ // Remove all existing listeners and keep them for the new instance
+ updateListeners = Sets.newHashSet(oldInstance.getUpdateListeners());
+ for (DeviceUpdateListener listener : updateListeners) {
+ oldInstance.removeUpdateListener(listener);
+ }
+
+ oldInstance.close();
+
+ } else {
+ updateListeners = Sets.newHashSet();
+ }
+
+ T result = supplier.get();
+
+ // Attach all updateListener
+ for (DeviceUpdateListener listener : updateListeners) {
+ result.addUpdateListener(listener);
+ }
+
+ return result;
+ }
+
@Override
- public void onLocationReceived(GeoPoint newLocation) {
+ public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ GeoPoint newLocation = event.getNewValue();
if (newLocation != null/* && newLocation.getTopiaId() == null*/) {
newLocation.setFlight(flight);
persistence.delayEntityCreation(newLocation);
@@ -775,7 +856,8 @@
}
@Override
- public void onStateChanged(DeviceState state) {
+ public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
+ // nothing to do
}
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaContext.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaContext.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaContext.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -24,8 +24,6 @@
*/
package fr.ulr.sammoa.application;
-import fr.ulr.sammoa.application.audio.AudioRecorder;
-import fr.ulr.sammoa.application.audio.AudioRecorderDefault;
import fr.ulr.sammoa.application.map.ExportMapService;
import fr.ulr.sammoa.persistence.SammoaPersistence;
@@ -48,8 +46,6 @@
protected ExportMapService exportMapService;
- protected AudioRecorder audioRecorder;
-
public SammoaContext(SammoaConfig config) {
this(config, new SammoaPersistence(
config.getApplicationConfig().getFlatOptions(),
@@ -70,13 +66,6 @@
return persistence;
}
- public AudioRecorder getAudioRecorder() {
- if (audioRecorder == null) {
- audioRecorder = new AudioRecorderDefault();
- }
- return audioRecorder;
- }
-
public FlightService getFlightService() {
if (flightService == null) {
flightService = new FlightService(this);
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorder.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorder.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorder.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -23,7 +23,8 @@
* #L%
*/
-import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceManager;
+import fr.ulr.sammoa.application.DeviceUpdateListener;
import javax.sound.sampled.AudioFileFormat;
import java.io.File;
@@ -37,25 +38,14 @@
*
* @author fdesbois <desbois(a)codelutin.com>
*/
-public interface AudioRecorder {
+public interface AudioRecorder extends DeviceManager<DeviceUpdateListener> {
/**
- * @return current {@link DeviceState}
- */
- DeviceState getState();
-
- /**
* @return the {@link AudioFileFormat.Type} used (default is WAV)
*/
AudioFileFormat.Type getOutputType();
/**
- * Start the recorder. This will open the audio line. No recorders are
- * running yet.
- */
- void start();
-
- /**
* Record the audio line and save the data in given {@code outputFile}. The
* previous recording will be stopped in {@code delaySeconds}. The delay is
* useful to avoid recording lost or too quick between two files.
@@ -72,19 +62,4 @@
* @param delaySeconds Delay for current recording
*/
void stopRecord(long delaySeconds);
-
- /**
- * Stop the recorder. This will flush data in recorders and close the line.
- */
- void stop();
-
- /**
- * @param listener AudioUpdateListener to add
- */
- void addAudioUpdateListener(AudioUpdateListener listener);
-
- /**
- * @param listener AudioUpdateListener to remove
- */
- void removeAudioUpdateListener(AudioUpdateListener listener);
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderDefault.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderDefault.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderDefault.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -29,13 +29,32 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceTechnicalException;
+import fr.ulr.sammoa.application.DeviceUpdateEvent;
+import fr.ulr.sammoa.application.DeviceUpdateListener;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.sound.sampled.*;
-import java.io.*;
-import java.util.*;
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.TargetDataLine;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
/**
* Created: 16/05/12
@@ -81,7 +100,7 @@
protected DeviceState state;
- protected Set<AudioUpdateListener> listeners;
+ protected Set<DeviceUpdateListener> listeners;
public AudioRecorderDefault() {
this(new AudioFormat(
@@ -111,11 +130,12 @@
}
protected void setState(DeviceState state) {
+ DeviceState oldValue = getState();
this.state = state;
// Fire on listeners
- for (AudioUpdateListener listener : listeners) {
- listener.onStateChanged(state);
+ for (DeviceUpdateListener listener : listeners) {
+ listener.onStateChanged(new DeviceUpdateEvent<DeviceState>(this, oldValue, state));
}
}
@@ -125,22 +145,26 @@
}
@Override
- public void addAudioUpdateListener(AudioUpdateListener listener) {
+ public void addUpdateListener(DeviceUpdateListener listener) {
listeners.add(listener);
}
@Override
- public void removeAudioUpdateListener(AudioUpdateListener listener) {
+ public void removeUpdateListener(DeviceUpdateListener listener) {
listeners.remove(listener);
}
@Override
- public void start() {
+ public Set<DeviceUpdateListener> getUpdateListeners() {
+ return listeners;
+ }
- // Stop previous recording
- stop();
+ @Override
+ public void open() throws DeviceTechnicalException {
- logger.info("Open the audio line");
+ if (logger.isInfoEnabled()) {
+ logger.info("Open the audio line");
+ }
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
try {
@@ -150,24 +174,55 @@
// Start using the line for recording
dataLine.start();
- lineReader = new DataLineReader();
- lineReader.start();
-
setState(DeviceState.READY);
- } catch (Exception e) {
- logger.error("Can't start recording", e);
- setState(DeviceState.NO_DATA);
+ if (logger.isInfoEnabled()) {
+ logger.info("Audio line is ready");
+ }
+
+ } catch (IllegalArgumentException e) {
+ setState(DeviceState.NO_DEVICE);
+ throw new DeviceTechnicalException(this, "Can't open audio device", e);
+
+ } catch (IllegalStateException e) {
+ setState(DeviceState.NO_DEVICE);
+ throw new DeviceTechnicalException(this, "Can't open audio device", e);
+
+ } catch (SecurityException e) {
+ setState(DeviceState.NO_DEVICE);
+ throw new DeviceTechnicalException(this, "Can't open audio device", e);
+
+ } catch (LineUnavailableException e) {
+ setState(DeviceState.NO_DEVICE);
+ throw new DeviceTechnicalException(this, "Can't open audio device", e);
}
}
@Override
+ public void start() {
+
+ if (getState() == DeviceState.READY) {
+
+ // Stop previous recording
+ stop();
+
+ logger.info("Start reading audio line");
+
+ lineReader = new DataLineReader();
+ lineReader.start();
+ }
+ }
+
+ @Override
public void record(File outputFile, long delaySeconds) throws IOException {
if (DeviceState.NO_DATA == state) {
if (logger.isWarnEnabled()) {
logger.warn("Can't record " + outputFile.getAbsolutePath() + ", no available dataLine");
}
+
+ // XXX-fdesbois-2012-08-03 : try to start the line again ?
+
return;
}
@@ -220,16 +275,25 @@
@Override
public void stop() {
- if (dataLine != null && dataLine.isRunning()) {
+ if (getState() != DeviceState.NO_DEVICE) {
- logger.info("Close the audio line");
-
// Destroy the thread
if (lineReader != null) {
lineReader.interrupt();
}
lineReader = null;
+ }
+ }
+ @Override
+ public void close() throws DeviceTechnicalException {
+
+ stop();
+
+ if (dataLine != null && dataLine.isRunning()) {
+
+ logger.info("Close the audio line");
+
dataLine.stop();
dataLine.drain();
dataLine.close();
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderMock.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderMock.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioRecorderMock.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -23,11 +23,15 @@
* #L%
*/
+import com.google.common.collect.Sets;
import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceTechnicalException;
+import fr.ulr.sammoa.application.DeviceUpdateListener;
import javax.sound.sampled.AudioFileFormat;
import java.io.File;
import java.io.IOException;
+import java.util.Set;
/**
* Mock for {@link AudioRecorder} that record nothing.
@@ -49,6 +53,11 @@
}
@Override
+ public void open() throws DeviceTechnicalException {
+ // do nothing
+ }
+
+ @Override
public void start() {
// do nothing
}
@@ -69,12 +78,22 @@
}
@Override
- public void addAudioUpdateListener(AudioUpdateListener listener) {
+ public void close() throws DeviceTechnicalException {
// do nothing
}
@Override
- public void removeAudioUpdateListener(AudioUpdateListener listener) {
+ public void addUpdateListener(DeviceUpdateListener listener) {
// do nothing
}
+
+ @Override
+ public void removeUpdateListener(DeviceUpdateListener listener) {
+ // do nothing
+ }
+
+ @Override
+ public Set<DeviceUpdateListener> getUpdateListeners() {
+ return Sets.newHashSet();
+ }
}
Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioUpdateListener.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioUpdateListener.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioUpdateListener.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -1,42 +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.application.audio;
-
-import fr.ulr.sammoa.application.DeviceState;
-
-/**
- * Created: 15/06/12
- *
- * @author fdesbois <desbois(a)codelutin.com>
- */
-public interface AudioUpdateListener {
-
- /**
- * Update audio line state.
- *
- * @param state new state
- */
- void onStateChanged(DeviceState state);
-
-}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/BaseGpsHandler.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/BaseGpsHandler.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/BaseGpsHandler.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -25,7 +25,11 @@
import com.google.common.collect.Sets;
import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceTechnicalException;
+import fr.ulr.sammoa.application.DeviceUpdateEvent;
import fr.ulr.sammoa.persistence.GeoPoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Set;
import java.util.Timer;
@@ -33,11 +37,11 @@
/**
* Base class for {@link GpsHandler} interface. This class contains common behaviour
- * for automatic check on a given {@code period}. For that, this class act
- * as a {@link TimerTask} scheduled from constructor. You can override the
- * method {@link #onInit()} to add some initialize behaviour before running
- * the Timer thread. The method {@link #getCurrentLocation()} must return
- * null if the location doesn't change or the GPS is down.
+ * for automatic check on a given {@code period}. For that, this class contains
+ * a {@link TimerTask} scheduled from {@link #start()}. The {@link #open()} method
+ * will be called on start if state is still {@link DeviceState#NO_DEVICE}.
+ * The method {@link #getCurrentLocation()} must return null if the location doesn't
+ * change or the GPS is down.
*
* Created: 02/07/12
*
@@ -46,40 +50,35 @@
* @see FakeGpsHandler
* @see GpsHandlerGpsylon
*/
-public abstract class BaseGpsHandler extends TimerTask implements GpsHandler {
+public abstract class BaseGpsHandler implements GpsHandler {
+ private static final Logger logger = LoggerFactory.getLogger(BaseGpsHandler.class);
+
protected Set<GpsUpdateListener> gpsUpdateListeners;
/** To test if connection to device is effective. */
- protected DeviceState gpsState = DeviceState.NO_DEVICE;
+ protected DeviceState state;
- /** To test if UI has activated gps position tracking. */
- protected boolean trackingStarted;
+ protected GpsConfig config;
+ protected Timer timer;
+
/**
* Value to check the number of timer update failures before the DeviceState
* becomes {@link DeviceState#NO_DATA}
*/
protected int nbFailuresMax;
- protected int nbFailures;
-
- protected GpsConfig config;
-
public BaseGpsHandler(GpsConfig config) {
this.config = config;
- int periodSeconds = config.getCheckPeriod();
- int timeoutSeconds = config.getTimeout();
- gpsUpdateListeners = Sets.newHashSet();
+ this.state = DeviceState.NO_DEVICE;
+ this.gpsUpdateListeners = Sets.newHashSet();
+ this.nbFailuresMax =
+ (int) Math.ceil(config.getTimeout() / config.getCheckPeriod());
- onInit();
-
- nbFailuresMax = (int) Math.ceil(timeoutSeconds / periodSeconds);
-
- // un thread doit tourner tout le temps et dès le départ pour
- // vérifier un changement d'état du gps
- Timer gpsStatusTimer = new Timer();
- gpsStatusTimer.schedule(this, 0, periodSeconds * 1000);
+ if (logger.isDebugEnabled()) {
+ logger.debug("GPS NbFailuresMax = " + nbFailuresMax);
+ }
}
public GpsConfig getConfig() {
@@ -87,77 +86,122 @@
}
@Override
- public void start() {
- trackingStarted = true;
+ public DeviceState getState() {
+ return state;
}
@Override
+ public void start() throws DeviceTechnicalException {
+
+ long periodMilliseconds = config.getCheckPeriod() * 1000;
+
+ if (getState() == DeviceState.READY) {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Start scheduling GpsHandler every "
+ + periodMilliseconds + " milliseconds");
+ }
+
+ timer = new Timer();
+ timer.schedule(recordTask, 0, periodMilliseconds);
+
+ } else {
+
+ timer = new Timer();
+ timer.schedule(openTask, 0, periodMilliseconds);
+ }
+ }
+
+ @Override
public void stop() {
- trackingStarted = false;
+ timer.cancel();
+ timer = null;
}
@Override
- public void addGpsUpdateListener(GpsUpdateListener gpsUpdateListener) {
+ public void addUpdateListener(GpsUpdateListener gpsUpdateListener) {
gpsUpdateListeners.add(gpsUpdateListener);
}
@Override
- public void removeGpsUpdateListener(GpsUpdateListener gpsUpdateListener) {
+ public void removeUpdateListener(GpsUpdateListener gpsUpdateListener) {
gpsUpdateListeners.remove(gpsUpdateListener);
}
@Override
- public Set<GpsUpdateListener> getGpsUpdateListeners() {
+ public Set<GpsUpdateListener> getUpdateListeners() {
return gpsUpdateListeners;
}
- @Override
- public void run() {
+ protected void setState(DeviceState state) {
+ DeviceState oldValue = getState();
+ this.state = state;
- GeoPoint currentLocation = getCurrentLocation();
+ for (GpsUpdateListener listener : gpsUpdateListeners) {
+ listener.onStateChanged(new DeviceUpdateEvent<DeviceState>(this, oldValue, state));
+ }
+ }
- // increment nbFailures if currentLocation is undefined
- if (currentLocation == null) {
- nbFailures++;
- }else {
- nbFailures = 0;
+ protected TimerTask openTask = new TimerTask() {
+
+ @Override
+ public void run() {
+ try {
+
+ open();
+
+ timer.cancel();
+ timer = null;
+
+ start();
+
+ } catch (DeviceTechnicalException ex) {
+
+ // We use NO_DATA, because this task is during start
+ setState(DeviceState.NO_DATA);
+
+ if (logger.isErrorEnabled()) {
+ logger.error("Can't open GPS device. Try again in "
+ + this.scheduledExecutionTime() + " milliseconds", ex);
+ }
+ }
}
+ };
- if (trackingStarted) {
+ protected TimerTask recordTask = new TimerTask() {
+ protected GeoPoint location;
+
+ protected int nbFailures;
+
+ @Override
+ public void run() {
+
+ GeoPoint lastLocation = location;
+
+ location = getCurrentLocation();
+
+ // reset nbFailures if currentLocation is defined
+ if (location != null) {
+ nbFailures = 0;
+ } else {
+ nbFailures++;
+ }
+
// Data is unavailable
- if (currentLocation == null && nbFailures >= nbFailuresMax) {
- setGpsState(DeviceState.NO_DATA);
+ if (location == null && nbFailures >= nbFailuresMax) {
+ setState(DeviceState.NO_DATA);
// GPS is recording
} else {
- setGpsState(DeviceState.RECORDING);
+ setState(DeviceState.RECORDING);
// Fire events for location change
for (GpsUpdateListener listener : gpsUpdateListeners) {
- listener.onLocationReceived(currentLocation);
+ listener.onLocationReceived(new DeviceUpdateEvent<GeoPoint>(BaseGpsHandler.this, lastLocation, location));
}
}
-
- // GPS is unavailable
- } else if (currentLocation == null && nbFailures >= nbFailuresMax) {
- setGpsState(DeviceState.NO_DEVICE);
-
- // GPS is ready
- } else {
- setGpsState(DeviceState.READY);
}
- }
-
- protected void setGpsState(DeviceState gpsState) {
- this.gpsState = gpsState;
-
- for (GpsUpdateListener listener : gpsUpdateListeners) {
- listener.onStateChanged(gpsState);
- }
- }
-
- protected void onInit() {
- }
+ };
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/FakeGpsHandler.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/FakeGpsHandler.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/FakeGpsHandler.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -24,6 +24,7 @@
*/
package fr.ulr.sammoa.application.gps;
+import fr.ulr.sammoa.application.DeviceTechnicalException;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.persistence.GeoPointImpl;
import org.slf4j.Logger;
@@ -89,8 +90,13 @@
// }
// }, 10000, 10000);
}
-
+
@Override
+ public void open() throws DeviceTechnicalException {
+ // nothing to do
+ }
+
+ @Override
public void start() {
if (thread == null) {
thread = new Thread(new GpsPointGenerator());
@@ -100,6 +106,11 @@
}
@Override
+ public void close() throws DeviceTechnicalException {
+ // nothing to do
+ }
+
+ @Override
protected void finalize() throws Throwable {
if (thread != null) {
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandler.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandler.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandler.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -24,53 +24,19 @@
*/
package fr.ulr.sammoa.application.gps;
+import fr.ulr.sammoa.application.DeviceManager;
import fr.ulr.sammoa.persistence.GeoPoint;
-import java.util.Set;
-
/**
* Représente l'accès à un périphérique GPS.
*/
-public interface GpsHandler {
+public interface GpsHandler extends DeviceManager<GpsUpdateListener> {
/**
- * Démarre le tracking de position.
- * Active la notification de la position via {@link GpsUpdateListener#onLocationReceived(GeoPoint)}.
- */
- void start();
-
- /**
- * Stoppe le tracking de position.
- * Désactive la notification de la position via {@link GpsUpdateListener#onLocationReceived(GeoPoint)}.
- */
- void stop();
-
- /**
* Retourne la position courante du GPS.
*
* @return la position courante selon le GPS ou {@code null} si elle ne peut
* pas être obtenue
*/
GeoPoint getCurrentLocation();
-
- /**
- * Permet de s'enregistrer pour écouter un événement levé
- * lorsqu'un déplacement est mesuré par le GPS.
- *
- * @param gpsUpdateListener l'objet à notifier
- */
- void addGpsUpdateListener(GpsUpdateListener gpsUpdateListener);
-
- /**
- * Permet de se désenregistrer pour ne plus écouter les événements levés
- * lorsqu'un déplacement est mesuré par le GPS.
- *
- * @param gpsUpdateListener l'objet à ne plus notifier
- */
- void removeGpsUpdateListener(GpsUpdateListener gpsUpdateListener);
-
- /**
- * @return all the listeners
- */
- Set<GpsUpdateListener> getGpsUpdateListeners();
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandlerGpsylon.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandlerGpsylon.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsHandlerGpsylon.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -26,9 +26,11 @@
package fr.ulr.sammoa.application.gps;
import com.google.common.base.Objects;
-import fr.ulr.sammoa.application.SammoaTechnicalException;
+import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceTechnicalException;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.persistence.GeoPointImpl;
+import gnu.io.CommPortIdentifier;
import org.dinopolis.gpstool.gpsinput.GPSDataProcessor;
import org.dinopolis.gpstool.gpsinput.GPSDevice;
import org.dinopolis.gpstool.gpsinput.GPSException;
@@ -41,6 +43,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;
+import java.util.Enumeration;
import java.util.Hashtable;
/**
@@ -48,25 +51,14 @@
*
* @author echatellier
*/
-public class GpsHandlerGpsylon extends BaseGpsHandler implements PropertyChangeListener {
+public class GpsHandlerGpsylon extends BaseGpsHandler {
private static final Logger logger = LoggerFactory.getLogger(GpsHandlerGpsylon.class);
-// protected Set<GpsUpdateListener> gpsUpdateListeners;
-
protected GPSDataProcessor gpsDataProcessor;
protected GPSDevice gpsDevice;
-// /** To test if connection to device is effective. */
-// protected DeviceState gpsState = DeviceState.NO_DEVICE;
-//
-// /** To test if UI has activated gps position tracking. */
-// protected boolean trackingStarted;
-
- /** Time stamp of last data received from gps. */
- protected long lastDataReceivedTimeStamp;
-
protected GPSPosition lastPosition;
protected GPSPosition lastSendPosition;
@@ -75,48 +67,131 @@
protected float lastSpeed;
+ protected boolean deviceInitialized;
+
public GpsHandlerGpsylon(GpsConfig config) {
super(config);
}
@Override
- protected void onInit() {
- gpsDataProcessor = new GPSNmeaDataProcessor();
- // not usefull, processed by GPSNmeaDataProcessor
- // and dispatched to GPSDataChangeListener
- //gpsDataProcessor.addGPSRawDataListener(this);
+ public void open() throws DeviceTechnicalException {
- // listen for specific properties
- gpsDataProcessor.addGPSDataChangeListener(GPSDataProcessor.LOCATION, this);
- gpsDataProcessor.addGPSDataChangeListener(GPSDataProcessor.ALTITUDE, this);
- gpsDataProcessor.addGPSDataChangeListener(GPSDataProcessor.SPEED, this);
+ if (getState() == DeviceState.READY) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("GPS already opened");
+ }
+ return;
+ }
- gpsDevice = new GPSSerialDevice();
try {
- Hashtable<String, Object> options = new Hashtable<String, Object>();
- options.put(GPSSerialDevice.PORT_NAME_KEY, getConfig().getDevice());
- options.put(GPSSerialDevice.PORT_SPEED_KEY, getConfig().getSpeed());
- if (logger.isDebugEnabled()) {
- logger.debug("GPS options: " + options);
+ if (!deviceInitialized) {
+
+ gpsDataProcessor = new GPSNmeaDataProcessor();
+
+ gpsDevice = new SammoaGPSSerialDevice();
+
+ Hashtable<String, Object> options = new Hashtable<String, Object>();
+ options.put(GPSSerialDevice.PORT_NAME_KEY, getConfig().getDevice());
+ options.put(GPSSerialDevice.PORT_SPEED_KEY, getConfig().getSpeed());
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("GPS options: " + options);
+ }
+
+ gpsDevice.init(options);
+ gpsDataProcessor.setGPSDevice(gpsDevice);
+
+ deviceInitialized = true;
}
- gpsDevice.init(options);
- gpsDataProcessor.setGPSDevice(gpsDevice);
+ if (logger.isTraceEnabled()) {
+ Enumeration portList = CommPortIdentifier.getPortIdentifiers();
- } catch (GPSException ex) {
- throw new SammoaTechnicalException("Can't connect to gps", ex);
- }
+ while (portList.hasMoreElements()) {
+ CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
+ if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
+ logger.trace("Available SERIAL port : " + portId.getName());
+ }
+ }
+ }
- // try to reconnect
- try {
gpsDataProcessor.open();
+
+ gpsDataProcessor.addGPSDataChangeListener(
+ GPSDataProcessor.LOCATION, gpsDataProcessorListener);
+ gpsDataProcessor.addGPSDataChangeListener(
+ GPSDataProcessor.ALTITUDE, gpsDataProcessorListener);
+ gpsDataProcessor.addGPSDataChangeListener(
+ GPSDataProcessor.SPEED, gpsDataProcessorListener);
+
logger.info("Connected to GPS device");
+
+ setState(DeviceState.READY);
+
} catch (GPSException ex) {
- logger.trace("Can't connect to gps device");
+
+ setState(DeviceState.NO_DEVICE);
+
+ throw new DeviceTechnicalException(this, "Can't open GPS device", ex);
}
}
+ @Override
+ public void close() {
+
+ stop();
+
+ if (gpsDataProcessor != null && getState() != DeviceState.NO_DEVICE) {
+
+ logger.info("Closing GPS device...");
+ try {
+
+ gpsDataProcessor.removeGPSDataChangeListener(
+ GPSDataProcessor.LOCATION, gpsDataProcessorListener);
+ gpsDataProcessor.removeGPSDataChangeListener(
+ GPSDataProcessor.ALTITUDE, gpsDataProcessorListener);
+ gpsDataProcessor.removeGPSDataChangeListener(
+ GPSDataProcessor.SPEED, gpsDataProcessorListener);
+
+ gpsDataProcessor.close();
+
+ logger.info("GPS device is closed");
+
+ setState(DeviceState.NO_DEVICE);
+
+ } catch (GPSException e) {
+ throw new DeviceTechnicalException(this, "Can't close GPS device", e);
+ }
+ }
+ }
+
+ @Override
+ public GeoPoint getCurrentLocation() {
+
+ GeoPoint result = null;
+
+ 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;
+ }
+ return result;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ close();
+ super.finalize();
+ }
+
/**
* 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
@@ -138,54 +213,24 @@
* <li>VDOP: a Float indicating the quality of the gps signal in vertical direction.
* </ul>
*/
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
+ protected PropertyChangeListener gpsDataProcessorListener = new PropertyChangeListener() {
- String property = evt.getPropertyName();
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
- if (trackingStarted) {
+ String property = evt.getPropertyName();
logger.trace("Gps data received {} {}", property, evt.getNewValue());
- // update timestamp of the last notification
- lastDataReceivedTimeStamp = System.currentTimeMillis();
-
if (GPSDataProcessor.LOCATION.equals(property)) {
lastPosition = (GPSPosition) evt.getNewValue();
+
} else if (GPSDataProcessor.ALTITUDE.equals(property)) {
lastAltitude = (Float) evt.getNewValue();
+
} else if (GPSDataProcessor.SPEED.equals(property)) {
lastSpeed = (Float) evt.getNewValue();
}
}
- }
-
- @Override
- public GeoPoint getCurrentLocation() {
-
- logger.trace("Ask for position = {}", lastPosition);
-
- GeoPoint location = null;
- if (!Objects.equal(lastPosition, lastSendPosition) && lastPosition != null) {
-
- location = new GeoPointImpl(lastPosition.getLatitude(), lastPosition.getLongitude());
- location.setAltitude(lastAltitude);
- location.setSpeed(lastSpeed);
- // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp
- location.setRecordTime(new Date());
-
- lastSendPosition = lastPosition;
- }
-
- return location;
- }
-
- @Override
- protected void finalize() throws Throwable {
- if (gpsDataProcessor != null) {
- logger.info("Closing GPS device");
- gpsDataProcessor.close();
- }
- super.finalize();
- }
+ };
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsUpdateListener.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsUpdateListener.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/GpsUpdateListener.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -24,25 +24,19 @@
*/
package fr.ulr.sammoa.application.gps;
-import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceUpdateEvent;
+import fr.ulr.sammoa.application.DeviceUpdateListener;
import fr.ulr.sammoa.persistence.GeoPoint;
/**
* DP Observateur.
*/
-public interface GpsUpdateListener {
+public interface GpsUpdateListener extends DeviceUpdateListener {
/**
* Update GPS location.
*
- * @param newLocation new location
+ * @param event new event
*/
- void onLocationReceived(GeoPoint newLocation);
-
- /**
- * Update GPS state.
- *
- * @param state new state
- */
- void onStateChanged(DeviceState state);
+ void onLocationReceived(DeviceUpdateEvent<GeoPoint> event);
}
Added: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/SammoaGPSSerialDevice.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/SammoaGPSSerialDevice.java (rev 0)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/SammoaGPSSerialDevice.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -0,0 +1,67 @@
+package fr.ulr.sammoa.application.gps;
+/*
+ * #%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 gnu.io.RXTXHack;
+import gnu.io.RXTXPort;
+import org.dinopolis.gpstool.gpsinput.GPSException;
+import org.dinopolis.gpstool.gpsinput.GPSSerialDevice;
+
+/**
+ * There is an issue with closing on {@link gnu.io.SerialPort}. See
+ * <a href="https://forums.oracle.com/forums/thread.jspa?threadID=1292323">
+ * https://forums.oracle.com/forums/thread.jspa?threadID=1292323
+ * </a>
+ *
+ * Note that only the {@link RXTXHack} works... Maybe the upgrade of rxtx.jar could
+ * works (not in maven repo).
+ * <p/>
+ * The issue is probably from {@link org.dinopolis.gpstool.gpsinput.nmea.GPSNmeaDataProcessor}
+ * that creates a daemon thread to read the serialPort InputStream. There is
+ * no way to kill properly this thread before closing serialPort.
+ *
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public class SammoaGPSSerialDevice extends GPSSerialDevice {
+
+ @Override
+ public void close() throws GPSException {
+ if (serial_port_ != null) {
+
+// serial_port_.removeEventListener();
+// try {
+// serial_port_.getOutputStream().flush();
+// serial_port_.getOutputStream().close();
+// serial_port_.getInputStream().close();
+// } catch (IOException e) {
+// throw Throwables.propagate(e);
+// }
+// serial_port_.close();
+
+ RXTXHack.closeRxtxPort((RXTXPort) serial_port_);
+ }
+ }
+}
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/gps/SammoaGPSSerialDevice.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java (from rev 356, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/audio/AudioUpdateListener.java)
===================================================================
--- trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java (rev 0)
+++ trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -0,0 +1,42 @@
+package gnu.io;
+/*
+ * #%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%
+ */
+
+/**
+ * Created: 06/08/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ * @see fr.ulr.sammoa.application.gps.SammoaGPSSerialDevice for usage
+ */
+public final class RXTXHack {
+
+ private RXTXHack() {
+ // final class with static methods
+ }
+
+ public static void closeRxtxPort(RXTXPort port) {
+ port.IOLocked = 0;
+ port.close();
+ }
+}
Property changes on: trunk/sammoa-application/src/main/java/gnu/io/RXTXHack.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/MainUIHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -24,6 +24,7 @@
*/
package fr.ulr.sammoa.ui.swing;
+import fr.ulr.sammoa.application.DeviceTechnicalException;
import fr.ulr.sammoa.application.FlightState;
import fr.ulr.sammoa.application.SammoaConfig;
import fr.ulr.sammoa.application.SammoaContext;
@@ -35,6 +36,7 @@
import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler;
import fr.ulr.sammoa.ui.swing.home.HomeUI;
import fr.ulr.sammoa.ui.swing.io.exportMap.ExportMapUI;
+import fr.ulr.sammoa.ui.swing.util.SammoaUtil;
import jaxx.runtime.SwingUtil;
import jaxx.runtime.swing.AboutPanel;
import jaxx.runtime.swing.ErrorDialogUI;
@@ -90,10 +92,10 @@
@Override
public void afterInitUI() {
- // 3- Synch to error dialog
+ // Sync to error dialog
ErrorDialogUI.init(ui);
- // 4- Init SwingSession
+ // Init SwingSession
SwingSession swingSession = new SwingSession(getConfig().getUIConfigFile(), false);
swingSession.add(ui);
swingSession.save();
@@ -295,7 +297,12 @@
FlightUIHandler flightUIHandler = context.getFlightUIHandler();
if (flightUIHandler != null) {
GpsConfig gpsConfig = context.getConfig().getGpsConfig();
- flightUIHandler.getFlightController().initGpsHandler(gpsConfig);
+ try {
+ flightUIHandler.getFlightController().openGpsDevice(gpsConfig);
+ } catch (DeviceTechnicalException ex) {
+ logger.error("Error on new GpsHandler", ex);
+ SammoaUtil.showError(ui, ex);
+ }
}
}
});
Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/AudioStateLED.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/AudioStateLED.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/AudioStateLED.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -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;
-
-import fr.ulr.sammoa.application.audio.AudioUpdateListener;
-
-/**
- * Panel qui écoute l'état du gps pour afficher à l'utilsateur un voyant
- * lunineux dépendant de l'état du peripherique audio.
- *
- * Indicateurs pour l'état du GPS
- * <ul>
- * <li>voyant gris : pas de peripherique
- * <li>voyant bleu : peripherique prêt
- * <li>voyant vert : enregistrement en cours
- * <li>voyant rouge clignotant : enregistrement mais pas de données
- * </ul>
- *
- * @author echatellier
- */
-public class AudioStateLED extends DeviceStateLED implements AudioUpdateListener {
-
- /** serialVersionUID. */
- private static final long serialVersionUID = 1L;
-}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/DeviceStateLED.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -25,29 +25,41 @@
package fr.ulr.sammoa.ui.swing.flight;
import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceUpdateEvent;
+import fr.ulr.sammoa.application.DeviceUpdateListener;
+import fr.ulr.sammoa.application.gps.GpsUpdateListener;
+import fr.ulr.sammoa.persistence.GeoPoint;
import org.nuiton.util.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.swing.ImageIcon;
-import javax.swing.JLabel;
+import javax.swing.*;
/**
- * Classe abtraite permettant d'obtenir et d'afficher l'état d'un périphérique.
+ * Panel qui écoute l'état du peripherique pour afficher à l'utilsateur un voyant
+ * lunineux dépendant de l'état du peripherique.
+ *
+ * Indicateurs pour l'état du peripherique
+ * <ul>
+ * <li>voyant gris : pas de peripherique
+ * <li>voyant bleu : peripherique prêt
+ * <li>voyant vert : enregistrement en cours
+ * <li>voyant rouge clignotant : enregistrement mais pas de données
+ * </ul>
*
* @author chatellier
*/
-public abstract class DeviceStateLED extends JLabel {
+public class DeviceStateLED extends JLabel implements DeviceUpdateListener, GpsUpdateListener {
- private static final Logger logger = LoggerFactory.getLogger(DeviceStateLED.class);
-
/** serialVersionUID. */
private static final long serialVersionUID = 1L;
+ private static final Logger logger = LoggerFactory.getLogger(DeviceStateLED.class);
+
protected DeviceState state;
public DeviceStateLED() {
- onStateChanged(DeviceState.NO_DEVICE);
+// onStateChanged(DeviceState.NO_DEVICE);
}
protected static final ImageIcon NO_DEVICE_ICON = Resource.getIcon("/icons/device/nodevice.png");
@@ -55,9 +67,10 @@
protected static final ImageIcon RECORDING_ICON = Resource.getIcon("/icons/device/recording.png");
protected static final ImageIcon NO_DATA_ICON = Resource.getIcon("/icons/device/nodata.gif");
- public void onStateChanged(DeviceState state) {
+ @Override
+ public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
DeviceState oldValue = getState();
- this.state = state;
+ this.state = event.getNewValue();
if (oldValue != state) {
@@ -84,4 +97,9 @@
public DeviceState getState() {
return state;
}
+
+ @Override
+ public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ // nothing to do
+ }
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBar.jaxx 2012-08-06 14:33:43 UTC (rev 357)
@@ -85,8 +85,8 @@
</cell>
<cell fill='horizontal' weightx='0.2' anchor='center'>
<JPanel id='cbPanel' layout='{new BoxLayout(cbPanel, BoxLayout.Y_AXIS)}'>
- <GpsStateLED id='gpsLED' />
- <AudioStateLED id='audioLED' />
+ <DeviceStateLED id='gpsLED' />
+ <DeviceStateLED id='audioLED' />
</JPanel>
</cell>
<cell fill='vertical'>
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-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarHandler.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -51,19 +51,11 @@
return view.getModel();
}
- public AudioStateLED getAudioLED() {
- return view.getAudioLED();
- }
-
- public GpsStateLED getGpsLED() {
- return view.getGpsLED();
- }
-
public void init() {
getFlightUIModel().addPropertyChangeListener(this);
- getFlightController().getAudioRecorder().addAudioUpdateListener(getAudioLED());
- getFlightController().getGpsHandler().addGpsUpdateListener(getGpsLED());
- getFlightController().getGpsHandler().addGpsUpdateListener(getModel());
+ getFlightController().getAudioRecorder().addUpdateListener(view.getAudioLED());
+ getFlightController().getGpsHandler().addUpdateListener(view.getGpsLED());
+ getFlightController().getGpsHandler().addUpdateListener(getModel());
}
@Override
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightBarModel.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -25,11 +25,12 @@
package fr.ulr.sammoa.ui.swing.flight;
import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceUpdateEvent;
import fr.ulr.sammoa.application.gps.GpsUpdateListener;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.ui.swing.BaseModel;
-import java.awt.Color;
+import java.awt.*;
import static org.nuiton.i18n.I18n._;
@@ -81,7 +82,8 @@
}
@Override
- public void onLocationReceived(GeoPoint newLocation) {
+ public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ GeoPoint newLocation = event.getNewValue();
if (newLocation != null) {
setSpeed((float) newLocation.getSpeed());
setAlt((float) newLocation.getAltitude());
@@ -89,7 +91,7 @@
}
@Override
- public void onStateChanged(DeviceState state) {
+ public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
// nothing to do
}
}
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-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -47,6 +47,8 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceTechnicalException;
+import fr.ulr.sammoa.application.DeviceUpdateEvent;
import fr.ulr.sammoa.application.FlightController;
import fr.ulr.sammoa.application.FlightControllerDefault;
import fr.ulr.sammoa.application.FlightControllerUpdateListener;
@@ -84,6 +86,7 @@
import fr.ulr.sammoa.ui.swing.flight.layer.StrateLayer;
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;
import jaxx.runtime.JAXXObject;
import jaxx.runtime.SwingUtil;
import org.nuiton.util.ApplicationConfig;
@@ -143,6 +146,10 @@
return context.getAppContext();
}
+ public FlightUI getUI() {
+ return ui;
+ }
+
public FlightController getFlightController() {
return flightController;
}
@@ -203,7 +210,23 @@
startTime = timeLog.log(startTime, "beforeInitUI", "entities are loaded");
flightController = new FlightControllerDefault(getAppContext(), flight);
+
+ try {
+ flightController.openGpsDevice(getConfig().getGpsConfig());
+ } catch (DeviceTechnicalException ex) {
+ logger.error("Error on FlightController init", ex);
+ SammoaUtil.showError(ui, ex);
+ }
+
+ try {
+ flightController.openAudioDevice();
+ } catch (DeviceTechnicalException ex) {
+ logger.error("Error on FlightController init", ex);
+ SammoaUtil.showError(ui, ex);
+ }
+
flightController.addListener(this);
+ flightController.init();
FlightUIModel model = new FlightUIModel();
@@ -358,20 +381,21 @@
initMapHandler();
- getFlightController().getGpsHandler().addGpsUpdateListener(
+ getFlightController().getGpsHandler().addUpdateListener(
new GpsUpdateListener() {
@Override
- public void onLocationReceived(GeoPoint newLocation) {
+ public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ GeoPoint newLocation = event.getNewValue();
if (newLocation != null && getModel().isMapFollow()) {
MapBean mapBean = getOverlayMapPanel().getMapBean();
mapBean.setCenter(new LatLonPoint.Double(newLocation.getLatitude(),
- newLocation.getLongitude()));
+ newLocation.getLongitude()));
}
}
@Override
- public void onStateChanged(DeviceState state) {
+ public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
// nothing to do
}
});
@@ -725,7 +749,7 @@
// Ajout d'un layer pour représenter les points relevés par le GPS
GpsTracingLayer gpsTracingLayer = new GpsTracingLayer();
- getFlightController().getGpsHandler().addGpsUpdateListener(gpsTracingLayer);
+ getFlightController().getGpsHandler().addUpdateListener(gpsTracingLayer);
mapHandler.add(gpsTracingLayer);
InformationDelegator informationDelegator = new InformationDelegator();
Deleted: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/GpsStateLED.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/GpsStateLED.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/GpsStateLED.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -1,58 +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;
-
-import fr.ulr.sammoa.application.gps.GpsUpdateListener;
-import fr.ulr.sammoa.persistence.GeoPoint;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Panel qui écoute l'état du gps pour afficher à l'utilsateur un voyant
- * lunineux dépendant de l'état du gps.
- *
- * Indicateurs pour l'état du GPS
- * <ul>
- * <li>voyant gris : pas de GPS
- * <li>voyant bleu : GPS prêt
- * <li>voyant vert : enregistrement en cours
- * <li>voyant rouge clignotant : enregistrement mais pas de données GPS
- * </ul>
- *
- * @author echatellier
- */
-public class GpsStateLED extends DeviceStateLED implements GpsUpdateListener {
-
- private static final Logger logger = LoggerFactory.getLogger(GpsStateLED.class);
-
- /** serialVersionUID. */
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onLocationReceived(GeoPoint newLocation) {
- // nothing to do
- }
-}
Modified: 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-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/GpsTracingLayer.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -30,6 +30,7 @@
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.omGraphics.OMLine;
import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceUpdateEvent;
import fr.ulr.sammoa.application.gps.GpsUpdateListener;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.persistence.GeoPointImpl;
@@ -51,9 +52,11 @@
}
@Override
- public void onLocationReceived(GeoPoint newLocation) {
+ public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
// OMGraphic point = new OMPoint(newLocation.getLatitude(), newLocation.getLongitude());
+ GeoPoint newLocation = event.getNewValue();
+
if (currentLocation == null) {
// do not display the first location point
@@ -87,7 +90,7 @@
}
@Override
- public void onStateChanged(DeviceState state) {
-
+ public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
+ // nothing to do
}
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -24,9 +24,10 @@
*/
import fr.ulr.sammoa.application.DeviceState;
+import fr.ulr.sammoa.application.DeviceUpdateEvent;
+import fr.ulr.sammoa.application.DeviceUpdateListener;
import fr.ulr.sammoa.application.FlightController;
import fr.ulr.sammoa.application.FlightService;
-import fr.ulr.sammoa.application.audio.AudioUpdateListener;
import fr.ulr.sammoa.application.gps.GpsUpdateListener;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.persistence.Observation;
@@ -96,7 +97,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.4
*/
-public class EffortPanelHandler implements GpsUpdateListener, AudioUpdateListener {
+public class EffortPanelHandler implements DeviceUpdateListener, GpsUpdateListener {
private static final Logger logger =
LoggerFactory.getLogger(EffortPanelHandler.class);
@@ -274,8 +275,8 @@
SammoaUIContext.getUIContext().getFlightUIHandler().getFlightController();
if (flightController != null) {
- flightController.getGpsHandler().addGpsUpdateListener(this);
- flightController.getAudioRecorder().addAudioUpdateListener(this);
+ flightController.getGpsHandler().addUpdateListener(this);
+ flightController.getAudioRecorder().addUpdateListener(this);
}
@@ -551,12 +552,8 @@
}
@Override
- public void onLocationReceived(GeoPoint newLocation) {
- // do nothing
- }
-
- @Override
- public void onStateChanged(DeviceState state) {
+ public void onStateChanged(DeviceUpdateEvent<DeviceState> event) {
+ DeviceState state = event.getNewValue();
if (DeviceState.NO_DATA == state) {
ui.getObservationTable().setBackground(DEVICE_ERROR_BACKGROUND_COLOR);
@@ -565,11 +562,15 @@
}
}
+ @Override
+ public void onLocationReceived(DeviceUpdateEvent<GeoPoint> event) {
+ // nothing to do
+ }
+
public DecoratorProvider getDecoratorProvider() {
return SammoaUIContext.getUIContext().getDecoratorProvider();
}
-
public static void init(final JXTable table,
ListSelectionListener selectionListener) {
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-08-06 12:52:57 UTC (rev 356)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-08-06 14:33:43 UTC (rev 357)
@@ -26,6 +26,7 @@
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
+import fr.ulr.sammoa.application.DeviceTechnicalException;
import jaxx.runtime.JAXXUtil;
import jaxx.runtime.SwingUtil;
import org.apache.commons.beanutils.NestedNullException;
@@ -36,12 +37,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.swing.Action;
-import javax.swing.JComponent;
-import javax.swing.JDialog;
-import javax.swing.JFrame;
-import javax.swing.JRootPane;
-import javax.swing.KeyStroke;
+import javax.swing.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
@@ -230,4 +226,18 @@
ui.setCursor(Cursor.getDefaultCursor());
}
}
+
+ public static void showError(Component ui, DeviceTechnicalException ex) {
+ String message = ex.getMessage();
+ if (ex.getCause() != null) {
+ message += " : " + ex.getCause().getMessage();
+ }
+ JOptionPane.showMessageDialog(
+ ui,
+ message,
+ "Error",
+ JOptionPane.ERROR_MESSAGE,
+ UIManager.getIcon("error")
+ );
+ }
}
1
0
Author: tchemit
Date: 2012-08-06 14:52:57 +0200 (Mon, 06 Aug 2012)
New Revision: 356
Url: http://forge.codelutin.com/repositories/revision/sammoa/356
Log:
updates h2, hibernate, swingXVersion, logback and mavenpom versions
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-08-03 14:54:11 UTC (rev 355)
+++ trunk/pom.xml 2012-08-06 12:52:57 UTC (rev 356)
@@ -10,7 +10,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.3.4</version>
+ <version>3.3.5-SNAPSHOT</version>
</parent>
<groupId>fr.ulr</groupId>
@@ -117,16 +117,16 @@
<topiaVersion>2.6.11</topiaVersion>
<!--<hibernateVersion>4.1.3.Final</hibernateVersion>-->
<!--<geronimoJpaSpecVersion>1.1</geronimoJpaSpecVersion>-->
- <hibernateVersion>3.6.10.Final</hibernateVersion>
- <h2Version>1.3.167</h2Version>
+ <hibernateVersion>3.6.11.Final</hibernateVersion>
+ <h2Version>1.3.168</h2Version>
<postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion>
<jaxxVersion>2.5.4-SNAPSHOT</jaxxVersion>
- <swingXVersion>1.6.3</swingXVersion>
+ <swingXVersion>1.6.4</swingXVersion>
<xworkVersion>2.3.4</xworkVersion>
<slf4jVersion>1.6.6</slf4jVersion>
- <logbackVersion>1.0.2</logbackVersion>
+ <logbackVersion>1.0.6</logbackVersion>
<i18n.bundles>en_GB</i18n.bundles>
<i18n.silent>false</i18n.silent>
1
0