--- /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 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.correlatephotos") + " (" + _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
+ // Only need to look at connected photos, since correlation wouldn't disconnect\r
+ if (photo.getCurrentStatus() == Photo.Status.CONNECTED)\r
+ {\r
+ DataPoint prevPoint = _photoPoints[i];\r
+ DataPoint currPoint = photo.getDataPoint();\r
+ photo.setDataPoint(prevPoint);\r
+ if (currPoint != null) {\r
+ currPoint.setPhoto(null); // disconnect\r
+ }\r
+ if (prevPoint != null) {\r
+ prevPoint.setPhoto(photo); // reconnect to prev point\r
+ }\r
+ }\r
+ }\r
+ // clear selection\r
+ inTrackInfo.getSelection().clearAll();\r
+ }\r
+}\r