Sammoa-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- 446 discussions
r575 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort src/site/rst
by fdesbois@users.forge.codelutin.com 12 Sep '12
by fdesbois@users.forge.codelutin.com 12 Sep '12
12 Sep '12
Author: fdesbois
Date: 2012-09-12 16:38:09 +0200 (Wed, 12 Sep 2012)
New Revision: 575
Url: http://forge.codelutin.com/repositories/revision/sammoa/575
Log:
refs #1426 :
- add listener for observation species even during onBoard
- add GPS_DELAY instead of GPS_TIME in export maps
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map/ExportMapService.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
trunk/src/site/rst/import-export.rst
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map/ExportMapService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map/ExportMapService.java 2012-09-12 14:37:52 UTC (rev 574)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map/ExportMapService.java 2012-09-12 14:38:09 UTC (rev 575)
@@ -131,7 +131,7 @@
.doubleColumn("LON", 19, 11) // (geoPoint.longitude)
.doubleColumn("SPEED", 19, 11) // (geoPoint.speed)
.doubleColumn("ALTITUDE", 19, 11) // (geoPoint.altitude)
- .stringColumn("GPS_TIME") // (format(geoPoint.recordTime, "HHmmss"))
+ .integerColumn("GPS_DELAY") // (geoPoint.captureDelay)
.stringColumn("AIRCRAFT") // (route.flight.immatriculation)
.stringColumn("COMMENT") // (route.comment)
.build();
@@ -357,7 +357,7 @@
.doubleColumn("LON", 19, 11) // (geoPoint.longitude)
.doubleColumn("SPEED", 19, 11) // (geoPoint.speed)
.doubleColumn("ALTITUDE", 19, 11) // (geoPoint.altitude)
- .stringColumn("GPS_TIME") // (format(geoPoint.recordTime, "HHmmss"))
+ .integerColumn("GPS_DELAY") // (geoPoint.captureDelay)
.stringColumn("AIRCRAFT") // (flight.immatriculation)
.stringColumn("COMMENT") // (observation.comment)
.build();
@@ -594,6 +594,7 @@
.doubleColumn("LON", 19, 11)
.doubleColumn("SPEED", 19, 11)
.doubleColumn("ALTITUDE", 19, 11)
+ .integerColumn("GPS_DELAY") // (geoPoint.captureDelay)
.build();
Campaign campaign = dataModel.getCampaign();
@@ -678,6 +679,7 @@
record.put("LON", geoPoint.getLongitude());
record.put("SPEED", geoPoint.getSpeed());
record.put("ALTITUDE", geoPoint.getAltitude());
+ record.put("GPS_DELAY", geoPoint.getCaptureDelay());
builder.addValues(record);
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-12 14:37:52 UTC (rev 574)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-12 14:38:09 UTC (rev 575)
@@ -557,6 +557,18 @@
}
});
+ // Used to update map for each Species change, Note that this could be
+ // a heavy coast for onBoard screen
+ getModel().addPropertyChangeListener(
+ FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ onObservationChanged((Observation) evt.getOldValue(),
+ (Observation) evt.getNewValue());
+ }
+ });
+
if (getModel().isValidationMode()) {
getModel().addPropertyChangeListener(
@@ -824,6 +836,20 @@
}
}
+ private void onObservationChanged(Observation oldValue,
+ Observation newValue) {
+
+ if (oldValue != null) {
+ oldValue.removePropertyChangeListener(
+ Observation.PROPERTY_SPECIES, observationSpeciesChangeListener);
+ }
+
+ if (newValue != null) {
+ newValue.addPropertyChangeListener(
+ Observation.PROPERTY_SPECIES, observationSpeciesChangeListener);
+ }
+ }
+
private void onTransectFlightChangedForValidation(TransectFlightModel oldValue,
TransectFlightModel newValue) {
if (oldValue != null) {
@@ -873,15 +899,11 @@
if (oldValue != null) {
oldValue.removePropertyChangeListener(
Observation.PROPERTY_OBSERVATION_TIME, observationTimeChangeListener);
- oldValue.removePropertyChangeListener(
- Observation.PROPERTY_SPECIES, observationSpeciesChangeListener);
}
if (newValue != null) {
newValue.addPropertyChangeListener(
Observation.PROPERTY_OBSERVATION_TIME, observationTimeChangeListener);
- newValue.addPropertyChangeListener(
- Observation.PROPERTY_SPECIES, observationSpeciesChangeListener);
selectRouteByObservation(newValue);
Modified: trunk/src/site/rst/import-export.rst
===================================================================
--- trunk/src/site/rst/import-export.rst 2012-09-12 14:37:52 UTC (rev 574)
+++ trunk/src/site/rst/import-export.rst 2012-09-12 14:38:09 UTC (rev 575)
@@ -201,6 +201,8 @@
geoPoint.speed
- ALTITUDE : Altitude de l'avion à ce point GPS
geoPoint.altitude
+- GPS_DELAY : Délai en secondes depuis la capture GPS
+ geoPoint.captureDelay
Effort
~~~~~~
@@ -361,9 +363,9 @@
* geoPoint.altitude
-- GPS_TIME : Heure d'enregistrement du point (rarement différente de celle du parcours)
+- GPS_DELAY : Délai en secondes depuis la capture GPS (N)
- * format(geoPoint.recordTime, "HHmmss")
+ * geoPoint.captureDelay
- AIRCRAFT : Immatriculation de l'avion
@@ -540,9 +542,9 @@
* geoPoint.altitude
-- GPS_TIME : Heure d'enregistrement du point (rarement différente de celle du parcours)
+- GPS_DELAY : Délai en secondes depuis la capture GPS (N)
- * format(geoPoint.recordTime, "HHmmss")
+ * geoPoint.captureDelay
- AIRCRAFT : Immatriculation de l'avion
1
0
r574 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map sammoa-application/src/main/resources/i18n sammoa-ui-swing/src/main/resources/i18n
by fdesbois@users.forge.codelutin.com 12 Sep '12
by fdesbois@users.forge.codelutin.com 12 Sep '12
12 Sep '12
Author: fdesbois
Date: 2012-09-12 16:37:52 +0200 (Wed, 12 Sep 2012)
New Revision: 574
Url: http://forge.codelutin.com/repositories/revision/sammoa/574
Log:
some labels corrections
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map/ExportMapService.java
trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties
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/SammoaConfig.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-09-12 14:37:34 UTC (rev 573)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/SammoaConfig.java 2012-09-12 14:37:52 UTC (rev 574)
@@ -384,7 +384,7 @@
),
/** The auto commit delay for {@link AutoSaveListener} */
AUTO_COMMIT_DELAY("auto.commit.delay",
- n_("sammoa.config.flight.number"),
+ n_("sammoa.config.autoCommitDelay"),
"30000",
Long.class
),
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map/ExportMapService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map/ExportMapService.java 2012-09-12 14:37:34 UTC (rev 573)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/io/output/map/ExportMapService.java 2012-09-12 14:37:52 UTC (rev 574)
@@ -808,7 +808,7 @@
}
protected String computeObservationId(Flight flight, Observation observation) {
- return "O" + observation.getObservationNumber() + "-" +
+ return "S" + observation.getObservationNumber() + "-" +
flight.getFlightNumber() + "-" +
flight.getSystemId();
}
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-09-12 14:37:34 UTC (rev 573)
+++ trunk/sammoa-application/src/main/resources/i18n/sammoa-application_en_GB.properties 2012-09-12 14:37:52 UTC (rev 574)
@@ -1,12 +1,13 @@
sammoa.config.admin.email=Administrator's email
sammoa.config.application.site.url=Website URL of the application
sammoa.config.application.version=Version of the application
-sammoa.config.audio.compression=
+sammoa.config.audio.compression=Audio compression (possible values \: ULAW)
sammoa.config.audio.recordDelayInSeconds=Delay in seconds between each audio record. This will record multiple files at the same time to avoid too sudden stops. (Warning \: this is not supported by all sound systems)
sammoa.config.audio.sampleRate=Rate for the audio sampling (possible values \: 8000, 11025, 16000, 22050, 44100)
sammoa.config.audio.sampleSizeInBits=Size of bits for the audio sampling (possible values \: 8, 16)
+sammoa.config.autoCommitDelay=Time in milliseconds between each auto save in database
sammoa.config.background.shape.file=Location of the Background shape file
-sammoa.config.backup.directory=BAckup directory where to sotre all data backup
+sammoa.config.backup.directory=Backup directory where to store all data backup
sammoa.config.campaign.directory=Directory where are stored campaign data (maps, flight audio files,...)
sammoa.config.campaign.id=Id of the default campaign to use
sammoa.config.csv.separator=Csv separator caracter to use
@@ -19,23 +20,23 @@
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.license.organizationName=
+sammoa.config.license.organizationName=Name of the organization for license
sammoa.config.log.file=Path for application log file
sammoa.config.system.id=Id of the default system to use
sammoa.config.tmp.directory=Temporary directory used for different task (import, export,...)
-sammoa.config.ui.add=Add
-sammoa.config.ui.begin=Begin
-sammoa.config.ui.centerObservation=Observation from the center place
+sammoa.config.ui.add=Add a new LEG (conditions have changed)
+sammoa.config.ui.begin=Begin the effort on the next transect or restart effort from previous Circle-Back
+sammoa.config.ui.centerObservation=Sighting from the center observer
sammoa.config.ui.circleBack=Start a circle-back
sammoa.config.ui.config=Path for application windows configuration file
-sammoa.config.ui.end=End
-sammoa.config.ui.leftObservation=Observation from the left place
+sammoa.config.ui.end=End the effort
+sammoa.config.ui.leftObservation=Sighting from the left observer
sammoa.config.ui.locale=Application language
-sammoa.config.ui.next=Next
-sammoa.config.ui.rightObservation=Observation from the right place
-sammoa.config.ui.start=Start
-sammoa.config.ui.stop=Stop
-sammoa.config.ui.validObservation=Validate the selected observation
+sammoa.config.ui.next=Next effort will end the current one and begin on the next transect
+sammoa.config.ui.rightObservation=Sighting from the right observer
+sammoa.config.ui.start=Start the flight
+sammoa.config.ui.stop=Stop the flight
+sammoa.config.ui.validObservation=Validate the selected sighting
sammoa.config.ui.validRoute=Validate the selected route
sammoa.config.ui.validTransect=Validate the selected transect
sammoa.dateTimePattern=dd/MM/yyyy HH\:mm\:ss
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-09-12 14:37:34 UTC (rev 573)
+++ trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 2012-09-12 14:37:52 UTC (rev 574)
@@ -4,16 +4,16 @@
sammoa.action.about=About
sammoa.action.about.tip=About
sammoa.action.add=Add
-sammoa.action.add.tip=ADD \: create a new LEG route for the current Transect (the observation conditions have changed)
+sammoa.action.add.tip=ADD \: create a new LEG route for the current Transect (the sighting conditions have changed)
sammoa.action.audioCheck=Audio test
sammoa.action.audioCheck.tip=Audio test
sammoa.action.begin=Begin
sammoa.action.begin.tip=BEGIN \: begin effort to create a new LEG route for the next selected Transect
sammoa.action.cancel=Cancel
sammoa.action.cancelExport=Cancel
-sammoa.action.center.tip=CENTER \: create a new Observation for the navigator's observer
+sammoa.action.center.tip=CENTER \: create a new sighting for the navigator's observer
sammoa.action.choose.export.directory=Accept
-sammoa.action.circleBack.tip=CIRCLE-BACK \: create a CIRCLE_BACK route for this observation as cause
+sammoa.action.circleBack.tip=CIRCLE-BACK \: create a CIRCLE_BACK route for this sighting as cause
sammoa.action.close=Close
sammoa.action.configuration=Configuration
sammoa.action.configuration.tip=Configuration
@@ -26,11 +26,11 @@
sammoa.action.exportEffortsMap=Export Efforts
sammoa.action.exportGeoPointsMap=Export GPS Points
sammoa.action.exportMap=Export Maps
-sammoa.action.exportObservationsMap=Export Observations
+sammoa.action.exportObservationsMap=Export Sightings
sammoa.action.home=Home
sammoa.action.home.tip=Home
sammoa.action.importApplication=Import
-sammoa.action.left.tip=LEFT \: create a new Observation for the observer on the left side
+sammoa.action.left.tip=LEFT \: create a new sighting for the observer on the left side
sammoa.action.loadImportApplicationFile=Load selected import file
sammoa.action.new=New
sammoa.action.next=Next
@@ -40,11 +40,11 @@
sammoa.action.quitExportMaps=Quit
sammoa.action.quitImportApplication=Quit
sammoa.action.reload.actions=Reload actions
-sammoa.action.reload.audio=Relad Audio device
+sammoa.action.reload.audio=Reload Audio device
sammoa.action.reload.gps=Reload GPS device
sammoa.action.reload.home=Reload home screen
sammoa.action.reload.ui=Reload sammoa ui
-sammoa.action.right.tip=RIGHT \: create a new Observation for the observer on the right side
+sammoa.action.right.tip=RIGHT \: create a new sighting for the observer on the right side
sammoa.action.save=Save
sammoa.action.site=Site
sammoa.action.site.tip=Display project site
@@ -53,14 +53,14 @@
sammoa.action.startAudio.tip=Start audio
sammoa.action.startExport=Start
sammoa.action.stop=Stop flight
-sammoa.action.stop.tip=STOP \: stop the flight. No other actions on routes and observations could be done after stop.
+sammoa.action.stop.tip=STOP \: stop the flight. No other actions on routes and sightings could be done after stop.
sammoa.action.stopAudio.tip=Stop audio
-sammoa.action.validObservation=Observation
-sammoa.action.validObservation.tip=Validate the selected observation
+sammoa.action.validObservation=Sighting
+sammoa.action.validObservation.tip=Validate the selected sighting
sammoa.action.validRoute=Route
-sammoa.action.validRoute.tip=Validate the selected route and all its observations
+sammoa.action.validRoute.tip=Validate the selected route and all its sightings
sammoa.action.validTransect=Transect
-sammoa.action.validTransect.tip=Validate the selected transect and all its routes and observations
+sammoa.action.validTransect.tip=Validate the selected transect and all its routes and sightings
sammoa.action.validation=Validation
sammoa.config.category.applications=Application
sammoa.config.category.applications.description=Application
@@ -110,7 +110,7 @@
sammoa.importApplication.flightTable.column.toTreat.tip=Select the flight to import it
sammoa.info.importApplication.importfile.loaded.on.existingCampaign=Import an existing campaign %s, please choose which flights of the following list to import
sammoa.info.importApplication.importfile.loaded.on.newCampaign=Import a new campaign %s, all the flights of the following list will be imported
-sammoa.info.importApplication.no.importfile.loaded=No import file loaded, choose an file to import then press the 'load import file' button
+sammoa.info.importApplication.no.importfile.loaded=No import file loaded, choose a file to import then press the 'load import file' button
sammoa.inputDialog.flightNumber.error.lessThanNextFlightNumber=The flight number can't be less than %d
sammoa.inputDialog.flightNumber.error.notANumber=The flight number must be a valid integer
sammoa.inputDialog.flightNumber.message=Choose the flight number
@@ -181,7 +181,7 @@
sammoa.observation.observations.center=Center
sammoa.observation.observations.left=Left
sammoa.observation.observations.right=Right
-sammoa.observation.title=<html><b>Observation</b></html>
+sammoa.observation.title=<html><b>Sighting</b></html>
sammoa.observationCondition.title=<html><b>Conditions</b></html>
sammoa.observations.observationTable.column.age=Age
sammoa.observations.observationTable.column.age.tip=Age
@@ -263,7 +263,7 @@
sammoa.title.choose.export.directory=Choose directory where to export maps
sammoa.title.export.exportEfforts=Efforts Export
sammoa.title.export.exportGeoPoints=GPS Points ExportGPS
-sammoa.title.export.exportObservations=Observations Export
+sammoa.title.export.exportObservations=Sightings Export
sammoa.title.exportApplication=Application Export
sammoa.title.exportshape=Export Maps
sammoa.title.flight=System %1$s - Campaign %2$s - Region %3$s - Flight n°%4$d
@@ -278,7 +278,7 @@
sammoa.validator.campaign.endDate.required=The end date must be defined
sammoa.validator.campaign.region.required=The region must be set
sammoa.validator.campaign.uniqueKey=The campaign code '%1$s' already exists for the region '%2$s'
-sammoa.validator.observation.age.unkownValue=The age must be \: J for "juvénile", I for "immature", A for "adulte" and M for mixed groups
+sammoa.validator.observation.age.unkownValue=The age must be \: J for "juvenile", I for "immature", A for "adult" and M for mixed groups
sammoa.validator.observation.behaviour.unkownValue=The behaviour must be one of this value \: SW (normal), MI (milling), BR (breaching), LO (logging), FE (feeding), FA (feeding aggregation), SB (following boat), OT (other)
sammoa.validator.observation.cue.unkownValue=The cue must be between 2 and 9 or U for underwater and A for surface
sammoa.validator.observation.decAngle.invalidRange=The angle must be between %1$s and %2$s degrees or for the band \: 1 (in the band), 2 (outside the band), 3 (put in the band)
1
0
r573 - trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps
by fdesbois@users.forge.codelutin.com 12 Sep '12
by fdesbois@users.forge.codelutin.com 12 Sep '12
12 Sep '12
Author: fdesbois
Date: 2012-09-12 16:37:34 +0200 (Wed, 12 Sep 2012)
New Revision: 573
Url: http://forge.codelutin.com/repositories/revision/sammoa/573
Log:
little improvement, change state on GPS stop
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-09-12 11:52:18 UTC (rev 572)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-09-12 14:37:34 UTC (rev 573)
@@ -127,6 +127,12 @@
timer.cancel();
timer = null;
}
+ if (state == DeviceState.RUNNING) {
+ setState(DeviceState.READY, null);
+
+ } else if (state == DeviceState.ERROR) {
+ setState(DeviceState.UNAVAILABLE, null);
+ }
}
@Override
1
0
12 Sep '12
Author: fdesbois
Date: 2012-09-12 13:52:18 +0200 (Wed, 12 Sep 2012)
New Revision: 572
Url: http://forge.codelutin.com/repositories/revision/sammoa/572
Log:
fixes #1426 :
- manage update on map for observation changed (time and species)
- add label support
- improve GPS currentLocation behavior with captureDelay
- improve FlightController, some doubloons were created on currentLocation retrieval
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerOnBoard.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -40,6 +40,8 @@
import fr.ulr.sammoa.persistence.Flights;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.persistence.GeoPointDAO;
+import fr.ulr.sammoa.persistence.GeoPointImpl;
+import fr.ulr.sammoa.persistence.GeoPoints;
import fr.ulr.sammoa.persistence.Observation;
import fr.ulr.sammoa.persistence.ObservationDAO;
import fr.ulr.sammoa.persistence.ObservationStatus;
@@ -62,6 +64,7 @@
import fr.ulr.sammoa.persistence.TransectFlights;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
@@ -448,6 +451,73 @@
return result;
}
+ public GeoPoint getGeoPoint(Flight flight,
+ Date date) {
+
+ TopiaContext tx = beginTransaction();
+ try {
+
+ List<GeoPoint> geoPoints = getFlightGeoPoints(tx, flight);
+
+ GeoPoint result = getGeoPoint(tx, flight, geoPoints, date);
+ return result;
+
+ } catch (TopiaException ex) {
+ throw new TopiaRuntimeException(ex);
+ } finally {
+ endTransaction(tx);
+ }
+ }
+
+ public GeoPoint getGeoPoint(TopiaContext tx,
+ Flight flight,
+ List<GeoPoint> geoPoints,
+ Date date) throws TopiaException {
+
+ DateTime newTime = Dates.toDateTime(date);
+
+ // Retrieve the appropriate location
+ GeoPoint location = GeoPoints.getClosestPoint(geoPoints, date);
+ DateTime locationTime = Dates.toDateTime(location.getRecordTime());
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Find locationTime %1$tH:%1$tM:%1$tS.%1$tL",
+ locationTime.toDate())
+ );
+ }
+
+ GeoPoint result;
+
+ // Create a new location if no one is available for the newTime
+ if (!locationTime.isEqual(newTime)) {
+
+ result = new GeoPointImpl(location.getLatitude(), location.getLongitude());
+ result.setSpeed(location.getSpeed());
+ result.setAltitude(location.getAltitude());
+
+ int captureDelay = Dates
+ .toInterval(locationTime, newTime)
+ .toDuration()
+ .toStandardSeconds()
+ .getSeconds();
+
+ result.setCaptureDelay(captureDelay);
+
+ result.setFlight(flight);
+ result.setRecordTime(newTime.toDate());
+ SammoaDAOHelper.getGeoPointDAO(tx).create(result);
+ geoPoints.add(result);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Create a new GeoPoint : {}", result);
+ }
+
+ } else {
+ result = location;
+ }
+ return result;
+ }
+
public List<GeoPoint> getFlightGeoPoints(Flight flight) {
TopiaContext transaction = beginTransaction();
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/BaseGpsHandler.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -28,11 +28,14 @@
import fr.ulr.sammoa.application.device.DeviceStateEvent;
import fr.ulr.sammoa.application.device.DeviceStateListener;
import fr.ulr.sammoa.application.device.DeviceTechnicalException;
+import fr.ulr.sammoa.persistence.Dates;
import fr.ulr.sammoa.persistence.GeoPoint;
+import fr.ulr.sammoa.persistence.GeoPointImpl;
import fr.ulr.sammoa.persistence.GeoPoints;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Date;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
@@ -156,6 +159,44 @@
return gpsLocationListeners;
}
+ @Override
+ public GeoPoint getCurrentLocation() {
+
+ GeoPoint lastLocation = getLastLocation();
+
+ Date currentDate = getDate();
+
+ GeoPoint result = new GeoPointImpl(lastLocation.getLatitude(), lastLocation.getLongitude());
+ result.setAltitude(lastLocation.getAltitude());
+ result.setSpeed(lastLocation.getSpeed());
+ result.setRecordTime(currentDate);
+
+ if (lastLocation.getRecordTime() != null) {
+ long captureDelay = Dates
+ .toInterval(lastLocation.getRecordTime(), currentDate)
+ .toDuration()
+ .getStandardSeconds();
+ result.setCaptureDelay((int) captureDelay);
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("CaptureDelay = {} for GeoPoint {}", captureDelay, result);
+ }
+ }
+
+ if (logger.isWarnEnabled() && GeoPoints.isCoordinatesEmpty(result)) {
+ logger.warn("Retrieve a location without any coordinates : {}", result);
+ }
+ return result;
+ }
+
+ protected Date getDate() {
+ // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp
+ Date result = Dates.newDateWithoutMillis();
+ return result;
+ }
+
+ protected abstract GeoPoint getLastLocation();
+
public void setState(DeviceState state, DeviceTechnicalException error) {
DeviceState oldValue = getState();
this.state = state;
@@ -220,7 +261,7 @@
nbFailures = 0;
}
- location.setCaptureDelay(nbFailures * config.getCheckPeriod());
+// location.setCaptureDelay(nbFailures * config.getCheckPeriod());
// Data is unavailable
if (GeoPoints.isCoordinatesEmpty(location) || sameLocation && nbFailures >= nbFailuresMax) {
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/FakeGpsHandler.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -26,14 +26,12 @@
import fr.ulr.sammoa.application.device.DeviceState;
import fr.ulr.sammoa.application.device.DeviceTechnicalException;
-import fr.ulr.sammoa.persistence.Dates;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.persistence.GeoPointImpl;
import fr.ulr.sammoa.persistence.GeoPoints;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Date;
import java.util.Random;
/**
@@ -130,24 +128,37 @@
}
@Override
- public GeoPoint getCurrentLocation() {
+ protected GeoPoint getLastLocation() {
GeoPoint result;
if (currentLocation == null) {
result = new GeoPointImpl(GeoPoints.EMPTY_COORDINATE, GeoPoints.EMPTY_COORDINATE);
result.setRecordTime(getDate());
-
- } else if (currentLocation.getTopiaId() != null) {
- result = new GeoPointImpl(currentLocation.getLatitude(), currentLocation.getLongitude());
- result.setAltitude(currentLocation.getAltitude());
- result.setSpeed(currentLocation.getSpeed());
- result.setRecordTime(getDate());
-
} else {
result = currentLocation;
}
return result;
}
+ //
+// @Override
+// public GeoPoint getCurrentLocation() {
+// GeoPoint result;
+// if (currentLocation == null) {
+// result = new GeoPointImpl(GeoPoints.EMPTY_COORDINATE, GeoPoints.EMPTY_COORDINATE);
+// result.setRecordTime(getDate());
+//
+// } else if (currentLocation.getTopiaId() != null) {
+// result = new GeoPointImpl(currentLocation.getLatitude(), currentLocation.getLongitude());
+// result.setAltitude(currentLocation.getAltitude());
+// result.setSpeed(currentLocation.getSpeed());
+// result.setRecordTime(getDate());
+//
+// } else {
+// result = currentLocation;
+// }
+// return result;
+// }
+
protected class GpsPointGenerator implements Runnable {
@Override
@@ -179,9 +190,4 @@
}
}
- protected Date getDate() {
- Date result = Dates.newDateWithoutMillis();
- return result;
- }
-
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/gps/GpsHandlerGpsylon.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -27,7 +27,6 @@
import fr.ulr.sammoa.application.device.DeviceState;
import fr.ulr.sammoa.application.device.DeviceTechnicalException;
-import fr.ulr.sammoa.persistence.Dates;
import fr.ulr.sammoa.persistence.GeoPoint;
import fr.ulr.sammoa.persistence.GeoPointImpl;
import fr.ulr.sammoa.persistence.GeoPoints;
@@ -62,6 +61,8 @@
protected GPSPosition lastPosition;
+ protected Date lastPositionDate;
+
protected float lastAltitude;
protected float lastSpeed;
@@ -156,23 +157,12 @@
}
@Override
- public GeoPoint getCurrentLocation() {
+ protected GeoPoint getLastLocation() {
if (logger.isTraceEnabled()) {
logger.trace("Ask lastPosition = {}", lastPosition);
}
-// if (!Objects.equal(lastPosition, lastSendPosition) && lastPosition != null) {
-//
-// result = new GeoPointImpl(lastPosition.getLatitude(), lastPosition.getLongitude());
-// result.setAltitude(lastAltitude);
-// result.setSpeed(lastSpeed);
-// // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp
-// result.setRecordTime(new Date());
-//
-// lastSendPosition = lastPosition;
-// }
-
double latitude = lastPosition != null
? lastPosition.getLatitude()
: GeoPoints.EMPTY_COORDINATE;
@@ -184,14 +174,49 @@
GeoPoint result = new GeoPointImpl(latitude, longitude);
result.setAltitude(lastAltitude);
result.setSpeed(lastSpeed);
- result.setRecordTime(getDate());
+ result.setRecordTime(lastPositionDate);
- if (logger.isWarnEnabled() && lastPosition == null) {
- logger.warn("Retrieve a location without any coordinates : {}", result);
- }
return result;
}
+ //
+// @Override
+// public GeoPoint getCurrentLocation() {
+//
+// if (logger.isTraceEnabled()) {
+// logger.trace("Ask lastPosition = {}", lastPosition);
+// }
+//
+//// if (!Objects.equal(lastPosition, lastSendPosition) && lastPosition != null) {
+////
+//// result = new GeoPointImpl(lastPosition.getLatitude(), lastPosition.getLongitude());
+//// result.setAltitude(lastAltitude);
+//// result.setSpeed(lastSpeed);
+//// // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp
+//// result.setRecordTime(new Date());
+////
+//// lastSendPosition = lastPosition;
+//// }
+//
+// double latitude = lastPosition != null
+// ? lastPosition.getLatitude()
+// : GeoPoints.EMPTY_COORDINATE;
+//
+// double longitude = lastPosition != null
+// ? lastPosition.getLongitude()
+// : GeoPoints.EMPTY_COORDINATE;
+//
+// GeoPoint result = new GeoPointImpl(latitude, longitude);
+// result.setAltitude(lastAltitude);
+// result.setSpeed(lastSpeed);
+// result.setRecordTime(getDate());
+//
+// if (logger.isWarnEnabled() && lastPosition == null) {
+// logger.warn("Retrieve a location without any coordinates : {}", result);
+// }
+// return result;
+// }
+
@Override
protected DeviceTechnicalException onError(GeoPoint location) {
@@ -217,18 +242,18 @@
if (GeoPoints.isCoordinatesEmpty(location)) {
- result = new DeviceTechnicalException(this,
- "GPS is not ready, turn it on or wait for it to find satellites");
+ result = new DeviceTechnicalException(
+ this, "GPS is not ready, turn it on or wait for it to find satellites");
} else {
if (lastNumberSatellites == 0) {
- result = new DeviceTechnicalException(this,
- "GPS signal lost, there is no available satellite found");
+ result = new DeviceTechnicalException(
+ this, "GPS signal lost, there is no available satellite found");
} else {
- result = new DeviceTechnicalException(this,
- "GPS signal lost, please check the connection port");
+ result = new DeviceTechnicalException(
+ this, "GPS signal lost, please check the connection port");
}
}
}
@@ -257,13 +282,13 @@
close();
super.finalize();
}
+//
+// protected Date getDate() {
+// // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp
+// Date result = Dates.newDateWithoutMillis();
+// return result;
+// }
- protected Date getDate() {
- // FIXME-fdesbois-2012-07-02 : ensure time with GPS value and not system timestamp
- Date result = Dates.newDateWithoutMillis();
- return result;
- }
-
/**
* Si l'on recoit des evenements, c'est que le gps fonctionne.
* Il sont envoyé par le traitement des flux NMEA et propagé par le
@@ -297,6 +322,7 @@
}
if (GPSDataProcessor.LOCATION.equals(property)) {
+ lastPositionDate = getDate();
lastPosition = (GPSPosition) evt.getNewValue();
} else if (GPSDataProcessor.ALTITUDE.equals(property)) {
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerOnBoard.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerOnBoard.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerOnBoard.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -25,6 +25,7 @@
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import fr.ulr.sammoa.application.device.DeviceManager;
import fr.ulr.sammoa.application.device.audio.AudioRecorder;
import fr.ulr.sammoa.application.device.gps.GpsHandler;
@@ -38,8 +39,12 @@
import fr.ulr.sammoa.persistence.TransectFlight;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
+import java.util.Date;
+import java.util.Map;
/**
* Created: 21/08/12
@@ -48,6 +53,11 @@
*/
public class FlightControllerOnBoard extends BaseFlightController implements GpsLocationListener {
+ /** Logger. */
+ private static final Logger logger = LoggerFactory.getLogger(FlightControllerOnBoard.class);
+
+ protected Map<Date, GeoPoint> geoPoints = Maps.newHashMap();
+
@Override
public <T extends DeviceManager> void openDeviceManager(Class<T> deviceManager) {
boolean autoStart = initialized && isRunning();
@@ -73,6 +83,10 @@
super.init(flight);
+ geoPoints = Maps.newHashMap(Maps.uniqueIndex(
+ service.getFlightGeoPoints(flight), GeoPoints.toDate())
+ );
+
initCurrentRoute(service.getLastUnfinishedRoute(flight));
if (isRunning()) {
@@ -108,18 +122,25 @@
@Override
public void locationChanged(GpsLocationEvent event) {
GeoPoint newLocation = event.getNewValue();
- if (!GeoPoints.isCoordinatesEmpty(newLocation) && newLocation.getTopiaId() == null) {
+ GeoPoint existLocation = geoPoints.get(newLocation.getRecordTime());
+ if (existLocation == null) {
newLocation.setFlight(flight);
persistence.delayEntityCreation(newLocation);
+ geoPoints.put(newLocation.getRecordTime(), newLocation);
}
}
@Override
protected GeoPoint getLocation(TopiaContext tx) throws TopiaException {
- GeoPoint result = getGpsHandler().getCurrentLocation();
- result.setFlight(flight);
- if (result.getTopiaId() == null) {
- SammoaDAOHelper.getGeoPointDAO(tx).create(result);
+ GeoPoint gpsLocation = getGpsHandler().getCurrentLocation();
+ GeoPoint result = geoPoints.get(gpsLocation.getRecordTime());
+ if (result == null) {
+ gpsLocation.setFlight(flight);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Create a GeoPoint {}", gpsLocation);
+ }
+ result = SammoaDAOHelper.getGeoPointDAO(tx).create(gpsLocation);
+ geoPoints.put(result.getRecordTime(), result);
}
return result;
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -30,11 +30,8 @@
import fr.ulr.sammoa.persistence.Dates;
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.persistence.GeoPoint;
-import fr.ulr.sammoa.persistence.GeoPointImpl;
-import fr.ulr.sammoa.persistence.GeoPoints;
import fr.ulr.sammoa.persistence.Route;
import fr.ulr.sammoa.persistence.Routes;
-import fr.ulr.sammoa.persistence.SammoaDAOHelper;
import fr.ulr.sammoa.persistence.TransectFlight;
import fr.ulr.sammoa.persistence.TransectFlights;
import org.joda.time.DateTime;
@@ -85,8 +82,6 @@
Preconditions.checkNotNull(currentRoute, "You must set the current route to retrieve location");
Preconditions.checkState(!geoPoints.isEmpty(), "No geoPoints available");
- GeoPoint result;
-
if (logger.isDebugEnabled()) {
logger.debug(String.format("Get location after startTime %1$tH:%1$tM:%1$tS.%1$tL (audio position = %2$d)",
getAudioReader().getStartDate(),
@@ -111,42 +106,44 @@
}
// Retrieve the appropriate location
- GeoPoint location = GeoPoints.getClosestPoint(geoPoints, newTime.toDate());
- DateTime locationTime = Dates.toDateTime(location.getRecordTime());
+ GeoPoint result = service.getGeoPoint(tx, flight, geoPoints, newTime.toDate());
- if (logger.isDebugEnabled()) {
- logger.debug(String.format("Find locationTime %1$tH:%1$tM:%1$tS.%1$tL",
- locationTime.toDate())
- );
- }
-
- // Create a new location if no one is available for the newTime
- if (!locationTime.isEqual(newTime)) {
-
- result = new GeoPointImpl(location.getLatitude(), location.getLongitude());
- result.setSpeed(location.getSpeed());
- result.setAltitude(location.getAltitude());
-
- int captureDelay = Dates
- .toInterval(locationTime, newTime)
- .toDuration()
- .toStandardSeconds()
- .getSeconds();
-
- result.setCaptureDelay(captureDelay);
-
- result.setFlight(flight);
- result.setRecordTime(newTime.toDate());
- SammoaDAOHelper.getGeoPointDAO(tx).create(result);
- geoPoints.add(result);
-
- if (logger.isDebugEnabled()) {
- logger.debug("Create a new GeoPoint : {}", result);
- }
-
- } else {
- result = location;
- }
+// GeoPoint location = GeoPoints.getClosestPoint(geoPoints, newTime.toDate());
+// DateTime locationTime = Dates.toDateTime(location.getRecordTime());
+//
+// if (logger.isDebugEnabled()) {
+// logger.debug(String.format("Find locationTime %1$tH:%1$tM:%1$tS.%1$tL",
+// locationTime.toDate())
+// );
+// }
+//
+// // Create a new location if no one is available for the newTime
+// if (!locationTime.isEqual(newTime)) {
+//
+// result = new GeoPointImpl(location.getLatitude(), location.getLongitude());
+// result.setSpeed(location.getSpeed());
+// result.setAltitude(location.getAltitude());
+//
+// int captureDelay = Dates
+// .toInterval(locationTime, newTime)
+// .toDuration()
+// .toStandardSeconds()
+// .getSeconds();
+//
+// result.setCaptureDelay(captureDelay);
+//
+// result.setFlight(flight);
+// result.setRecordTime(newTime.toDate());
+// SammoaDAOHelper.getGeoPointDAO(tx).create(result);
+// geoPoints.add(result);
+//
+// if (logger.isDebugEnabled()) {
+// logger.debug("Create a new GeoPoint : {}", result);
+// }
+//
+// } else {
+// result = location;
+// }
return result;
}
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -26,7 +26,6 @@
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
@@ -67,21 +66,14 @@
return result;
}
- public static List<GeoPoint> retainsValidCoordinates(Iterable<GeoPoint> input) {
- List<GeoPoint> result = FluentIterable.from(input)
- .filter(Predicates.not(withCoordinatesEmpty()))
- .toImmutableList();
- return result;
- }
-
public static boolean isCoordinatesEmpty(GeoPoint geoPoint) {
return geoPoint.getLatitude() == GeoPoints.EMPTY_COORDINATE
&& geoPoint.getLongitude() == GeoPoints.EMPTY_COORDINATE;
}
- public static Predicate<GeoPoint> withCoordinatesEmpty() {
- return IS_COORDINATES_EMPTY_PREDICATE;
- }
+// public static Predicate<GeoPoint> withCoordinatesEmpty() {
+// return IS_COORDINATES_EMPTY_PREDICATE;
+// }
public static Function<GeoPoint, Date> toDate() {
return TO_DATE_FUNCTION;
@@ -117,14 +109,14 @@
}
};
- private static Predicate<GeoPoint> IS_COORDINATES_EMPTY_PREDICATE = new Predicate<GeoPoint>() {
+// private static Predicate<GeoPoint> IS_COORDINATES_EMPTY_PREDICATE = new Predicate<GeoPoint>() {
+//
+// @Override
+// public boolean apply(GeoPoint input) {
+// return isCoordinatesEmpty(input);
+// }
+// };
- @Override
- public boolean apply(GeoPoint input) {
- return isCoordinatesEmpty(input);
- }
- };
-
private static class WithDatePredicate implements Predicate<GeoPoint> {
protected Date date;
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Observations.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -53,9 +53,20 @@
}
public static Iterable<Date> toDates(Iterable<Observation> observations) {
- return Iterables.transform(observations, TO_DATE_FUNCTION);
+ return Iterables.transform(observations, toDate());
}
+ public static String toLabel(Observation observation) {
+ Species species = observation.getSpecies();
+ return (species != null ? species.getCode() : "") + " (S" + observation.getObservationNumber() + ")";
+ }
+
+ public static GeoPoint toGeoPoint(Observation observation,
+ Iterable<GeoPoint> geoPoints) {
+ Date date = observation.getObservationTime();
+ return Iterables.find(geoPoints, GeoPoints.withDate(date), GeoPoints.newEmptyGeoPoint(date));
+ }
+
public static Iterable<Observation> filterInRoute(Iterable<Observation> observations,
Route route,
Iterable<Route> routes,
@@ -172,6 +183,18 @@
return result;
}
+ public static Function<Observation, GeoPoint> toGeoPoint(final Iterable<GeoPoint> geoPoints) {
+ return new ToGeoPointFunction(geoPoints);
+ }
+
+ public static Function<Observation, Date> toDate() {
+ return TO_DATE_FUNCTION;
+ }
+
+ public static Function<Observation, String> toLabel() {
+ return TO_LABEL_FUNCTION;
+ }
+
public static Predicate<Observation> inDateInterval(Interval interval) {
return new InDateIntervalPredicate(interval);
}
@@ -188,6 +211,28 @@
}
};
+ private static Function<Observation, String> TO_LABEL_FUNCTION = new Function<Observation, String>() {
+
+ @Override
+ public String apply(Observation input) {
+ return toLabel(input);
+ }
+ };
+
+ private static class ToGeoPointFunction implements Function<Observation, GeoPoint> {
+
+ protected Iterable<GeoPoint> geoPoints;
+
+ public ToGeoPointFunction(Iterable<GeoPoint> geoPoints) {
+ this.geoPoints = geoPoints;
+ }
+
+ @Override
+ public GeoPoint apply(Observation input) {
+ return toGeoPoint(input, geoPoints);
+ }
+ }
+
private static class InRoutePredicate implements Predicate<Observation> {
protected Route route;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -233,8 +233,7 @@
List<Observer> observers = flightService.getFlightObserverForPositions(flight);
List<Observation> observations = flightService.getObservations(flight);
List<Route> routes = flightService.getRoutes(flight);
- List<GeoPoint> geoPoints =
- GeoPoints.retainsValidCoordinates(flightService.getFlightGeoPoints(flight));
+ List<GeoPoint> geoPoints = flightService.getFlightGeoPoints(flight);
if (logger.isTraceEnabled()) {
for (GeoPoint geoPoint : geoPoints) {
@@ -739,13 +738,17 @@
Observation observation = event.getObservation();
getModel().addObservation(observation);
- // Add the GeoPoint to the layer
- GeoPoint geoPoint = event.getGeoPoint();
- if (!GeoPoints.isCoordinatesEmpty(geoPoint)) {
- observationLayer.addGeoPoint(geoPoint);
- }
+ setObservationGeoPointInMap(observation, event.getGeoPoint());
}
+ public void setObservationGeoPointInMap(Observation observation, GeoPoint geoPoint) {
+ observationLayer.putGeoPoint(observation, geoPoint, Observations.toLabel(observation));
+ }
+
+ public void setObservationLabelInMap(Observation observation) {
+ observationLayer.setLabel(observation, Observations.toLabel(observation));
+ }
+
public void selectStrate(StrateModel strate) {
if (logger.isDebugEnabled()) {
@@ -1092,12 +1095,11 @@
observationLayer = new SimpleGeoPointLayer();
observationLayer.setProperties(properties);
-
- List<GeoPoint> geoPoints = GeoPoints.getClosestPoints(
- getModel().getGeoPoints(),
- Observations.toDates(getModel().getObservations())
+ observationLayer.setGeoPoints(
+ getModel().getObservations(),
+ Observations.toGeoPoint(getModel().getGeoPoints()),
+ Observations.toLabel()
);
- observationLayer.setGeoPoints(geoPoints);
mapHandler.add(observationLayer);
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -36,6 +36,8 @@
import fr.ulr.sammoa.application.device.audio.AudioRecorder;
import fr.ulr.sammoa.application.device.gps.GpsHandler;
import fr.ulr.sammoa.application.flightController.FlightController;
+import fr.ulr.sammoa.persistence.GeoPoint;
+import fr.ulr.sammoa.persistence.GeoPoints;
import fr.ulr.sammoa.persistence.Observation;
import fr.ulr.sammoa.persistence.ObservationStatus;
import fr.ulr.sammoa.persistence.Observations;
@@ -837,12 +839,20 @@
getParentUI().getHandler().getFlightController().setCurrentRoute(newValue);
+ if (oldValue != null) {
+ oldValue.removePropertyChangeListener(
+ Route.PROPERTY_BEGIN_TIME, routeTimeChangeListener);
+ }
+
if (newValue == null) {
// no unselect but ensure valid button (a select will cause a loop)
getModel().setObservationEditBean(null);
} else {
+ newValue.addPropertyChangeListener(
+ Route.PROPERTY_BEGIN_TIME, routeTimeChangeListener);
+
// Set audio position
setAudioReaderPositionDate(newValue.getBeginTime());
@@ -862,14 +872,16 @@
if (oldValue != null) {
oldValue.removePropertyChangeListener(
- Observation.PROPERTY_OBSERVATION_TIME,
- observationTimeChangeListener);
+ Observation.PROPERTY_OBSERVATION_TIME, observationTimeChangeListener);
+ oldValue.removePropertyChangeListener(
+ Observation.PROPERTY_SPECIES, observationSpeciesChangeListener);
}
if (newValue != null) {
newValue.addPropertyChangeListener(
- Observation.PROPERTY_OBSERVATION_TIME,
- observationTimeChangeListener);
+ Observation.PROPERTY_OBSERVATION_TIME, observationTimeChangeListener);
+ newValue.addPropertyChangeListener(
+ Observation.PROPERTY_SPECIES, observationSpeciesChangeListener);
selectRouteByObservation(newValue);
@@ -878,14 +890,53 @@
}
}
+ protected GeoPoint ensureGeoPoint(Date date) {
+
+ List<GeoPoint> modelPoints = getModel().getGeoPoints();
+ GeoPoint result = Iterables.find(modelPoints, GeoPoints.withDate(date), null);
+
+ if (result == null) {
+ FlightService service = context.getService(FlightService.class);
+ result = service.getGeoPoint(getModel().getFlight(), date);
+ modelPoints.add(result);
+ }
+ return result;
+ }
+
+ private PropertyChangeListener routeTimeChangeListener = new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ ensureGeoPoint((Date) evt.getNewValue());
+ }
+ };
+
private PropertyChangeListener observationTimeChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
- selectRouteByObservation((Observation) evt.getSource());
+
+ Observation observation = (Observation) evt.getSource();
+
+ GeoPoint geoPoint = ensureGeoPoint((Date) evt.getNewValue());
+
+ getParentUI().getHandler().setObservationGeoPointInMap(observation, geoPoint);
+
+ selectRouteByObservation(observation);
}
};
+ private PropertyChangeListener observationSpeciesChangeListener = new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+
+ Observation observation = (Observation) evt.getSource();
+
+ getParentUI().getHandler().setObservationLabelInMap(observation);
+ }
+ };
+
/**
* Editor for type {@link TransectFlight}. This will use the
* {@link DefaultCellEditor} with {@link JComboBox} as editor component.
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/BaseGeoPointLayer.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -26,10 +26,19 @@
import com.bbn.openmap.layer.OMGraphicHandlerLayer;
import com.bbn.openmap.omGraphics.DrawingAttributes;
import com.bbn.openmap.omGraphics.OMGraphic;
+import com.bbn.openmap.omGraphics.OMGraphicConstants;
import com.bbn.openmap.omGraphics.OMGraphicList;
+import com.bbn.openmap.omGraphics.OMText;
+import com.bbn.openmap.omGraphics.OMTextLabeler;
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import fr.ulr.sammoa.persistence.GeoPoint;
+import fr.ulr.sammoa.persistence.GeoPoints;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import java.util.List;
import java.util.Properties;
/**
@@ -41,25 +50,96 @@
private static final long serialVersionUID = 1L;
+ /** Logger. */
+ private static final Logger logger = LoggerFactory.getLogger(BaseGeoPointLayer.class);
+
protected DrawingAttributes drawingAttributes = DrawingAttributes.getDefaultClone();
- public void setGeoPoints(List<GeoPoint> geoPoints) {
+ public void setGeoPoints(Iterable<GeoPoint> geoPoints) {
+
setList(new OMGraphicList());
- for (GeoPoint geoPoint : geoPoints) {
- addGraphic(geoPoint);
+ for (GeoPoint reference : geoPoints) {
+ if (GeoPoints.isCoordinatesEmpty(reference)) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Can't add geoPoint, no coordinates available " +
+ "at {}", reference.getRecordTime());
+ }
+ } else {
+ getList().add(createGraphic(reference, reference, null));
+ }
}
}
+ public <T> void setGeoPoints(Iterable<T> references,
+ Function<T, GeoPoint> toGeoPoint,
+ Function<T, String> toLabel) {
+
+ setList(new OMGraphicList());
+
+ for (T reference : references) {
+ GeoPoint geoPoint = toGeoPoint.apply(reference);
+ String label = toLabel.apply(reference);
+
+ if (GeoPoints.isCoordinatesEmpty(geoPoint)) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Can't add geoPoint, no coordinates available " +
+ "at {} (label={})", geoPoint.getRecordTime(), label);
+ }
+ } else {
+ getList().add(createGraphic(reference, geoPoint, label));
+ }
+ }
+ }
+
public void addGeoPoint(GeoPoint geoPoint) {
+ putGeoPoint(geoPoint, geoPoint, null);
+ }
- addGraphic(geoPoint);
+ public void setLabel(Object reference, String label) {
+ OMGraphic graphic = Iterables.find(getList(), withReference(reference), null);
+ if (graphic != null) {
+ setLabel(graphic, label);
+ applyChange();
+ }
+ }
- // Need to generate the projection to apply change
- getList().generate(getProjection());
+ public void putGeoPoint(Object reference, GeoPoint geoPoint, String label) {
- // Refresh the view
- repaint();
+ int index = Iterables.indexOf(getList(), withReference(reference));
+
+ if (GeoPoints.isCoordinatesEmpty(geoPoint)) {
+ if (logger.isWarnEnabled()) {
+ logger.warn("Can't add geoPoint, no coordinates available " +
+ "(label={})", label);
+ }
+
+ if (index != -1) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Remove geoPoint at index {} (label={})", index, label);
+ }
+ getList().remove(index);
+ }
+
+ } else {
+
+ OMGraphic graphic = createGraphic(reference, geoPoint, label);
+
+ if (index != -1) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Update geoPoint at index {} (label={})", index, label);
+ }
+ getList().set(index, graphic);
+
+ } else {
+ if (logger.isDebugEnabled() && label != null) {
+ logger.debug("Add geoPoint (label={})", label);
+ }
+ getList().add(graphic);
+ }
+ }
+
+ applyChange();
}
@Override
@@ -82,12 +162,47 @@
return result;
}
- protected void addGraphic(GeoPoint geoPoint) {
- OMGraphic graphic = newGraphic(geoPoint);
- drawingAttributes.setTo(graphic);
- graphic.setAppObject(geoPoint);
- getList().add(graphic);
+ protected OMGraphic createGraphic(Object reference, GeoPoint geoPoint, String label) {
+ OMGraphic result = newGraphic(geoPoint);
+ if (label != null) {
+ setLabel(result, label);
+ }
+ drawingAttributes.setTo(result);
+ result.setAppObject(reference);
+ return result;
}
+ protected void setLabel(OMGraphic graphic, String label) {
+ graphic.putAttribute(OMGraphicConstants.LABEL,
+ new OMTextLabeler(label, OMText.JUSTIFY_CENTER));
+ }
+
+ protected void applyChange() {
+
+ // Need to generate the projection to apply change
+ getList().generate(getProjection());
+
+ // Refresh the view
+ repaint();
+ }
+
protected abstract OMGraphic newGraphic(GeoPoint geoPoint);
+
+ public static Predicate<OMGraphic> withReference(Object reference) {
+ return new WithReferencePredicate(reference);
+ }
+
+ private static class WithReferencePredicate implements Predicate<OMGraphic> {
+
+ protected Object reference;
+
+ private WithReferencePredicate(Object reference) {
+ this.reference = reference;
+ }
+
+ @Override
+ public boolean apply(OMGraphic input) {
+ return Objects.equal(input.getAppObject(), reference);
+ }
+ }
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java 2012-09-11 14:17:14 UTC (rev 571)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/layer/LineGeoPointLayer.java 2012-09-12 11:52:18 UTC (rev 572)
@@ -47,11 +47,20 @@
OMGraphic lastGraphic = Iterables.getLast(getList());
- GeoPoint previousPoint = (GeoPoint) lastGraphic.getAppObject();
+ double lat, lon;
+ if (lastGraphic instanceof OMPoint) {
+ lat = ((OMPoint) lastGraphic).getLat();
+ lon = ((OMPoint) lastGraphic).getLon();
+ } else {
+ lat = ((OMLine) lastGraphic).getLL()[2];
+ lon = ((OMLine) lastGraphic).getLL()[3];
+ }
+// GeoPoint previousPoint = (GeoPoint) lastGraphic.getAppObject();
+
result = new OMLine(
- previousPoint.getLatitude(),
- previousPoint.getLongitude(),
+ lat,
+ lon,
geoPoint.getLatitude(),
geoPoint.getLongitude(),
OMGraphicConstants.LINETYPE_GREATCIRCLE
1
0
r571 - trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/input/application
by fdesbois@users.forge.codelutin.com 11 Sep '12
by fdesbois@users.forge.codelutin.com 11 Sep '12
11 Sep '12
Author: fdesbois
Date: 2012-09-11 16:17:14 +0200 (Tue, 11 Sep 2012)
New Revision: 571
Url: http://forge.codelutin.com/repositories/revision/sammoa/571
Log:
fixes #1482 : use greater weighty for panel with flights
Modified:
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/input/application/ImportApplicationUI.jaxx
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/input/application/ImportApplicationUI.jaxx
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/input/application/ImportApplicationUI.jaxx 2012-09-11 13:10:44 UTC (rev 570)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/io/input/application/ImportApplicationUI.jaxx 2012-09-11 14:17:14 UTC (rev 571)
@@ -86,7 +86,7 @@
</row>
<!-- load import file result -->
<row>
- <cell fill='both' weightx='1.0' columns='3'>
+ <cell fill='both' weightx='1.0' weighty='2.0' columns='3'>
<JPanel id='loadImportFileResultPanel' layout='{new BorderLayout()}'
decorator='boxed'>
<JLabel id='loadImportFileResultInfo'
1
0
r570 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation
by fdesbois@users.forge.codelutin.com 11 Sep '12
by fdesbois@users.forge.codelutin.com 11 Sep '12
11 Sep '12
Author: fdesbois
Date: 2012-09-11 15:10:44 +0200 (Tue, 11 Sep 2012)
New Revision: 570
Url: http://forge.codelutin.com/repositories/revision/sammoa/570
Log:
fixes #1473 : clean AudioCheck
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioReader.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioRecorder.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/SoundPlayer.java
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java 2012-09-11 10:08:46 UTC (rev 569)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java 2012-09-11 13:10:44 UTC (rev 570)
@@ -38,12 +38,4 @@
* @param audioPosition la nouvelle position en milliseconds
*/
public void positionChanged(AudioReader source, long audioPosition);
-
- /**
- * @param source La source de l'evenement
- * @param audioLength la nouvelle taille en milliseconds
- * @deprecated no longer used
- */
- @Deprecated
- public void audioChanged(AudioReader source, long audioLength);
}
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioReader.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioReader.java 2012-09-11 10:08:46 UTC (rev 569)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioReader.java 2012-09-11 13:10:44 UTC (rev 570)
@@ -182,10 +182,7 @@
}
// Get the clip length in microseconds and convert to milliseconds
audioLength = (int)(clip.getMicrosecondLength( )/1000);
- for (AudioPositionListener l : audioPositionListener) {
- l.audioChanged(this, audioLength);
- }
- this.startDate = recordingDate;
+ startDate = recordingDate;
setState(DeviceState.READY);
logger.debug(String.format("Sound file '%s' loaded", file));
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioRecorder.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioRecorder.java 2012-09-11 10:08:46 UTC (rev 569)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioRecorder.java 2012-09-11 13:10:44 UTC (rev 570)
@@ -25,16 +25,17 @@
package fr.ulr.sammoa.application.device.audio;
import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
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 java.io.File;
-import java.io.IOException;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
@@ -42,10 +43,11 @@
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.TargetDataLine;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
/**
* Classe permettant l'enregistrement d'un fichier audio. Par defaut la
@@ -289,8 +291,14 @@
targetDataLine.open(audioFormat);
targetDataLine.start();
stream = new AudioInputStream(targetDataLine);
- stream = AudioSystem.getAudioInputStream(encoding, stream);
-
+ try {
+ stream = AudioSystem.getAudioInputStream(encoding, stream);
+ } catch (Exception eee) {
+ // Clean TargetDataLine if error occurs on audioInputStream
+ targetDataLine.stop();
+ targetDataLine.close();
+ throw Throwables.propagate(eee);
+ }
}
/**
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java 2012-09-11 10:08:46 UTC (rev 569)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java 2012-09-11 13:10:44 UTC (rev 570)
@@ -24,7 +24,6 @@
* #L%
*/
-import com.google.common.base.Throwables;
import fr.ulr.sammoa.application.device.audio.SammoaAudioReader;
import fr.ulr.sammoa.application.device.audio.SammoaAudioRecorder;
import fr.ulr.sammoa.ui.swing.flight.bar.validation.SoundPlayer;
@@ -47,6 +46,8 @@
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.Date;
@@ -192,9 +193,11 @@
new ActionListener(){
public void actionPerformed(
ActionEvent e){
- captureBtn.setEnabled(false);
- stopBtn.setEnabled(true);
- captureAudio();
+ boolean audioRecording = captureAudio();
+ if (audioRecording) {
+ captureBtn.setEnabled(false);
+ stopBtn.setEnabled(true);
+ }
}
});
@@ -216,16 +219,36 @@
playerPanel.getAudioReader().load(file, new Date());
}
});
+
+ addWindowListener(new WindowAdapter() {
+
+ @Override
+ public void windowClosed(WindowEvent e) {
+ if (recorder != null) {
+ recorder.close();
+ }
+ }
+ });
}
- protected void captureAudio(){
- try{
- File file = new File(filenameField.getText());
- recorder = new SammoaAudioRecorder(
- getSampleRate(), getSampleSizeInBits(), getCompression(), 0);
+ protected boolean captureAudio(){
+ File file = new File(filenameField.getText());
+ if (recorder != null) {
+ recorder.close();
+ }
+ recorder = new SammoaAudioRecorder(
+ getSampleRate(), getSampleSizeInBits(), getCompression(), 0);
+ try {
recorder.record(file, true);
- }catch (Exception eee) {
+ return true;
+
+ } catch (Exception eee) {
+ // Close only on error, otherwise no recording will be launch
+ recorder.close();
+
logger.error("Can't capture audio", eee);
+ SammoaUtil.showErrorMessage(this, "Can't capture audio : " + eee.getMessage());
+ return false;
}
}
@@ -278,19 +301,27 @@
r1.stop();
r2.stop();
delay = 5;
- SammoaUtil.showSuccessMessage(this, "The recording delay is set to " +
- "5 seconds between each recording, " +
- "you can update this value from" +
- " configuration interface");
+ if (logger.isInfoEnabled()) {
+ logger.info("The recording delay is set to 5 seconds between " +
+ "each recording, you can update this value from" +
+ " configuration interface");
+ }
+
} catch(IOException ex) {
- throw Throwables.propagate(ex);
+ if (logger.isErrorEnabled()) {
+ logger.error("Can't check audio line", ex);
+ }
+ SammoaUtil.showErrorMessage(this, "Can't check audio line : " + ex.getMessage());
} catch(LineUnavailableException ex) {
delay = 0;
- logger.error("Can't record multiple file in same time", ex);
- SammoaUtil.showErrorMessage(this, "Can't record multiple file in " +
- "same time, 0 second delay " +
- "between recording must be used");
+ if (logger.isDebugEnabled()) {
+ logger.debug("Can't record multiple file at the same time", ex);
+ }
+ if (logger.isInfoEnabled()) {
+ logger.info("Can't record multiple file at the same time, 0 " +
+ "second delay between recording must be used");
+ }
} finally {
r1.close();
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/SoundPlayer.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/SoundPlayer.java 2012-09-11 10:08:46 UTC (rev 569)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/SoundPlayer.java 2012-09-11 13:10:44 UTC (rev 570)
@@ -32,8 +32,6 @@
import fr.ulr.sammoa.application.device.audio.SammoaAudioReader;
import org.apache.commons.lang3.time.FastDateFormat;
-import javax.sound.sampled.LineUnavailableException;
-import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
@@ -48,7 +46,6 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
-import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
@@ -73,7 +70,7 @@
protected AudioReader reader;
// le fichier charge acutellement au niveau de l'ui (config du slider
- protected File currentFile;
+// protected File currentFile;
// The following fields are for the GUI
protected JButton play; // The Play button
@@ -323,8 +320,7 @@
}
// The main method just creates a SoundPlayer in a Frame and displays it
- public static void main(String[] args)
- throws IOException, UnsupportedAudioFileException, LineUnavailableException {
+ public static void main(String[] args) {
SoundPlayer player;
File file;
@@ -347,8 +343,4 @@
f.pack();
f.setVisible(true);
}
-
- public void audioChanged(AudioReader source, long audioLength) {
- // A SUPPRIMER
- }
}
\ No newline at end of file
1
0
r569 - in trunk/sammoa-ui-swing/src/main: java/fr/ulr/sammoa/ui/swing/flight/effort resources/i18n
by fdesbois@users.forge.codelutin.com 11 Sep '12
by fdesbois@users.forge.codelutin.com 11 Sep '12
11 Sep '12
Author: fdesbois
Date: 2012-09-11 12:08:46 +0200 (Tue, 11 Sep 2012)
New Revision: 569
Url: http://forge.codelutin.com/repositories/revision/sammoa/569
Log:
fixes #1469 : allow LEG transect edition
Modified:
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java
trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-10 15:55:43 UTC (rev 568)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-11 10:08:46 UTC (rev 569)
@@ -24,10 +24,10 @@
*/
import com.ezware.oxbow.swingbits.table.filter.TableRowFilterSupport;
+import com.google.common.base.Objects;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
-import fr.ulr.sammoa.application.DecoratorService;
import fr.ulr.sammoa.application.FlightService;
import fr.ulr.sammoa.application.device.DeviceState;
import fr.ulr.sammoa.application.device.DeviceStateEvent;
@@ -415,14 +415,22 @@
UIDecoratorService decoratorService =
context.getService(UIDecoratorService.class);
- TableCellRenderer stringRenderer = table.getDefaultRenderer(String.class);
-
// TransectFlight
{
+ TableCellRenderer tableRenderer =
+ decoratorService.newTableCellRender(TransectFlightModel.class);
TableCellRenderer renderer = new TransectFlightCellRenderer(
- stringRenderer, decoratorService, getModel());
+ tableRenderer, getModel());
+ JComboBox comboBox = new JComboBox();
+ ListCellRenderer listRenderer =
+ decoratorService.newListCellRender(TransectFlightModel.class);
+ comboBox.setRenderer(listRenderer);
+ TableCellEditor editor = new TransectFlightCellEditor(
+ comboBox, getModel());
+
table.setDefaultRenderer(TransectFlight.class, renderer);
+ table.setDefaultEditor(TransectFlight.class, editor);
}
table.addHighlighter(SammoaUtil.newBackgroundColorHighlighter(
@@ -878,19 +886,92 @@
}
};
+ /**
+ * Editor for type {@link TransectFlight}. This will use the
+ * {@link DefaultCellEditor} with {@link JComboBox} as editor component.
+ * <p/>
+ * The model used is the list of {@link TransectFlightModel} from
+ * {@link FlightUIModel}. So we need to convert {@link TransectFlightModel}
+ * to {@link TransectFlight} and listen the model change on property
+ * {@link FlightUIModel#PROPERTY_TRANSECT_FLIGHTS}.
+ * <p/>
+ * We also want to ensure the change by asking a user question to confirm it.
+ */
+ private static class TransectFlightCellEditor extends DefaultCellEditor
+ implements PropertyChangeListener {
+
+ protected FlightUIModel model;
+
+ protected TransectFlight initValue;
+
+ public TransectFlightCellEditor(JComboBox comboBox,
+ FlightUIModel model) {
+ super(comboBox);
+ this.model = model;
+ SwingUtil.fillComboBox(comboBox, model.getTransectFlights(), null);
+ model.addPropertyChangeListener(FlightUIModel.PROPERTY_TRANSECT_FLIGHTS, this);
+ }
+
+ @Override
+ public Component getTableCellEditorComponent(JTable table,
+ Object value,
+ boolean isSelected,
+ int row,
+ int column) {
+
+ initValue = (TransectFlight) value;
+ TransectFlightModel modelValue = TransectFlightModel.findTransectFlightModel(
+ model.getTransectFlights(), initValue);
+
+ return super.getTableCellEditorComponent(table, modelValue, isSelected, row, column);
+ }
+
+ @Override
+ public TransectFlight getCellEditorValue() {
+ TransectFlightModel modelValue = (TransectFlightModel) super.getCellEditorValue();
+ return modelValue == null ? null : modelValue.getSource();
+ }
+
+ @Override
+ public boolean stopCellEditing() {
+ boolean result;
+
+ TransectFlight value = getCellEditorValue();
+ if (Objects.equal(value, initValue)
+ || SammoaUtil.askQuestion(editorComponent, _(
+ "sammoa.confirmDialog.changeRouteTransect.message",
+ value.getTransect().getName()))) {
+
+ result = super.stopCellEditing();
+
+ } else {
+ cancelCellEditing();
+ result = true;
+ }
+ return result;
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+
+ List<TransectFlightModel> newValue =
+ (List<TransectFlightModel>) evt.getNewValue();
+
+ if (newValue != null) {
+ SwingUtil.fillComboBox((JComboBox) editorComponent, newValue, null);
+ }
+ }
+ }
+
private static class TransectFlightCellRenderer implements TableCellRenderer {
protected TableCellRenderer delegate;
- protected Decorator<TransectFlightModel> decorator;
-
protected FlightUIModel model;
public TransectFlightCellRenderer(TableCellRenderer delegate,
- DecoratorService decoratorService,
FlightUIModel model) {
this.delegate = delegate;
- this.decorator = decoratorService.getDecoratorByType(TransectFlightModel.class);
this.model = model;
}
@@ -907,14 +988,11 @@
if (value != null) {
TransectFlight transectFlight = (TransectFlight) value;
- // Retrieve the transect params from matching TransectFlightModel
- TransectFlightModel transectFlightModel =
- TransectFlightModel.findTransectFlightModel(model.getTransectFlights(),
- transectFlight);
-
- newValue = decorator.toString(transectFlightModel);
+ newValue = TransectFlightModel.findTransectFlightModel(
+ model.getTransectFlights(), transectFlight);
}
- return delegate.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column);
+ return delegate.getTableCellRendererComponent(
+ table, newValue, isSelected, hasFocus, row, column);
}
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java 2012-09-10 15:55:43 UTC (rev 568)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java 2012-09-11 10:08:46 UTC (rev 569)
@@ -136,7 +136,15 @@
}
},
ROUTE_TYPE(false, RouteType.class, Route.PROPERTY_ROUTE_TYPE),
- TRANSECT(false, TransectFlight.class, Route.PROPERTY_TRANSECT_FLIGHT),
+ TRANSECT(true, TransectFlight.class, Route.PROPERTY_TRANSECT_FLIGHT) {
+
+ @Override
+ public boolean isEditable(Route bean, boolean validationMode) {
+ return super.isEditable(bean, validationMode)
+ && bean.getRouteType() == RouteType.LEG
+ && validationMode;
+ }
+ },
SEA_STATE(true, int.class, Route.PROPERTY_SEA_STATE),
SWELL(true, int.class, Route.PROPERTY_SWELL),
TURBIDITY(true, int.class, Route.PROPERTY_TURBIDITY),
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-09-10 15:55:43 UTC (rev 568)
+++ trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 2012-09-11 10:08:46 UTC (rev 569)
@@ -72,6 +72,7 @@
sammoa.config.category.other.description=Other
sammoa.config.category.shortcuts=Shortcuts
sammoa.config.category.shortcuts.description=List of all the shortcuts
+sammoa.confirmDialog.changeRouteTransect.message=Are you sure you want to change the LEG transect by %s ?
sammoa.confirmDialog.deleteTransect.message=The flight is not started, do you want to definitely delete this flight's transect ?
sammoa.confirmDialog.flightInProgress.message.exit=A flight is in progress, are you sure you want to quit ?
sammoa.confirmDialog.flightInProgress.message.showHome=A flight is in progress, are you sure you want to go back to the home screen ?
1
0
r568 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util
by fdesbois@users.forge.codelutin.com 10 Sep '12
by fdesbois@users.forge.codelutin.com 10 Sep '12
10 Sep '12
Author: fdesbois
Date: 2012-09-10 17:55:43 +0200 (Mon, 10 Sep 2012)
New Revision: 568
Url: http://forge.codelutin.com/repositories/revision/sammoa/568
Log:
fixes #1470: improve refresh for crossingNumber and realNbTimes
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DecoratorService.java
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/UIDecoratorService.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/TransectFlightModel.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DecoratorService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DecoratorService.java 2012-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/DecoratorService.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -80,8 +80,19 @@
decoratorProvider = new DecoratorProvider() {
@Override
protected void loadDecorators() {
- registerJXPathDecorator(Route.class, "${routeType}$s ${beginTime}$tH:%2$tM:%2$tS");
- registerJXPathDecorator(Observation.class, "Obs_${observationNumber}$s ${observationTime}$tH:%2$tM:%2$tS");
+ registerDecorator(new Decorator<Route>(Route.class) {
+
+ @Override
+ public String toString(Object bean) {
+ Route route = (Route) bean;
+ String result = route.getRouteType().name();
+ if (route.getEffortNumber() != null) {
+ result += " " + route.getEffortNumber();
+ }
+ return result;
+ }
+ });
+ registerJXPathDecorator(Observation.class, "Sighting ${observationNumber}$s");
registerJXPathDecorator(Transect.class, "${name}$s");
registerJXPathDecorator(Observer.class, "${initials}$s");
registerMultiJXPathDecorator(Strate.class, "${code}$s##${name}$s", "##", " - ");
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/FlightService.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -563,6 +563,10 @@
return result;
}
+ public Long getTransectRealNbTimes(Transect transect) {
+ return getTransectRealNbTimes(Lists.newArrayList(transect)).get(transect);
+ }
+
public Map<Transect, Long> getTransectRealNbTimes(Collection<Transect> transects) {
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/UIDecoratorService.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/UIDecoratorService.java 2012-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/UIDecoratorService.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -29,6 +29,7 @@
import fr.ulr.sammoa.application.SammoaContext;
import fr.ulr.sammoa.persistence.Strate;
import fr.ulr.sammoa.ui.swing.flight.StrateModel;
+import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel;
import fr.ulr.sammoa.ui.swing.flight.TransectModel;
import jaxx.runtime.swing.renderer.DecoratorListCellRenderer;
import jaxx.runtime.swing.renderer.DecoratorTableCellRenderer;
@@ -53,6 +54,7 @@
// add extra ui decorators
decoratorProvider.registerJXPathDecorator(TransectModel.class, "${source/name}$s");
+ decoratorProvider.registerJXPathDecorator(TransectFlightModel.class, "${transect/source/name}$s (${crossingNumber}$d)");
decoratorProvider.registerDecorator(new Decorator<StrateModel>(StrateModel.class) {
private static final long serialVersionUID = 1L;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/FlightUIHandler.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -658,6 +658,9 @@
getModel().addPropertyChangeListener(
FlightUIModel.PROPERTY_NEXT_TRANSECT, nextTransectListener);
+ getModel().addPropertyChangeListener(
+ FlightUIModel.PROPERTY_TRANSECT_FLIGHTS, removeTransectListener);
+
transectUi = new TransectUI(context);
transectUi.addComponentListener(transectUIListener);
@@ -1180,6 +1183,35 @@
}
};
+ protected PropertyChangeListener removeTransectListener = new PropertyChangeListener() {
+
+ // Update transectRealNbTimes on transectFlight removal
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+
+ if (evt instanceof IndexedPropertyChangeEvent) {
+ int index = ((IndexedPropertyChangeEvent) evt).getIndex();
+
+ // REMOVE case
+ if (SammoaUtil.isCollectionRemoveEvent(evt)) {
+
+ List<TransectFlightModel> oldList =
+ (List<TransectFlightModel>) evt.getOldValue();
+
+ TransectFlightModel model = oldList.get(index);
+
+ TransectModel transectModel = model.getTransect();
+ FlightService service = context.getService(FlightService.class);
+ Long value = service.getTransectRealNbTimes(transectModel.getSource());
+
+ int realNbTimes = Objects.firstNonNull(value, 0).intValue();
+ transectModel.setRealNbTimes(realNbTimes);
+ }
+ }
+ }
+ };
+
protected PropertyChangeListener transectFlightListener = new PropertyChangeListener() {
@Override
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectFlightModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectFlightModel.java 2012-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/TransectFlightModel.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -167,6 +167,12 @@
return flightModel.getFlight();
}
+ public static TransectFlightModel findTransectFlightModel(Iterable<TransectFlightModel> transectFlightModels,
+ TransectFlight transectFlight) {
+ return Iterables.find(
+ transectFlightModels, new WithTransectFlightPredicate(transectFlight));
+ }
+
public static int indexOfTransectFlight(Iterable<TransectFlightModel> transectFlightModels,
TransectFlight transectFlight) {
return Iterables.indexOf(
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.java 2012-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/validation/ValidationBarHandler.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -26,24 +26,20 @@
import fr.ulr.sammoa.application.device.audio.AudioReader;
import fr.ulr.sammoa.application.flightController.FlightController;
-import fr.ulr.sammoa.persistence.Observation;
-import fr.ulr.sammoa.persistence.Route;
+import fr.ulr.sammoa.ui.swing.SammoaUIContext;
+import fr.ulr.sammoa.ui.swing.UIDecoratorService;
import fr.ulr.sammoa.ui.swing.flight.FlightUI;
import fr.ulr.sammoa.ui.swing.flight.FlightUIModel;
-import fr.ulr.sammoa.ui.swing.flight.TransectFlightModel;
+import jaxx.runtime.JAXXObject;
import jaxx.runtime.JAXXUtil;
+import javax.swing.JButton;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import static org.nuiton.i18n.I18n._;
-
/** @author fdesbois <fdesbois(a)codelutin.com> */
public class ValidationBarHandler {
-// private static final Logger logger =
-// LoggerFactory.getLogger(ValidationBarHandler.class);
-
protected final ValidationBar ui;
public ValidationBarHandler(ValidationBar ui) {
@@ -67,61 +63,43 @@
ui.getSoundPlayer().setReader(audioReader);
getModel().addPropertyChangeListener(
- FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, validTransectListener);
+ FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN,
+ new ValidableChangeListener(ui, ui.getValidTransectButton()));
getModel().addPropertyChangeListener(
- FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, validRouteListener);
+ FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN,
+ new ValidableChangeListener(ui, ui.getValidRouteButton()));
getModel().addPropertyChangeListener(
- FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, validObservationListener);
+ FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN,
+ new ValidableChangeListener(ui, ui.getValidObservationButton()));
}
- protected PropertyChangeListener validTransectListener = new PropertyChangeListener() {
+ private static class ValidableChangeListener implements PropertyChangeListener {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
+ protected SammoaUIContext context;
- TransectFlightModel newValue = (TransectFlightModel) evt.getNewValue();
+ protected JButton button;
- String text = null;
- if (newValue != null) {
- text = newValue.getTransect().getSource().getName();
- }
- ui.getValidTransectButton().setText(text);
+ private ValidableChangeListener(JAXXObject jaxxObject,
+ JButton button) {
+ this.context = jaxxObject.getContextValue(SammoaUIContext.class);
+ this.button = button;
}
- };
- protected PropertyChangeListener validRouteListener = new PropertyChangeListener() {
-
@Override
public void propertyChange(PropertyChangeEvent evt) {
+ Object newValue = evt.getNewValue();
- Route newValue = (Route) evt.getNewValue();
-
- String text = null;
+ String text;
if (newValue != null) {
- text = newValue.getRouteType().name();
- if (newValue.getEffortNumber() != null) {
- text += " " + newValue.getEffortNumber();
- }
- }
- ui.getValidRouteButton().setText(text);
- }
- };
+ UIDecoratorService service = context.getService(UIDecoratorService.class);
+ text = service.getDecorator(newValue).toString(newValue);
- protected PropertyChangeListener validObservationListener = new PropertyChangeListener() {
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
-
- Observation newValue = (Observation) evt.getNewValue();
-
- String text = null;
- if (newValue != null) {
- text = _("sammoa.validable.observation")
- + " " + newValue.getObservationNumber();
+ } else {
+ text = null;
}
- ui.getValidObservationButton().setText(text);
+ button.setText(text);
}
- };
+ }
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -27,6 +27,7 @@
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
+import fr.ulr.sammoa.application.DecoratorService;
import fr.ulr.sammoa.application.FlightService;
import fr.ulr.sammoa.application.device.DeviceState;
import fr.ulr.sammoa.application.device.DeviceStateEvent;
@@ -43,6 +44,7 @@
import fr.ulr.sammoa.persistence.Position;
import fr.ulr.sammoa.persistence.Route;
import fr.ulr.sammoa.persistence.Routes;
+import fr.ulr.sammoa.persistence.TransectFlight;
import fr.ulr.sammoa.ui.swing.SammoaColors;
import fr.ulr.sammoa.ui.swing.SammoaUIContext;
import fr.ulr.sammoa.ui.swing.UIDecoratorService;
@@ -408,8 +410,21 @@
}
}
- // Highlighters
+ // Renderers/Editors/Highlighters
{
+ UIDecoratorService decoratorService =
+ context.getService(UIDecoratorService.class);
+
+ TableCellRenderer stringRenderer = table.getDefaultRenderer(String.class);
+
+ // TransectFlight
+ {
+ TableCellRenderer renderer = new TransectFlightCellRenderer(
+ stringRenderer, decoratorService, getModel());
+
+ table.setDefaultRenderer(TransectFlight.class, renderer);
+ }
+
table.addHighlighter(SammoaUtil.newBackgroundColorHighlighter(
new RouteForSelectedTransectFlightHighlightPredicate(getModel()),
SammoaColors.ROUTE_FOR_TRANSECT_ROW_COLOR)
@@ -863,6 +878,46 @@
}
};
+ private static class TransectFlightCellRenderer implements TableCellRenderer {
+
+ protected TableCellRenderer delegate;
+
+ protected Decorator<TransectFlightModel> decorator;
+
+ protected FlightUIModel model;
+
+ public TransectFlightCellRenderer(TableCellRenderer delegate,
+ DecoratorService decoratorService,
+ FlightUIModel model) {
+ this.delegate = delegate;
+ this.decorator = decoratorService.getDecoratorByType(TransectFlightModel.class);
+ this.model = model;
+ }
+
+ @Override
+ public Component getTableCellRendererComponent(JTable table,
+ Object value,
+ boolean isSelected,
+ boolean hasFocus,
+ int row,
+ int column) {
+
+ Object newValue = value;
+
+ if (value != null) {
+ TransectFlight transectFlight = (TransectFlight) value;
+
+ // Retrieve the transect params from matching TransectFlightModel
+ TransectFlightModel transectFlightModel =
+ TransectFlightModel.findTransectFlightModel(model.getTransectFlights(),
+ transectFlight);
+
+ newValue = decorator.toString(transectFlightModel);
+ }
+ return delegate.getTableCellRendererComponent(table, newValue, isSelected, hasFocus, row, column);
+ }
+ }
+
private static class ObservationPositionCellRenderer implements TableCellRenderer {
protected TableCellRenderer delegate;
@@ -961,40 +1016,6 @@
}
}
-// public static class DeletedRowHighlightPredicate<T extends Deletable> extends AbstractRowHighlightPredicate {
-//
-// protected FlightUIModel UIModel;
-//
-// protected Class<T> referenceClass;
-//
-// public DeletedRowHighlightPredicate(FlightUIModel UIModel,
-// Class<T> referenceClass) {
-// this.UIModel = UIModel;
-// this.referenceClass = referenceClass;
-// }
-//
-// @Override
-// protected boolean isHighlighted(int rowIndex) {
-// boolean result = getValueAt(rowIndex).isDeleted();
-// return result;
-// }
-//
-// @Override
-// protected T getValueAt(int rowIndex) {
-// List<T> list;
-// if (Route.class.isAssignableFrom(referenceClass)) {
-// list = (List<T>) UIModel.getRoutes();
-//
-// } else if (Observation.class.isAssignableFrom(referenceClass)) {
-// list = (List<T>) UIModel.getObservations();
-//
-// } else {
-// throw new IllegalStateException("Not supported type " + referenceClass.getName());
-// }
-// return list.get(rowIndex);
-// }
-// }
-
public static class RouteForSelectedTransectFlightHighlightPredicate extends AbstractRowHighlightPredicate {
protected FlightUIModel UIModel;
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java 2012-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/RouteTableModel.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -27,7 +27,6 @@
import fr.ulr.sammoa.persistence.Flight;
import fr.ulr.sammoa.persistence.Route;
import fr.ulr.sammoa.persistence.RouteType;
-import fr.ulr.sammoa.persistence.Transect;
import fr.ulr.sammoa.persistence.TransectFlight;
import fr.ulr.sammoa.ui.swing.flight.FlightUIModel;
import fr.ulr.sammoa.ui.swing.util.SammoaUtil;
@@ -137,31 +136,7 @@
}
},
ROUTE_TYPE(false, RouteType.class, Route.PROPERTY_ROUTE_TYPE),
- TRANSECT(false, String.class,
- Route.PROPERTY_TRANSECT_FLIGHT,
- TransectFlight.PROPERTY_TRANSECT,
- Transect.PROPERTY_NAME
- ) {
- @Override
- public Object getValue(Route bean, RouteTableModel model) {
- Object result;
- TransectFlight transectFlight = bean.getTransectFlight();
- if (transectFlight != null) {
-
- Transect transect = transectFlight.getTransect();
-
-// int index = model.getFlight().getTransectFlightIndex(transectFlight);
-// result = transect.getName() + " (" + index + ")";
-
- int crossingNumber = transectFlight.getCrossingNumber();
- result = transect.getName() + " (" + crossingNumber + ")";
-
- } else {
- result = null;
- }
- return result;
- }
- },
+ TRANSECT(false, TransectFlight.class, Route.PROPERTY_TRANSECT_FLIGHT),
SEA_STATE(true, int.class, Route.PROPERTY_SEA_STATE),
SWELL(true, int.class, Route.PROPERTY_SWELL),
TURBIDITY(true, int.class, Route.PROPERTY_TURBIDITY),
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-09-10 15:53:25 UTC (rev 567)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/util/SammoaUtil.java 2012-09-10 15:55:43 UTC (rev 568)
@@ -24,6 +24,7 @@
*/
package fr.ulr.sammoa.ui.swing.util;
+import com.ezware.oxbow.swingbits.util.Preconditions;
import com.google.common.base.Joiner;
import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
@@ -55,8 +56,10 @@
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.beans.PropertyChangeEvent;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
/**
* Created: 14/06/12
@@ -131,6 +134,20 @@
return result;
}
+ public static boolean isCollectionRemoveEvent(PropertyChangeEvent event) {
+ boolean result = false;
+ if (event.getOldValue() != null && event.getNewValue() != null) {
+ Preconditions.checkArgument(event.getOldValue() instanceof Collection);
+ Preconditions.checkArgument(event.getNewValue() instanceof Collection);
+
+ int oldSize = ((Collection) event.getOldValue()).size();
+ int newSize = ((Collection) event.getNewValue()).size();
+
+ result = oldSize > newSize;
+ }
+ return result;
+ }
+
public static <T> TableSelectionListener<T> addTableSelectionListener(JTable table,
SelectionModelAdapter<T> selectionModelAdapter) {
TableSelectionListener<T> result =
1
0
r567 - in trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight: action effort
by fdesbois@users.forge.codelutin.com 10 Sep '12
by fdesbois@users.forge.codelutin.com 10 Sep '12
10 Sep '12
Author: fdesbois
Date: 2012-09-10 17:53:25 +0200 (Mon, 10 Sep 2012)
New Revision: 567
Url: http://forge.codelutin.com/repositories/revision/sammoa/567
Log:
little cleaning
Modified:
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java
trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java 2012-09-10 13:33:34 UTC (rev 566)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidRouteAction.java 2012-09-10 15:53:25 UTC (rev 567)
@@ -93,7 +93,6 @@
validatorIsAdjusting = true;
- getModel().setCurrentRoute(routeChanged);
getModel().setRouteEditBean(routeChanged);
getModel().setObservationEditBean(null);
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java 2012-09-10 13:33:34 UTC (rev 566)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/action/ValidTransectAction.java 2012-09-10 15:53:25 UTC (rev 567)
@@ -129,7 +129,6 @@
// Keep the route selected
if (routeEditBean != null && !routeEditBean.isDeleted()) {
- getModel().setCurrentRoute(routeEditBean);
getModel().setRouteEditBean(routeEditBean);
}
Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java
===================================================================
--- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-10 13:33:34 UTC (rev 566)
+++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/effort/EffortPanelHandler.java 2012-09-10 15:53:25 UTC (rev 567)
@@ -360,51 +360,25 @@
// FlightController # change current route
getModel().addPropertyChangeListener(
- FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN,
- new PropertyChangeListener() {
+ FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- Route route = (Route) evt.getNewValue();
- getParentUI().getHandler().getFlightController().setCurrentRoute(route);
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ onRouteChangedForValidation(
+ (Route) evt.getOldValue(),
+ (Route) evt.getNewValue());
+ }
+ });
- if (route == null) {
- // no unselect but ensure valid button (a select will cause a loop)
- getModel().setObservationEditBean(null);
-
- } else {
-
- // Set audio position
- setAudioReaderPositionDate(route.getBeginTime());
-
- // Remove observationEditBean if not in route
- Observation previousObservation = getModel().getObservationEditBean();
- if (previousObservation != null
- && !Observations.inRoute(previousObservation, route, getModel().getRoutes(), true)) {
-
- // no unselect but ensure valid button (a select will cause a loop)
- getModel().setObservationEditBean(null);
- }
- }
- }
- }
- );
-
// Refresh matching routes from selected transectFlight
getModel().addPropertyChangeListener(
FlightUIModel.PROPERTY_TRANSECT_FLIGHT_EDIT_BEAN, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
-
- TransectFlightModel oldValue = (TransectFlightModel) evt.getOldValue();
- if (oldValue != null) {
- fireRoutesUpdated(oldValue, false);
- }
- TransectFlightModel newValue = (TransectFlightModel) evt.getNewValue();
- if (newValue != null) {
- fireRoutesUpdated(newValue, true);
- }
+ onTransectFlightChangedForValidation(
+ (TransectFlightModel) evt.getOldValue(),
+ (TransectFlightModel) evt.getNewValue());
}
});
}
@@ -549,53 +523,28 @@
// Refresh matching observations from selected route
getModel().addPropertyChangeListener(
- FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN,
- new PropertyChangeListener() {
+ FlightUIModel.PROPERTY_ROUTE_EDIT_BEAN, new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ onRouteChanged((Route) evt.getOldValue(),
+ (Route) evt.getNewValue());
+ }
+ });
- Route oldValue = (Route) evt.getOldValue();
- if (oldValue != null) {
- fireObservationsUpdated(oldValue, false);
- }
- Route newValue = (Route) evt.getNewValue();
- if (newValue != null) {
- fireObservationsUpdated(newValue, true);
- }
- }
- });
-
if (getModel().isValidationMode()) {
- // For validation, time change is listening to properly select the route
getModel().addPropertyChangeListener(
- FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN,
- new PropertyChangeListener() {
+ FlightUIModel.PROPERTY_OBSERVATION_EDIT_BEAN, new PropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ onObservationChangedForValidation(
+ (Observation) evt.getOldValue(),
+ (Observation) evt.getNewValue());
+ }
+ });
- Observation oldValue = (Observation) evt.getNewValue();
- if (oldValue != null) {
- oldValue.removePropertyChangeListener(
- Observation.PROPERTY_OBSERVATION_TIME,
- observationTimeChangeListener);
- }
- Observation newValue = (Observation) evt.getNewValue();
- if (newValue != null) {
- newValue.addPropertyChangeListener(
- Observation.PROPERTY_OBSERVATION_TIME,
- observationTimeChangeListener);
-
- selectRouteByObservation(newValue);
-
- // Set audio position
- setAudioReaderPositionDate(newValue.getObservationTime());
- }
- }
- });
-
} else {
flightController.getDeviceManager(GpsHandler.class).addDeviceStateListener(this);
flightController.getDeviceManager(AudioRecorder.class).addDeviceStateListener(this);
@@ -840,6 +789,72 @@
SammoaUtil.selectTableRow(ui.getRouteTable(), routeIndex);
}
+ private void onRouteChanged(Route oldValue, Route newValue) {
+
+ if (oldValue != null) {
+ fireObservationsUpdated(oldValue, false);
+ }
+ if (newValue != null) {
+ fireObservationsUpdated(newValue, true);
+ }
+ }
+
+ private void onTransectFlightChangedForValidation(TransectFlightModel oldValue,
+ TransectFlightModel newValue) {
+ if (oldValue != null) {
+ fireRoutesUpdated(oldValue, false);
+ }
+ if (newValue != null) {
+ fireRoutesUpdated(newValue, true);
+ }
+ }
+
+ private void onRouteChangedForValidation(Route oldValue,
+ Route newValue) {
+
+ getParentUI().getHandler().getFlightController().setCurrentRoute(newValue);
+
+ if (newValue == null) {
+ // no unselect but ensure valid button (a select will cause a loop)
+ getModel().setObservationEditBean(null);
+
+ } else {
+
+ // Set audio position
+ setAudioReaderPositionDate(newValue.getBeginTime());
+
+ // Remove observationEditBean if not in route
+ Observation previousObservation = getModel().getObservationEditBean();
+ if (previousObservation != null
+ && !Observations.inRoute(previousObservation, newValue, getModel().getRoutes(), true)) {
+
+ // no unselect but ensure valid button (a select will cause a loop)
+ getModel().setObservationEditBean(null);
+ }
+ }
+ }
+
+ private void onObservationChangedForValidation(Observation oldValue,
+ Observation newValue) {
+
+ if (oldValue != null) {
+ oldValue.removePropertyChangeListener(
+ Observation.PROPERTY_OBSERVATION_TIME,
+ observationTimeChangeListener);
+ }
+
+ if (newValue != null) {
+ newValue.addPropertyChangeListener(
+ Observation.PROPERTY_OBSERVATION_TIME,
+ observationTimeChangeListener);
+
+ selectRouteByObservation(newValue);
+
+ // Set audio position
+ setAudioReaderPositionDate(newValue.getObservationTime());
+ }
+ }
+
private PropertyChangeListener observationTimeChangeListener = new PropertyChangeListener() {
@Override
1
0
r566 - in trunk: sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence
by fdesbois@users.forge.codelutin.com 10 Sep '12
by fdesbois@users.forge.codelutin.com 10 Sep '12
10 Sep '12
Author: fdesbois
Date: 2012-09-10 15:33:34 +0200 (Mon, 10 Sep 2012)
New Revision: 566
Url: http://forge.codelutin.com/repositories/revision/sammoa/566
Log:
fixes #1464 : Rewrite all the algorithm for closestPoint and beforeDate
Added:
trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/DatesTest.java
Modified:
trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Dates.java
trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java
Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java
===================================================================
--- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-09-10 11:10:56 UTC (rev 565)
+++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-09-10 13:33:34 UTC (rev 566)
@@ -121,7 +121,7 @@
}
// Create a new location if no one is available for the newTime
- if (!locationTime.equals(newTime)) {
+ if (!locationTime.isEqual(newTime)) {
result = new GeoPointImpl(location.getLatitude(), location.getLongitude());
result.setSpeed(location.getSpeed());
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Dates.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Dates.java 2012-09-10 11:10:56 UTC (rev 565)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/Dates.java 2012-09-10 13:33:34 UTC (rev 566)
@@ -24,10 +24,14 @@
* #L%
*/
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Ordering;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import java.util.Date;
+import java.util.Iterator;
/**
* Created: 31/08/12
@@ -52,6 +56,25 @@
return new DateTime(date);
}
+ public static Date getBeforeDate(Date date, Iterable<Date> source) {
+
+ Date result = null;
+ if (!Iterables.isEmpty(source)) {
+
+ Iterator<Date> dates = Ordering.natural().sortedCopy(source).iterator();
+
+ Date current = dates.next();
+
+ while (current != null && !current.after(date)) {
+ // Current is before or equal to date
+ result = current;
+ // Go to next date
+ current = dates.hasNext() ? dates.next() : null;
+ }
+ }
+ return result;
+ }
+
public static Date newDateWithoutMillis() {
return DateTime.now().withMillisOfSecond(0).toDate();
}
@@ -64,6 +87,16 @@
return interval.contains(toDateTime(date));
}
+ public static Function<Date, DateTime> toDateTime() {
+ return new Function<Date, DateTime>() {
+
+ @Override
+ public DateTime apply(Date input) {
+ return toDateTime(input);
+ }
+ };
+ }
+
// public static Predicate<Date> inInterval(Interval interval) {
// return new InIntervalPredicate(interval);
// }
Modified: trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java
===================================================================
--- trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-09-10 11:10:56 UTC (rev 565)
+++ trunk/sammoa-persistence/src/main/java/fr/ulr/sammoa/persistence/GeoPoints.java 2012-09-10 13:33:34 UTC (rev 566)
@@ -25,16 +25,12 @@
import com.google.common.base.Function;
import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Lists;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
-import org.joda.time.DateTime;
-import org.joda.time.Interval;
-import java.util.Comparator;
import java.util.Date;
import java.util.List;
@@ -91,129 +87,86 @@
return TO_DATE_FUNCTION;
}
- public static Comparator<GeoPoint> orderByDate() {
- return BY_DATE_COMPARATOR;
+ public static List<GeoPoint> getClosestPoints(List<GeoPoint> geoPoints,
+ Iterable<Date> dates) {
+
+ return FluentIterable.from(dates)
+ .transform(toClosestGeoPoint(geoPoints))
+ .toImmutableList();
}
- public static List<GeoPoint> getClosestPoints(List<GeoPoint> geoPoints, Iterable<Date> dates) {
+ public static GeoPoint getClosestPoint(List<GeoPoint> geoPoints,
+ Date date) {
- List<GeoPoint> result = Lists.newArrayList();
+ return toClosestGeoPoint(geoPoints).apply(date);
+ }
- if (!geoPoints.isEmpty()) {
+ public static Function<Date, GeoPoint> toClosestGeoPoint(List<GeoPoint> list) {
+ return new ToClosestPointFunction(list);
+ }
- List<GeoPoint> source =
- Ordering.from(orderByDate()).sortedCopy(geoPoints);
+ public static Predicate<GeoPoint> withDate(Date date) {
+ return new WithDatePredicate(date);
+ }
- List<Date> geoPointDates = Lists.transform(source, toDate());
+ private static Function<GeoPoint, Date> TO_DATE_FUNCTION = new Function<GeoPoint, Date>() {
- int index = 0;
- for (Date date : dates) {
+ @Override
+ public Date apply(GeoPoint input) {
+ return input.getRecordTime();
+ }
+ };
- // We continue starting from the previous index to avoid loop on all the date list
- index = getBeforeDateIndex(index > 0 ? index - 1 : 0, geoPointDates, date);
+ private static Predicate<GeoPoint> IS_COORDINATES_EMPTY_PREDICATE = new Predicate<GeoPoint>() {
- if (index != -1) {
- result.add(geoPoints.get(index));
- } else {
- result.add(newEmptyGeoPoint(date));
- }
- }
+ @Override
+ public boolean apply(GeoPoint input) {
+ return isCoordinatesEmpty(input);
}
- return result;
- }
+ };
- public static GeoPoint getClosestPoint(List<GeoPoint> geoPoints, Date date) {
+ private static class WithDatePredicate implements Predicate<GeoPoint> {
- GeoPoint result = null;
+ protected Date date;
- if (!geoPoints.isEmpty()) {
+ private WithDatePredicate(Date date) {
+ this.date = date;
+ }
- List<GeoPoint> source =
- Ordering.from(orderByDate()).sortedCopy(geoPoints);
-
- List<Date> geoPointDates = Lists.transform(source, toDate());
-
- int index = getBeforeDateIndex(0, geoPointDates, date);
- if (index != -1) {
- result = geoPoints.get(index);
- } else {
- result = newEmptyGeoPoint(date);
- }
+ @Override
+ public boolean apply(GeoPoint input) {
+ return date != null && date.equals(input.getRecordTime());
}
- return result;
}
- protected static int getBeforeDateIndex(int startIndex, List<Date> source, Date date) {
- int size = source.size();
- Preconditions.checkElementIndex(startIndex, size);
- DateTime dateTime = Dates.toDateTime(date);
+ private static class ToClosestPointFunction implements Function<Date, GeoPoint> {
- // If the first date is after the argument date we return -1, no date
- // is available before
- if (Dates.toDateTime(source.get(0)).isAfter(dateTime)) {
- return -1;
- }
+ protected Date date;
- for (int index = startIndex; index < size; index++) {
+ protected List<GeoPoint> list;
- int nextIndex = index + 1;
- if (nextIndex < size) {
+ protected List<Date> dates;
- Date begin = source.get(index);
- Date end = source.get(nextIndex);
- Interval interval = Dates.toInterval(begin, end);
-
- if (interval.contains(dateTime)) {
- return index;
- }
-
-// // If the date is equal or before we take the current index
-// if (date.equals(before) || date.before(before)) {
-// return index;
-//
-// // If the date is before the next date, we check which one
-// // of the before and after is the nearest value and we return
-// // its index
-// } else if (date.before(after)) {
-//
-// long diffBefore = date.getTime() - before.getTime();
-// long diffAfter = after.getTime() - date.getTime();
-//
-// if (diffBefore <= diffAfter) {
-// return index;
-//
-// } else {
-// return nextIndex;
-// }
-// }
- }
+ private ToClosestPointFunction(List<GeoPoint> list) {
+ this.list = list;
+ this.dates = FluentIterable
+ .from(list)
+ .transform(toDate())
+ .toSortedImmutableList(Ordering.natural());
}
- // We loop over the whole list, we return the last index
- return size - 1;
- }
- private static Function<GeoPoint, Date> TO_DATE_FUNCTION = new Function<GeoPoint, Date>() {
-
@Override
- public Date apply(GeoPoint input) {
- return input.getRecordTime();
- }
- };
+ public GeoPoint apply(Date input) {
- private static Comparator<GeoPoint> BY_DATE_COMPARATOR = new Comparator<GeoPoint>() {
+ // Get the date before
+ Date beforeDate = Dates.getBeforeDate(input, dates);
- @Override
- public int compare(GeoPoint o1, GeoPoint o2) {
- return o1.getRecordTime().compareTo(o2.getRecordTime());
- }
- };
+ // Find the matching GeoPoint or create an empty one with the date
+ GeoPoint result = Iterables.find(
+ list, withDate(beforeDate), newEmptyGeoPoint(input));
- private static Predicate<GeoPoint> IS_COORDINATES_EMPTY_PREDICATE = new Predicate<GeoPoint>() {
-
- @Override
- public boolean apply(GeoPoint input) {
- return isCoordinatesEmpty(input);
+ return result;
}
- };
+ }
}
Added: trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/DatesTest.java
===================================================================
--- trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/DatesTest.java (rev 0)
+++ trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/DatesTest.java 2012-09-10 13:33:34 UTC (rev 566)
@@ -0,0 +1,54 @@
+package fr.ulr.sammoa.persistence;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Created: 10/09/12
+ *
+ * @author fdesbois <florian.desbois(a)codelutin.com>
+ */
+public class DatesTest {
+
+ @Test
+ public void testGetBeforeDate() throws Exception {
+
+ List<Date> dates = ImmutableList.of(
+ new Date(2000),
+ new Date(4000),
+ new Date(3000)
+ );
+
+ // Begin case
+ {
+ Date date = new Date(1000);
+ Date result = Dates.getBeforeDate(date, dates);
+ Assert.assertNull(result);
+ }
+
+ // Normal case
+ {
+ Date date = new Date(2100);
+ Date result = Dates.getBeforeDate(date, dates);
+ Assert.assertEquals(2000, result.getTime());
+ }
+
+ // Equal case
+ {
+ Date date = new Date(3000);
+ Date result = Dates.getBeforeDate(date, dates);
+ Assert.assertEquals(3000, result.getTime());
+ }
+
+ // End case
+ {
+ Date date = new Date(4100);
+ Date result = Dates.getBeforeDate(date, dates);
+ Assert.assertEquals(4000, result.getTime());
+ }
+ }
+}
Property changes on: trunk/sammoa-persistence/src/test/java/fr/ulr/sammoa/persistence/DatesTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0