]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/undo/UndoDeletePhoto.java
Version 3, August 2007
[GpsPrune.git] / tim / prune / undo / UndoDeletePhoto.java
diff --git a/tim/prune/undo/UndoDeletePhoto.java b/tim/prune/undo/UndoDeletePhoto.java
new file mode 100644 (file)
index 0000000..cfc1662
--- /dev/null
@@ -0,0 +1,73 @@
+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 a delete of a single photo, either with or without point\r
+ */\r
+public class UndoDeletePhoto implements UndoOperation\r
+{\r
+       private int _photoIndex = -1;\r
+       private Photo _photo = null;\r
+       private int _pointIndex = -1;\r
+       private DataPoint _point = null;\r
+\r
+\r
+       /**\r
+        * Constructor\r
+        * @param inPhoto photo\r
+        * @param inPhotoIndex index number of photo within photo list\r
+        * @param inPoint data point\r
+        * @param inPointIndex index number of point within track\r
+        */\r
+       public UndoDeletePhoto(Photo inPhoto, int inPhotoIndex, DataPoint inPoint, int inPointIndex)\r
+       {\r
+               _photo = inPhoto;\r
+               _photoIndex = inPhotoIndex;\r
+               _point = inPoint;\r
+               _pointIndex = inPointIndex;\r
+       }\r
+\r
+\r
+       /**\r
+        * @return description of operation including photo name\r
+        */\r
+       public String getDescription()\r
+       {\r
+               String desc = I18nManager.getText("undo.deletephoto") + " " + _photo.getFile().getName();\r
+               return desc;\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 photo\r
+               inTrackInfo.getPhotoList().addPhoto(_photo, _photoIndex);\r
+               // if there's a point to restore, restore it\r
+               if (_point != null)\r
+               {\r
+                       if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex))\r
+                       {\r
+                               throw new UndoException(getDescription());\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // update needed if not already triggered by track update\r
+                       inTrackInfo.triggerUpdate();\r
+               }\r
+               // Ensure that photo is associated with point and vice versa\r
+               _photo.setDataPoint(_point);\r
+               if (_point != null)\r
+               {\r
+                       _point.setPhoto(_photo);\r
+               }\r
+       }\r
+}\r