]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/undo/UndoCorrelatePhotos.java
Version 4, January 2008
[GpsPrune.git] / tim / prune / undo / UndoCorrelatePhotos.java
diff --git a/tim/prune/undo/UndoCorrelatePhotos.java b/tim/prune/undo/UndoCorrelatePhotos.java
new file mode 100644 (file)
index 0000000..3c25837
--- /dev/null
@@ -0,0 +1,72 @@
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\r
+import tim.prune.data.DataPoint;\r
+import tim.prune.data.Photo;\r
+import tim.prune.data.TrackInfo;\r
+\r
+/**\r
+ * Operation to undo an auto-correlation of photos with points\r
+ */\r
+public class UndoCorrelatePhotos implements UndoOperation\r
+{\r
+       private DataPoint[] _contents = null;\r
+       private DataPoint[] _photoPoints = null;\r
+       private int _numPhotosCorrelated = -1;\r
+\r
+\r
+       /**\r
+        * Constructor\r
+        * @param inTrackInfo track information\r
+        */\r
+       public UndoCorrelatePhotos(TrackInfo inTrackInfo)\r
+       {\r
+               // Copy track contents\r
+               _contents = inTrackInfo.getTrack().cloneContents();\r
+               // Copy points associated with photos before correlation\r
+               int numPhotos = inTrackInfo.getPhotoList().getNumPhotos();\r
+               _photoPoints = new DataPoint[numPhotos];\r
+               for (int i=0; i<numPhotos; i++) {\r
+                       _photoPoints[i] = inTrackInfo.getPhotoList().getPhoto(i).getDataPoint();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * @param inNumCorrelated number of photos correlated\r
+        */\r
+       public void setNumPhotosCorrelated(int inNumCorrelated)\r
+       {\r
+               _numPhotosCorrelated = inNumCorrelated;\r
+       }\r
+\r
+       /**\r
+        * @return description of operation including parameters\r
+        */\r
+       public String getDescription()\r
+       {\r
+               return I18nManager.getText("undo.correlate") + " (" + _numPhotosCorrelated + ")";\r
+       }\r
+\r
+\r
+       /**\r
+        * Perform the undo operation on the given Track\r
+        * @param inTrackInfo TrackInfo object on which to perform the operation\r
+        */\r
+       public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
+       {\r
+               // restore track to previous values\r
+               inTrackInfo.getTrack().replaceContents(_contents);\r
+               // restore photo association\r
+               for (int i=0; i<_photoPoints.length; i++)\r
+               {\r
+                       Photo photo = inTrackInfo.getPhotoList().getPhoto(i);\r
+                       DataPoint point = _photoPoints[i];\r
+                       photo.setDataPoint(point);\r
+                       if (point != null) {\r
+                               point.setPhoto(photo);\r
+                       }\r
+               }\r
+               // clear selection\r
+               inTrackInfo.getSelection().clearAll();\r
+       }\r
+}
\ No newline at end of file