--- /dev/null
+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 load photos operation\r
+ */\r
+public class UndoLoadPhotos implements UndoOperation\r
+{\r
+ private int _numPhotos = -1;\r
+ private int _numPoints = -1;\r
+\r
+\r
+ /**\r
+ * Constructor\r
+ * @param inNumPhotos number of photos loaded\r
+ * @param inNumPoints number of points loaded\r
+ */\r
+ public UndoLoadPhotos(int inNumPhotos, int inNumPoints)\r
+ {\r
+ _numPhotos = inNumPhotos;\r
+ _numPoints = inNumPoints;\r
+ }\r
+\r
+\r
+ /**\r
+ * @return description of operation including number of photos loaded\r
+ */\r
+ public String getDescription()\r
+ {\r
+ String desc = I18nManager.getText("undo.loadphotos");\r
+ if (_numPhotos > 0)\r
+ desc = desc + " (" + _numPhotos + ")";\r
+ return desc;\r
+ }\r
+\r
+\r
+ /**\r
+ * Perform the undo operation on the given Track\r
+ * Delete both track points and Photo objects\r
+ * @param inTrackInfo TrackInfo object on which to perform the operation\r
+ */\r
+ public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
+ {\r
+ int cropIndex;\r
+ // crop track to previous size\r
+ if (_numPoints > 0)\r
+ {\r
+ cropIndex = inTrackInfo.getTrack().getNumPoints() - _numPoints;\r
+ inTrackInfo.getTrack().cropTo(cropIndex);\r
+ }\r
+ else\r
+ {\r
+ // Loop through the points (if any) and detach them\r
+ for (int i=0; i<_numPhotos; i++)\r
+ {\r
+ Photo photo = inTrackInfo.getPhotoList().getPhoto(inTrackInfo.getPhotoList().getNumPhotos() - 1 - i);\r
+ if (photo.isConnected()) {\r
+ DataPoint point = photo.getDataPoint();\r
+ if (point != null) {point.setPhoto(null);}\r
+ }\r
+ }\r
+ }\r
+ // crop photo list to previous size\r
+ cropIndex = inTrackInfo.getPhotoList().getNumPhotos() - _numPhotos;\r
+ inTrackInfo.getPhotoList().cropTo(cropIndex);\r
+ // clear selection\r
+ inTrackInfo.getSelection().clearAll();\r
+ }\r
+}
\ No newline at end of file