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
August 2012
- 4 participants
- 171 discussions
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
03 Aug '12
Author: tchemit
Date: 2012-08-03 16:54:11 +0200 (Fri, 03 Aug 2012)
New Revision: 355
Url: http://forge.codelutin.com/repositories/revision/sammoa/355
Log:
add missing svn properties + file headers
remove obsolete methods
refs #1203: Export SHP (changing campaign refresh species + speciesType list)
Added:
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Species2.java
Removed:
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/SpeciesDAOImpl.java
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ReferentialService.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapModel.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteType.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRef.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRefs.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.css
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/ExportMapUIHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanel.css
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/ForceSelectionSelectionModel.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextEditableCellAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextRowEditableAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousEditableCellAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousRowEditableAction.java
trunk/sammoa-ui-swing/src/main/resources/icons/action-accept.png
trunk/sammoa-ui-swing/src/main/resources/icons/action-cancel.png
trunk/sammoa-ui-swing/src/main/resources/icons/action-fileChooser.png
trunk/sammoa-ui-swing/src/test/resources/logback-test.xml
trunk/src/site/resources/ulr-sammoa-echange-data.svg
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-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/ReferentialService.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -615,25 +615,6 @@
return result;
}
- public List<String> getAllSpeciesTypes() {
- TopiaContext tx = persistence.beginTransaction();
- try {
-
- List<String> result =
- SammoaDAOHelper.getSpeciesDAO(tx).findAllSpeciesTypes();
-
- Collections.sort(result);
-
- return result;
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
-
- } finally {
- persistence.endTransaction(tx);
- }
-
- }
-
public List<Species> getAllSpecies() {
TopiaContext tx = persistence.beginTransaction();
try {
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-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapModel.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
package fr.ulr.sammoa.application.map;
+/*
+ * #%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.Lists;
import fr.ulr.sammoa.persistence.Campaign;
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
package fr.ulr.sammoa.application.map;
+/*
+ * #%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.SammoaConfig;
import fr.ulr.sammoa.application.SammoaContext;
Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteType.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteType.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteType.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
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%
+ */
public enum RouteType {
TRANSIT,
Property changes on: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteType.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Species2.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Species2.java (rev 0)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Species2.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -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 com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Useful methods around {@link Species}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.5
+ */
+public class Species2 {
+
+ private Species2() {
+ // no instance on util class
+ }
+
+ public static List<String> toSpeciesTypes(Collection<Species> species) {
+ Set<String> types = Sets.newHashSet();
+ for (Species specy : species) {
+ types.add(specy.getType());
+ }
+ return Lists.newArrayList(types);
+ }
+}
Property changes on: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Species2.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/SpeciesDAOImpl.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/SpeciesDAOImpl.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/SpeciesDAOImpl.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,21 +0,0 @@
-package fr.ulr.sammoa.persistence;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import org.nuiton.topia.TopiaException;
-
-import java.util.List;
-import java.util.Set;
-
-public class SpeciesDAOImpl<E extends Species> extends SpeciesDAOAbstract<E> {
-
- public List<String> findAllSpeciesTypes() throws TopiaException {
- Set<String> result = Sets.newHashSet();
- List<E> all = findAll();
- for (E e : all) {
- result.add(e.getType());
- }
- return Lists.newArrayList(result);
- }
-
-} //SpeciesDAOImpl<E extends Species>
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRef.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRef.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRef.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
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 java.io.Serializable;
Property changes on: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRef.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRefs.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRefs.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRefs.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
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.Iterables;
Property changes on: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/StringRefs.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,3 +1,26 @@
+/*
+ * #%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%
+ */
#exportMapDirectoryFileChooseAction {
actionIcon:"fileChooser";
}
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,3 +1,26 @@
+<!--
+ #%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%
+ -->
<JPanel layout='{new BorderLayout()}'>
<import>
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx
___________________________________________________________________
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/io/exportMap/ExportMapUI.css
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.css 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.css 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,3 +1,26 @@
+/*
+ * #%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%
+ */
BeanListHeader {
i18nPrefix: "sammoa.common.";
}
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.css
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
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-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.jaxx 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,3 +1,26 @@
+<!--
+ #%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%
+ -->
<JPanel id='exportMapUI' layout='{new BorderLayout()}'
implements='fr.ulr.sammoa.ui.swing.SammoaUI<ExportMapUIHandler>'>
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.jaxx
___________________________________________________________________
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/io/exportMap/ExportMapUIHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIHandler.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIHandler.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
package fr.ulr.sammoa.ui.swing.io.exportMap;
+/*
+ * #%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.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -8,7 +31,9 @@
import fr.ulr.sammoa.persistence.Campaign;
import fr.ulr.sammoa.persistence.RouteType;
import fr.ulr.sammoa.persistence.Species;
+import fr.ulr.sammoa.persistence.Species2;
import fr.ulr.sammoa.persistence.Strate;
+import fr.ulr.sammoa.persistence.StringRef;
import fr.ulr.sammoa.persistence.StringRefs;
import fr.ulr.sammoa.ui.swing.SammoaDecoratorProvider;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
@@ -84,12 +109,12 @@
campaigns.add(0, null);
model.setCampaigns(campaigns);
- List<String> speciesTypes = getReferentialService().getAllSpeciesTypes();
- model.setSpeciesTypes(StringRefs.toRefs(speciesTypes));
+// List<String> speciesTypes = getReferentialService().getAllSpeciesTypes();
+// model.setSpeciesTypes(StringRefs.toRefs(speciesTypes));
+//
+// List<Species> species = getReferentialService().getAllSpecies();
+// model.setSpecies(species);
- List<Species> species = getReferentialService().getAllSpecies();
- model.setSpecies(species);
-
model.setRouteTypes(Lists.newArrayList(RouteType.values()));
String campaignId = context.getCampaignId();
@@ -114,9 +139,14 @@
Campaign newValue = (Campaign) evt.getNewValue();
onSelectedCampaignChanged(newValue);
} else if (ExportMapUIModel.PROPERTY_STRATES.equals(evt.getPropertyName())) {
-
List<Strate> newValue = (List<Strate>) evt.getNewValue();
onStratesChanged(newValue);
+ } else if (ExportMapUIModel.PROPERTY_SPECIES.equals(evt.getPropertyName())) {
+ List<Species> newValue = (List<Species>) evt.getNewValue();
+ onSpeciesChanged(newValue);
+ } else if (ExportMapUIModel.PROPERTY_SPECIES_TYPES.equals(evt.getPropertyName())) {
+ List<StringRef> newValue = (List<StringRef>) evt.getNewValue();
+ onSpeciesTypesChanged(newValue);
}
}
});
@@ -159,6 +189,20 @@
ui.getStrateFilterListHeader().setData(newValue);
}
+ protected void onSpeciesChanged(List<Species> newValue) {
+ if (logger.isInfoEnabled()) {
+ logger.info("New species to use: {}", newValue.size());
+ }
+ ui.getSpeciesFilterListHeader().setData(newValue);
+ }
+
+ protected void onSpeciesTypesChanged(List<StringRef> newValue) {
+ if (logger.isInfoEnabled()) {
+ logger.info("New species types to use: {}", newValue.size());
+ }
+ ui.getSpeciesTypeFilterListHeader().setData(newValue);
+ }
+
protected void onSelectedCampaignChanged(Campaign newCampaign) {
// reset strates,...
@@ -170,6 +214,8 @@
ExportMapUIModel model = ui.getModel();
model.setSelectedStrates(Collections.<Strate>emptyList());
+ model.setSelectedSpecies(Collections.<Species>emptyList());
+ model.setSelectedSpeciesTypes(Collections.<StringRef>emptyList());
List<Strate> strates;
if (newCampaign == null) {
@@ -181,6 +227,20 @@
logger.debug("New strates: {}", strates.size());
}
model.setStrates(strates);
+
+ List<Species> species;
+ List<StringRef> speciesTypes;
+
+ if (newCampaign == null) {
+ species = Collections.emptyList();
+ speciesTypes = Collections.emptyList();
+
+ } else {
+ species = getReferentialService().getAllSpecies(newCampaign);
+ speciesTypes = StringRefs.toRefs(Species2.toSpeciesTypes(species));
+ }
+ model.setSpecies(species);
+ model.setSpeciesTypes(speciesTypes);
}
public void close() {
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIHandler.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
package fr.ulr.sammoa.ui.swing.io.exportMap;
+/*
+ * #%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.google.common.collect.Lists;
import fr.ulr.sammoa.application.map.ExportMapModel;
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanel.css
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanel.css 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanel.css 2012-08-03 14:54:11 UTC (rev 355)
@@ -2,7 +2,7 @@
* #%L
* SAMMOA :: UI Swing
* $Id$
- * $HeadURL:$
+ * $HeadURL$
* %%
* Copyright (C) 2012 UMS 3462, Code Lutin
* %%
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanel.css
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
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-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -3,7 +3,7 @@
* #%L
* SAMMOA :: UI Swing
* $Id$
- * $HeadURL:$
+ * $HeadURL$
* %%
* Copyright (C) 2012 UMS 3462, Code Lutin
* %%
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ForceSelectionSelectionModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ForceSelectionSelectionModel.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ForceSelectionSelectionModel.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -3,7 +3,7 @@
* SAMMOA :: UI Swing
*
* $Id$
- * $HeadURL: http://svn.forge.codelutin.com/svn/sammoa/trunk/sammoa-ui-swing/src/main/ja… $
+ * $HeadURL$
* %%
* Copyright (C) 2012 UMS 3462, Code Lutin
* %%
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ForceSelectionSelectionModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -3,7 +3,7 @@
* SAMMOA :: UI Swing
* *
* $Id$
- * $HeadURL: http://svn.forge.codelutin.com/svn/sammoa/trunk/sammoa-ui-swing/src/main/ja… $
+ * $HeadURL$
* %%
* Copyright (C) 2012 UMS 3462, Code Lutin
* %%
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/ObservationTableModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -3,7 +3,7 @@
* SAMMOA :: UI Swing
* *
* $Id$
- * $HeadURL: http://svn.forge.codelutin.com/svn/sammoa/trunk/sammoa-ui-swing/src/main/ja… $
+ * $HeadURL$
* %%
* Copyright (C) 2012 UMS 3462, Code Lutin
* %%
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/RouteTableModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextEditableCellAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextEditableCellAction.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextEditableCellAction.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
package fr.ulr.sammoa.ui.swing.observations.action;
+/*
+ * #%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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextEditableCellAction.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextRowEditableAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextRowEditableAction.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextRowEditableAction.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
package fr.ulr.sammoa.ui.swing.observations.action;
+/*
+ * #%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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToNextRowEditableAction.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousEditableCellAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousEditableCellAction.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousEditableCellAction.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
package fr.ulr.sammoa.ui.swing.observations.action;
+/*
+ * #%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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousEditableCellAction.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousRowEditableAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousRowEditableAction.java 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousRowEditableAction.java 2012-08-03 14:54:11 UTC (rev 355)
@@ -1,4 +1,27 @@
package fr.ulr.sammoa.ui.swing.observations.action;
+/*
+ * #%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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/action/MoveToPreviousRowEditableAction.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/sammoa-ui-swing/src/main/resources/icons/action-accept.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/sammoa-ui-swing/src/main/resources/icons/action-cancel.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Property changes on: trunk/sammoa-ui-swing/src/main/resources/icons/action-fileChooser.png
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/sammoa-ui-swing/src/test/resources/logback-test.xml
===================================================================
--- trunk/sammoa-ui-swing/src/test/resources/logback-test.xml 2012-08-03 14:28:31 UTC (rev 354)
+++ trunk/sammoa-ui-swing/src/test/resources/logback-test.xml 2012-08-03 14:54:11 UTC (rev 355)
@@ -4,7 +4,7 @@
SAMMOA :: Application
$Id$
- $HeadURL: http://svn.forge.codelutin.com/svn/sammoa/trunk/sammoa-ui-swing/src/main/re… $
+ $HeadURL$
%%
Copyright (C) 2012 UMS 3462, Code Lutin
%%
Property changes on: trunk/sammoa-ui-swing/src/test/resources/logback-test.xml
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/src/site/resources/ulr-sammoa-echange-data.svg
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r354 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application/map sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util sammoa-ui-swing/src/main/resources/i18n sammoa-ui-swing/src/main/resources/icons
by tchemit@users.forge.codelutin.com 03 Aug '12
by tchemit@users.forge.codelutin.com 03 Aug '12
03 Aug '12
Author: tchemit
Date: 2012-08-03 16:28:31 +0200 (Fri, 03 Aug 2012)
New Revision: 354
Url: http://forge.codelutin.com/repositories/revision/sammoa/354
Log:
refs #1203: Export SHP (continue ui)
Added:
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx
trunk/sammoa-ui-swing/src/main/resources/icons/action-accept.png
trunk/sammoa-ui-swing/src/main/resources/icons/action-cancel.png
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.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/io/exportMap/ExportMapUIHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java
trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.java 2012-08-03 14:27:36 UTC (rev 353)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/map/ExportMapService.java 2012-08-03 14:28:31 UTC (rev 354)
@@ -30,16 +30,41 @@
}
public void exportEffortsMap(ExportMapModel dataModel) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Start EffortsMap export to " +
+ dataModel.getExportDirectory() + "::" +
+ dataModel.getExportFilename());
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
}
public void exportObservationsMap(ExportMapModel dataModel) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Start ObservationsMap export to " +
+ dataModel.getExportDirectory() + "::" +
+ dataModel.getExportFilename());
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
}
public void exportGeoPointsMap(ExportMapModel dataModel) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Start GeoPointsMap export to " +
+ dataModel.getExportDirectory() + "::" +
+ dataModel.getExportFilename());
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
}
-
-
}
Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css (rev 0)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css 2012-08-03 14:28:31 UTC (rev 354)
@@ -0,0 +1,20 @@
+#exportMapDirectoryFileChooseAction {
+ actionIcon:"fileChooser";
+}
+
+#exportMapDirectoryLbl {
+ text:"sammoa.label.exportMapDirectory";
+}
+
+#exportMapDirectory {
+ text:{model.getExportDirectory().getAbsolutePath()};
+}
+
+#exportMapFilenameLbl {
+ text:"sammoa.label.exportMapFilename";
+}
+
+#exportMapFilename {
+ text:{model.getExportFilename()};
+}
+
Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.css
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx (rev 0)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapLauncherUI.jaxx 2012-08-03 14:28:31 UTC (rev 354)
@@ -0,0 +1,60 @@
+<JPanel layout='{new BorderLayout()}'>
+
+ <import>
+
+ java.awt.BorderLayout
+ java.io.File
+
+ jaxx.runtime.swing.BlockingLayerUI
+
+ static org.nuiton.i18n.I18n._
+ </import>
+
+ <script><![CDATA[
+
+ public ExportMapLauncherUI(ExportMapUIHandler handler) {
+ setContextValue(handler);
+ setContextValue(handler.getModel());
+ }
+ ]]></script>
+
+ <ExportMapUIModel id='model'
+ initializer='getContextValue(ExportMapUIModel.class)'/>
+
+ <ExportMapUIHandler id='handler'
+ initializer='getContextValue(ExportMapUIHandler.class)'/>
+
+ <Table id='body' fill='both' constraints='BorderLayout.CENTER' decorator='boxed'>
+ <!-- export directory-->
+ <row>
+ <cell anchor='west'>
+ <JLabel id='exportMapDirectoryLbl'/>
+ </cell>
+ <cell weightx='1' fill="horizontal">
+ <JTextField id='exportMapDirectory'
+ onKeyReleased='getModel().setExportDirectory(new File(((JTextField)event.getSource()).getText()))'/>
+ </cell>
+ <cell anchor="east">
+ <JButton id="exportMapDirectoryFileChooseAction"
+ onActionPerformed="getHandler().chooseEffortDirectory()"/>
+ </cell>
+ </row>
+ <row>
+ <cell anchor='west'>
+ <JLabel id='exportMapFilenameLbl'/>
+ </cell>
+ <cell fill='horizontal' weightx='1.0' columns='2'>
+ <JTextField id='exportMapFilename'
+ onKeyReleased='model.setExportFilename(((JTextField)event.getSource()).getText())'/>
+ </cell>
+ </row>
+ <row>
+ <cell columns='3' fill="both">
+ <JPanel layout='{new GridLayout(1,2,0,0)}'>
+ <JButton id='cancel'/>
+ <JButton id='start'/>
+ </JPanel>
+ </cell>
+ </row>
+ </Table>
+</JPanel>
\ No newline at end of file
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-03 14:27:36 UTC (rev 353)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUI.jaxx 2012-08-03 14:28:31 UTC (rev 354)
@@ -1,5 +1,5 @@
-<JPanel id='campaignUI' layout='{new BorderLayout()}'
- implements='fr.ulr.sammoa.ui.swing.SammoaUI<ExportMapUIHandler>'>
+<JPanel id='exportMapUI' layout='{new BorderLayout()}'
+ implements='fr.ulr.sammoa.ui.swing.SammoaUI<ExportMapUIHandler>'>
<import>
fr.ulr.sammoa.application.FlightState
@@ -115,30 +115,6 @@
</JScrollPane>
</cell>
</row>
- <!-- export observations filename-->
- <!-- export directory-->
- <!--row>
- <cell anchor='west'>
- <JLabel id='exportDirectoryLbl'/>
- </cell>
- <cell weightx='1' fill="horizontal">
- <JTextField id='exportDirectory' text='{model.getExportDirectory().getAbsolutePath()}'
- onKeyReleased='getModel().setExportDirectory(new File(((JTextField)event.getSource()).getText()))'/>
- </cell>
- <cell anchor="east">
- <JButton id="exportDirectoryFileChooseAction"
- onActionPerformed="getHandler().chooseEffortDirectory()"/>
- </cell>
- </row-->
- <!--row>
- <cell anchor='west'>
- <JLabel id='exportObservationsFilenameLbl'/>
- </cell>
- <cell fill='horizontal' weightx='1.0'>
- <JTextField id='exportObservationsFilename' text='{model.getExportObservationsFilename()}'
- onKeyReleased='model.setExportObservationsFilename(((JTextField)event.getSource()).getText())'/>
- </cell>
- </row-->
<!--export observations -->
<row>
<cell columns='5' fill="both">
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIHandler.java 2012-08-03 14:27:36 UTC (rev 353)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIHandler.java 2012-08-03 14:28:31 UTC (rev 354)
@@ -24,7 +24,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFrame;
import javax.swing.JList;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
@@ -121,8 +128,18 @@
model.setExportEffortsFilename("Efforts");
model.setExportObservationsFilename("Observations");
- model.setExportDirectory(FileUtil.getCurrentDirectory().getAbsoluteFile());
+ model.setExportGeoPointsFilename("GeoPoints");
+ File currentDirectory = FileUtil.getCurrentDirectory();
+ String absolutePath = currentDirectory.getAbsolutePath();
+ if (absolutePath.endsWith(File.separator + ".")) {
+ currentDirectory = new File(absolutePath.substring(0, absolutePath.length() - 2));
+ }
+ if (logger.isInfoEnabled()) {
+ logger.info("Current directory to use: {}", currentDirectory);
+ }
+ model.setExportDirectory(currentDirectory);
+
SwingUtil.fillComboBox(ui.getCampaignCombobox(),
model.getCampaigns(),
model.getSelectedCampaign());
@@ -188,63 +205,169 @@
ExportMapUIModel model = ui.getModel();
- boolean canContinue = askExportFile(
- _("sammoa.title.export.exportEfforts"),
- ExportMapUIModel.PROPERTY_EXPORT_EFFORTS_FILENAME,
- model);
+ Action startAction = new AbstractAction(
+ _("sammoa.action.startExport"),
+ SwingUtil.createActionIcon("accept")) {
- if (canContinue) {
- ExportMapModel dataModel =
- model.toModel(model.getExportEffortsFilename());
+ private static final long serialVersionUID = 1L;
- getExportMapService().exportEffortsMap(dataModel);
- }
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JButton source = (JButton) e.getSource();
+ ExportMapLauncherUI fileChooserUI = SwingUtil.getParentContainer(
+ source, ExportMapLauncherUI.class);
+
+ SammoaUtil.updateBusyState(fileChooserUI, true);
+ try {
+ ExportMapUIModel model = ui.getModel();
+
+ // persist the file name
+ model.setExportEffortsFilename(model.getExportFilename());
+
+ // create export service model
+ ExportMapModel dataModel =
+ model.toModel(model.getExportEffortsFilename());
+
+ // launch export
+ getExportMapService().exportEffortsMap(dataModel);
+
+ } finally {
+
+ SwingUtil.getParentContainer(
+ source, JDialog.class).setVisible(false);
+ }
+ }
+ };
+
+ displayExportLauncher(_("sammoa.title.export.exportEfforts"),
+ model.getExportEffortsFilename(),
+ model,
+ startAction);
}
public void exportObservations() {
ExportMapUIModel model = ui.getModel();
- boolean canContinue = askExportFile(
- _("sammoa.title.export.exportObservations"),
- ExportMapUIModel.PROPERTY_EXPORT_OBSERVATIONS_FILENAME,
- model);
+ Action startAction = new AbstractAction(
+ _("sammoa.action.startExport"),
+ SwingUtil.createActionIcon("accept")) {
- if (canContinue) {
- ExportMapModel dataModel =
- model.toModel(model.getExportObservationsFilename());
+ private static final long serialVersionUID = 1L;
- getExportMapService().exportObservationsMap(dataModel);
- }
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ JButton source = (JButton) e.getSource();
+ ExportMapLauncherUI fileChooserUI = SwingUtil.getParentContainer(
+ source, ExportMapLauncherUI.class);
+
+ try {
+ SammoaUtil.updateBusyState(fileChooserUI, true);
+ ExportMapUIModel model = ui.getModel();
+
+ // persist the file name
+ model.setExportObservationsFilename(model.getExportFilename());
+
+ // create export service model
+ ExportMapModel dataModel =
+ model.toModel(model.getExportObservationsFilename());
+
+ // launch export
+ getExportMapService().exportObservationsMap(dataModel);
+
+ } finally {
+
+ SwingUtil.getParentContainer(
+ source, JDialog.class).setVisible(false);
+ }
+ }
+ };
+ displayExportLauncher(_("sammoa.title.export.exportObservations"),
+ model.getExportObservationsFilename(),
+ model,
+ startAction);
}
public void exportGeoPoints() {
ExportMapUIModel model = ui.getModel();
- boolean canContinue = askExportFile(
- _("sammoa.title.export.exportGeoPoints"),
- ExportMapUIModel.PROPERTY_EXPORT_GEO_POINTS_FILENAME,
- model);
+ Action startAction = new AbstractAction(
+ _("sammoa.action.startExport"),
+ SwingUtil.createActionIcon("accept")) {
- if (canContinue) {
- ExportMapModel dataModel =
- model.toModel(model.getExportGeoPointsFilename());
+ private static final long serialVersionUID = 1L;
- getExportMapService().exportGeoPointsMap(dataModel);
- }
+ @Override
+ public void actionPerformed(ActionEvent e) {
+
+ JButton source = (JButton) e.getSource();
+
+ ExportMapLauncherUI fileChooserUI = SwingUtil.getParentContainer(
+ source, ExportMapLauncherUI.class);
+ SammoaUtil.updateBusyState(fileChooserUI, true);
+ try {
+
+ ExportMapUIModel model = ui.getModel();
+
+ // persist the file name
+ model.setExportGeoPointsFilename(model.getExportFilename());
+
+ // create export service model
+ ExportMapModel dataModel =
+ model.toModel(model.getExportGeoPointsFilename());
+
+ // launch export
+ getExportMapService().exportGeoPointsMap(dataModel);
+
+ } finally {
+
+ SwingUtil.getParentContainer(
+ source, JDialog.class).setVisible(false);
+ }
+ }
+ };
+ displayExportLauncher(_("sammoa.title.export.exportGeoPoints"),
+ model.getExportGeoPointsFilename(),
+ model,
+ startAction);
}
- protected boolean askExportFile(String effortTitle,
- String exportType,
- ExportMapUIModel model) {
- boolean canContinue = false;
+ public ExportMapUIModel getModel() {
+ return ui.getModel();
+ }
- //TODO
- return canContinue;
+ protected void displayExportLauncher(String effortTitle,
+ String defaultFilename,
+ ExportMapUIModel model,
+ Action startAction) {
+
+ model.setExportFilename(defaultFilename);
+ final ExportMapLauncherUI ui = new ExportMapLauncherUI(this);
+
+ JFrame frame = this.ui.getParentContainer(JFrame.class);
+ Action closeAction = new AbstractAction(
+ _("sammoa.action.cancelExport"),
+ SwingUtil.createActionIcon("cancel")) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ ui.getParentContainer(JDialog.class).setVisible(false);
+ }
+ };
+
+ ui.getStart().setAction(startAction);
+ ui.getCancel().setAction(closeAction);
+
+ SammoaUtil.openInDialog(ui,
+ frame,
+ effortTitle,
+ closeAction,
+ new Dimension(550, 150));
}
-
/**
* Remplit le modèle d'une liste graphique avec la liste des entités d'un
* type donné sur un service de persistance donné.
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java 2012-08-03 14:27:36 UTC (rev 353)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/exportMap/ExportMapUIModel.java 2012-08-03 14:28:31 UTC (rev 354)
@@ -49,6 +49,8 @@
public static final String PROPERTY_EXPORT_DIRECTORY = "exportDirectory";
+ public static final String PROPERTY_EXPORT_FILENAME = "exportFilename";
+
public static final String PROPERTY_EXPORT_EFFORTS_FILENAME = "exportEffortsFilename";
public static final String PROPERTY_EXPORT_OBSERVATIONS_FILENAME = "exportObservationsFilename";
@@ -81,9 +83,12 @@
protected File exportDirectory;
+ protected String exportFilename;
+
protected String exportEffortsFilename;
protected String exportObservationsFilename;
+
protected String exportGeoPointsFilename;
public File getExportDirectory() {
@@ -96,6 +101,16 @@
firePropertyChange(PROPERTY_EXPORT_DIRECTORY, oldValue, exportDirectory);
}
+ public String getExportFilename() {
+ return exportFilename;
+ }
+
+ public void setExportFilename(String exportFilename) {
+ String oldValue = this.exportFilename;
+ this.exportFilename = exportFilename;
+ firePropertyChange(PROPERTY_EXPORT_FILENAME, oldValue, exportFilename);
+ }
+
public String getExportEffortsFilename() {
return exportEffortsFilename;
}
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-03 14:27:36 UTC (rev 353)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-08-03 14:28:31 UTC (rev 354)
@@ -36,8 +36,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.swing.*;
-import java.awt.*;
+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 java.awt.Color;
+import java.awt.Component;
+import java.awt.Cursor;
+import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
@@ -55,7 +63,7 @@
private SammoaUtil() {
// never instanciate util class
}
-
+
public static Highlighter newColorHighlighter(HighlightPredicate predicate, Color color) {
return new SammoaColorHighlighter(predicate, color);
}
@@ -91,17 +99,34 @@
throw Throwables.propagate(e);
}
}
-
- public static JDialog openInDialog(JComponent ui, JFrame frame, String title, Action closeAction) {
-
+
+ public static JDialog openInDialog(JComponent ui,
+ JFrame frame,
+ String title,
+ Action closeAction) {
+ return openInDialog(ui, frame, title, closeAction, null);
+ }
+
+ public static JDialog openInDialog(JComponent ui,
+ JFrame frame,
+ String title,
+ Action closeAction,
+ Dimension dim) {
+
JDialog result = new JDialog(frame, false);
result.setTitle(title);
result.add(ui);
result.setResizable(true);
- result.setSize(550, 450);
- JRootPane rootPane = result.getRootPane();
- rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close");
- rootPane.getActionMap().put("close", closeAction);
+ if (dim == null) {
+ result.setSize(550, 450);
+ } else {
+ result.setSize(dim);
+ }
+ if (closeAction != null) {
+ JRootPane rootPane = result.getRootPane();
+ rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close");
+ rootPane.getActionMap().put("close", closeAction);
+ }
result.addWindowListener(new WindowAdapter() {
@Override
@@ -189,4 +214,20 @@
FileUtil.setCurrentDirectory(oldBasedir);
return file == null ? incoming : new File(file);
}
+
+ public static void updateBusyState(JComponent ui, boolean busy) {
+ if (busy) {
+ // ui bloquee
+ if (logger.isDebugEnabled()) {
+ logger.debug("block ui in busy mode");
+ }
+ ui.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ } else {
+ // ui debloquee
+ if (logger.isDebugEnabled()) {
+ logger.debug("unblock ui in none busy mode");
+ }
+ ui.setCursor(Cursor.getDefaultCursor());
+ }
+ }
}
Modified: trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties
===================================================================
--- trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 2012-08-03 14:27:36 UTC (rev 353)
+++ trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 2012-08-03 14:28:31 UTC (rev 354)
@@ -1,10 +1,12 @@
SAMMOA=Sammoa
csv.import.error.unableToReadField=Unable to read value of column '%s' at line %s
+sammo.export.inprogress=Export in progress...
sammoa.about.message=About Sammoa
sammoa.action.about=About
sammoa.action.about.tip=About
sammoa.action.break.tip=Break
sammoa.action.cancel=Cancel
+sammoa.action.cancelExport=Cancel
sammoa.action.choose.export.directory=Accept
sammoa.action.circleback.tip=Circle Back
sammoa.action.close=Close
@@ -35,6 +37,7 @@
sammoa.action.save=Save
sammoa.action.site=Site
sammoa.action.site.tip=Display project site
+sammoa.action.startExport=Start
sammoa.action.startFlight.tip=Start the flight
sammoa.action.stop.tip=Stop
sammoa.action.stopFlight.tip=Stop the flight
@@ -90,6 +93,8 @@
sammoa.label.exportDirectory=Export directory
sammoa.label.exportEffortsFilename=Export filename (Efforts)
sammoa.label.exportGeoPointsFilename=Export filename (GeoPoints)
+sammoa.label.exportMapDirectory=Export directory
+sammoa.label.exportMapFilename=Export filename
sammoa.label.exportObservationsFilename=Export filename (Observations)
sammoa.label.flight=Flight\:
sammoa.label.flight.beginDate=Start
@@ -205,9 +210,9 @@
sammoa.title.about=About Sammoa
sammoa.title.campaign=Campaign
sammoa.title.choose.export.directory=Choose directory where to export maps
-sammoa.title.export.exportEfforts=
-sammoa.title.export.exportGeoPoints=
-sammoa.title.export.exportObservations=
+sammoa.title.export.exportEfforts=Efforts Export
+sammoa.title.export.exportGeoPoints=GPS Points ExportGPS
+sammoa.title.export.exportObservations=Observations Export
sammoa.title.exportshape=Export Maps
sammoa.title.flight=System %1$s - Campaign %2$s - Region %3$s - Flight n°%4$d
sammoa.title.home=Home
Added: trunk/sammoa-ui-swing/src/main/resources/icons/action-accept.png
===================================================================
(Binary files differ)
Property changes on: trunk/sammoa-ui-swing/src/main/resources/icons/action-accept.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/sammoa-ui-swing/src/main/resources/icons/action-cancel.png
===================================================================
(Binary files differ)
Property changes on: trunk/sammoa-ui-swing/src/main/resources/icons/action-cancel.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
1
0
r353 - in trunk: sammoa-application/src/test/resources sammoa-persistence/src/test/resources
by tchemit@users.forge.codelutin.com 03 Aug '12
by tchemit@users.forge.codelutin.com 03 Aug '12
03 Aug '12
Author: tchemit
Date: 2012-08-03 16:27:36 +0200 (Fri, 03 Aug 2012)
New Revision: 353
Url: http://forge.codelutin.com/repositories/revision/sammoa/353
Log:
fix logback config in tests (no DEBUG please :(
Modified:
trunk/sammoa-application/src/test/resources/logback-test.xml
trunk/sammoa-persistence/src/test/resources/logback-test.xml
Modified: trunk/sammoa-application/src/test/resources/logback-test.xml
===================================================================
--- trunk/sammoa-application/src/test/resources/logback-test.xml 2012-08-03 10:06:40 UTC (rev 352)
+++ trunk/sammoa-application/src/test/resources/logback-test.xml 2012-08-03 14:27:36 UTC (rev 353)
@@ -25,7 +25,7 @@
-->
-<configuration debug="true">
+<configuration>
<contextName>SAMMOA</contextName>
@@ -37,9 +37,9 @@
</encoder>
</appender>
- <logger name="fr.ulr.sammoa" level="DEBUG"/>
+ <logger name="fr.ulr.sammoa" level="INFO"/>
- <root level="INFO">
+ <root level="WARN">
<appender-ref ref="CONSOLE"/>
</root>
Modified: trunk/sammoa-persistence/src/test/resources/logback-test.xml
===================================================================
--- trunk/sammoa-persistence/src/test/resources/logback-test.xml 2012-08-03 10:06:40 UTC (rev 352)
+++ trunk/sammoa-persistence/src/test/resources/logback-test.xml 2012-08-03 14:27:36 UTC (rev 353)
@@ -25,7 +25,7 @@
-->
-<configuration debug="true">
+<configuration>
<contextName>SAMMOA</contextName>
@@ -37,9 +37,9 @@
</encoder>
</appender>
- <logger name="fr.ulr.sammoa" level="DEBUG"/>
+ <logger name="fr.ulr.sammoa" level="INFO"/>
- <root level="INFO">
+ <root level="WARN">
<appender-ref ref="CONSOLE"/>
</root>
1
0
r352 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing
by fdesbois@users.forge.codelutin.com 03 Aug '12
by fdesbois@users.forge.codelutin.com 03 Aug '12
03 Aug '12
Author: fdesbois
Date: 2012-08-03 12:06:40 +0200 (Fri, 03 Aug 2012)
New Revision: 352
Url: http://forge.codelutin.com/repositories/revision/sammoa/352
Log:
fixes #1385 : increment effortNumber and observationNumber by flight only
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/FlightDAOImpl.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/ObservationDAOImpl.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteDAOImpl.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/SammoaPersistence.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/FlightService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-08-03 10:06:20 UTC (rev 351)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-08-03 10:06:40 UTC (rev 352)
@@ -28,8 +28,29 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import fr.ulr.sammoa.persistence.*;
+import fr.ulr.sammoa.persistence.AutoSaveListener;
+import fr.ulr.sammoa.persistence.Campaign;
+import fr.ulr.sammoa.persistence.Flight;
+import fr.ulr.sammoa.persistence.FlightDAO;
+import fr.ulr.sammoa.persistence.Observation;
+import fr.ulr.sammoa.persistence.ObservationDAO;
+import fr.ulr.sammoa.persistence.ObservationStatus;
import fr.ulr.sammoa.persistence.Observer;
+import fr.ulr.sammoa.persistence.ObserverPosition;
+import fr.ulr.sammoa.persistence.ObserverPositionDAO;
+import fr.ulr.sammoa.persistence.ObserverPositions;
+import fr.ulr.sammoa.persistence.Observers;
+import fr.ulr.sammoa.persistence.PlatformType;
+import fr.ulr.sammoa.persistence.Position;
+import fr.ulr.sammoa.persistence.Route;
+import fr.ulr.sammoa.persistence.RouteDAO;
+import fr.ulr.sammoa.persistence.RouteType;
+import fr.ulr.sammoa.persistence.SammoaDAOHelper;
+import fr.ulr.sammoa.persistence.SammoaPersistence;
+import fr.ulr.sammoa.persistence.Transect;
+import fr.ulr.sammoa.persistence.TransectDAO;
+import fr.ulr.sammoa.persistence.TransectFlight;
+import fr.ulr.sammoa.persistence.TransectFlightDAO;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.TopiaRuntimeException;
@@ -37,7 +58,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
/**
* Created: 08/06/12
@@ -490,7 +516,7 @@
ObservationDAO dao = SammoaDAOHelper.getObservationDAO(transaction);
- int number = dao.getLastObservationNumber(config.getObservationNumber());
+ int number = dao.getLastObservationNumber(flight);
result = dao.createByNaturalId(number, flight);
result.setObservationTime(beginTime);
@@ -525,8 +551,7 @@
result.setTransectFlight(transectFlight);
- int startNumber = context.getConfig().getEffortNumber();
- int effortNumber = dao.getLastEffortNumber(startNumber);
+ int effortNumber = dao.getLastEffortNumber(flight);
result.setEffortNumber(effortNumber);
return result;
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-03 10:06:20 UTC (rev 351)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-08-03 10:06:40 UTC (rev 352)
@@ -232,22 +232,6 @@
}
/**
- * @return {@link SammoaConfigOption#EFFORT_NUMBER} value
- */
- public Integer getEffortNumber() {
- int result = applicationConfig.getOptionAsInt(SammoaConfigOption.EFFORT_NUMBER.key);
- return result;
- }
-
- /**
- * @return {@link SammoaConfigOption#OBSERVATION_NUMBER} value
- */
- public Integer getObservationNumber() {
- int result = applicationConfig.getOptionAsInt(SammoaConfigOption.OBSERVATION_NUMBER.key);
- return result;
- }
-
- /**
* @return {@link SammoaConfigOption#BACKGROUND_SHAPE_FILE} value
*/
public File getBackgroundShapeFile() {
@@ -407,18 +391,6 @@
"1",
Integer.class
),
- /** The starting value to increment effort number */
- EFFORT_NUMBER("effort.number",
- n_("sammoa.config.effort.number"),
- "1",
- Integer.class
- ),
- /** The starting value to increment observation number */
- OBSERVATION_NUMBER("observation.number",
- n_("sammoa.config.observation.number"),
- "1",
- Integer.class
- ),
/** The backgroud shape file to display the world */
BACKGROUND_SHAPE_FILE("background.shape.file",
n_("sammoa.config.background.shape.file"),
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/FlightDAOImpl.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/FlightDAOImpl.java 2012-08-03 10:06:20 UTC (rev 351)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/FlightDAOImpl.java 2012-08-03 10:06:40 UTC (rev 352)
@@ -38,9 +38,25 @@
public int getLastFlightNumber(int defaultValue) {
- int result = SammoaPersistence.findLastNumber(
- context, Flight.class, Flight.PROPERTY_FLIGHT_NUMBER, defaultValue);
+ int result;
+ String ql = String.format("SELECT max(%1$s) FROM %2$s",
+ Flight.PROPERTY_FLIGHT_NUMBER,
+ FlightImpl.class.getSimpleName()
+ );
+
+ try {
+ Integer queryResult = (Integer) context.findUnique(ql);
+
+ result = queryResult == null ? defaultValue : queryResult + 1;
+
+ if (result < defaultValue) {
+ result = defaultValue;
+ }
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+ }
return result;
}
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/ObservationDAOImpl.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/ObservationDAOImpl.java 2012-08-03 10:06:20 UTC (rev 351)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/ObservationDAOImpl.java 2012-08-03 10:06:40 UTC (rev 352)
@@ -98,11 +98,24 @@
}
- public int getLastObservationNumber(int defaultValue) {
+ public int getLastObservationNumber(Flight flight) {
- int result = SammoaPersistence.findLastNumber(
- context, Observation.class, Observation.PROPERTY_OBSERVATION_NUMBER, defaultValue);
+ int result;
+ String ql = String.format("SELECT max(%1$s) FROM %2$s WHERE %3$s = :flight",
+ Observation.PROPERTY_OBSERVATION_NUMBER,
+ ObservationImpl.class.getSimpleName(),
+ Observation.PROPERTY_FLIGHT
+ );
+
+ try {
+ Integer queryResult = (Integer) context.findUnique(ql, "flight", flight);
+
+ result = queryResult == null ? 1 : queryResult + 1;
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+ }
return result;
}
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteDAOImpl.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteDAOImpl.java 2012-08-03 10:06:20 UTC (rev 351)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/RouteDAOImpl.java 2012-08-03 10:06:40 UTC (rev 352)
@@ -97,11 +97,24 @@
return result;
}
- public int getLastEffortNumber(int defaultValue) {
+ public int getLastEffortNumber(Flight flight) {
- int result = SammoaPersistence.findLastNumber(
- context, Route.class, Route.PROPERTY_EFFORT_NUMBER, defaultValue);
+ int result;
+ String ql = String.format("SELECT max(%1$s) FROM %2$s WHERE %1$s IS NOT NULL AND %3$s = :flight",
+ Route.PROPERTY_EFFORT_NUMBER,
+ RouteImpl.class.getSimpleName(),
+ Route.PROPERTY_FLIGHT
+ );
+
+ try {
+ Integer queryResult = (Integer) context.findUnique(ql, "flight", flight);
+
+ result = queryResult == null ? 1 : queryResult + 1;
+
+ } catch (TopiaException e) {
+ throw new TopiaRuntimeException(e);
+ }
return result;
}
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/SammoaPersistence.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/SammoaPersistence.java 2012-08-03 10:06:20 UTC (rev 351)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/SammoaPersistence.java 2012-08-03 10:06:40 UTC (rev 352)
@@ -32,7 +32,6 @@
import org.nuiton.topia.TopiaRuntimeException;
import org.nuiton.topia.persistence.TopiaEntity;
-import java.util.List;
import java.util.Properties;
/**
@@ -203,34 +202,4 @@
}
}
- static int findLastNumber(TopiaContext context,
- Class<? extends TopiaEntity> entityClass,
- String numberProperty,
- int startNumber) {
-
- Class<? extends TopiaEntity> implClass =
- SammoaDAOHelper.getImplementationClass(entityClass);
-
- int result;
-
- String ql = String.format("SELECT %1$s FROM %2$s WHERE %1$s IS NOT NULL ORDER BY %1$s DESC",
- numberProperty,
- implClass.getSimpleName()
- );
-
- try {
- List<Integer> queryResults = context.find(ql, 0, 1, new Object[]{});
-
- result = queryResults.isEmpty() ? startNumber : queryResults.get(0) + 1;
-
- if (result < startNumber) {
- result = startNumber;
- }
-
- } catch (TopiaException e) {
- throw new TopiaRuntimeException(e);
- }
- return result;
- }
-
}
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-03 10:06:20 UTC (rev 351)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-08-03 10:06:40 UTC (rev 352)
@@ -44,10 +44,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.swing.JComponent;
-import javax.swing.JOptionPane;
-import javax.swing.UIManager;
-import java.awt.Desktop;
+import javax.swing.*;
+import java.awt.*;
import java.io.File;
import java.net.URL;
@@ -241,8 +239,6 @@
helper.addOption(SammoaConfig.SammoaConfigOption.AUDIO_DIRECTORY);
helper.setOptionCallBack("ui");
helper.addOption(SammoaConfig.SammoaConfigOption.FLIGHT_NUMBER);
- helper.addOption(SammoaConfig.SammoaConfigOption.EFFORT_NUMBER);
- helper.addOption(SammoaConfig.SammoaConfigOption.OBSERVATION_NUMBER);
helper.addOption(SammoaConfig.SammoaConfigOption.BACKGROUND_SHAPE_FILE);
helper.setOptionCallBack("ui");
// milliseconds
1
0
r351 - trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations
by fdesbois@users.forge.codelutin.com 03 Aug '12
by fdesbois@users.forge.codelutin.com 03 Aug '12
03 Aug '12
Author: fdesbois
Date: 2012-08-03 12:06:20 +0200 (Fri, 03 Aug 2012)
New Revision: 351
Url: http://forge.codelutin.com/repositories/revision/sammoa/351
Log:
Little issue with new route index fire update : use invokeLater to ensure tableModel size to be correct at that time
Modified:
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java
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-03 10:06:05 UTC (rev 350)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/observations/EffortPanelHandler.java 2012-08-03 10:06:20 UTC (rev 351)
@@ -41,12 +41,12 @@
import fr.ulr.sammoa.ui.swing.SammoaDecoratorProvider;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
import fr.ulr.sammoa.ui.swing.action.CircleBackAction;
+import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler;
+import fr.ulr.sammoa.ui.swing.flight.FlightUIModel;
import fr.ulr.sammoa.ui.swing.observations.action.MoveToNextEditableCellAction;
import fr.ulr.sammoa.ui.swing.observations.action.MoveToNextRowEditableAction;
import fr.ulr.sammoa.ui.swing.observations.action.MoveToPreviousEditableCellAction;
import fr.ulr.sammoa.ui.swing.observations.action.MoveToPreviousRowEditableAction;
-import fr.ulr.sammoa.ui.swing.flight.FlightUIHandler;
-import fr.ulr.sammoa.ui.swing.flight.FlightUIModel;
import fr.ulr.sammoa.ui.swing.util.AbstractRowHighlightPredicate;
import fr.ulr.sammoa.ui.swing.util.SammoaUtil;
import fr.ulr.sammoa.ui.swing.util.TableDataChangeListener;
@@ -68,14 +68,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.swing.AbstractCellEditor;
-import javax.swing.Action;
-import javax.swing.DefaultCellEditor;
-import javax.swing.JButton;
-import javax.swing.JComboBox;
-import javax.swing.JTable;
-import javax.swing.JTextField;
-import javax.swing.ListSelectionModel;
+import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@@ -85,9 +78,7 @@
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Rectangle;
+import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
@@ -122,7 +113,6 @@
this.ui = ui;
}
- @Deprecated
public FlightUIModel getFlightUIModel() {
return SammoaUIContext.getUIContext().getFlightUIHandler().getModel();
}
@@ -545,8 +535,17 @@
}
// Fire on TableModel to update the row (highlighting)
- int index = flightUIModel.indexOfRoutes(route);
- ui.getRouteTableModel().fireTableRowsUpdated(index, index);
+ // invokeLater in case of new route, otherwise the size is not updated yet
+ // in tableModel and an IndexOutOfBounds appears
+ SwingUtilities.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+ Route route = getFlightUIModel().getRouteEditBean();
+ int index = getFlightUIModel().indexOfRoutes(route);
+ ui.getRouteTableModel().fireTableRowsUpdated(index, index);
+ }
+ });
}
}
}
1
0