1 package tim.prune.undo;
\r
3 import tim.prune.I18nManager;
\r
4 import tim.prune.data.DataPoint;
\r
5 import tim.prune.data.Photo;
\r
6 import tim.prune.data.TrackInfo;
\r
9 * Operation to undo an auto-correlation of photos with points
\r
11 public class UndoCorrelatePhotos implements UndoOperation
\r
13 private DataPoint[] _contents = null;
\r
14 private DataPoint[] _photoPoints = null;
\r
15 private int _numPhotosCorrelated = -1;
\r
20 * @param inTrackInfo track information
\r
22 public UndoCorrelatePhotos(TrackInfo inTrackInfo)
\r
24 // Copy track contents
\r
25 _contents = inTrackInfo.getTrack().cloneContents();
\r
26 // Copy points associated with photos before correlation
\r
27 int numPhotos = inTrackInfo.getPhotoList().getNumPhotos();
\r
28 _photoPoints = new DataPoint[numPhotos];
\r
29 for (int i=0; i<numPhotos; i++) {
\r
30 _photoPoints[i] = inTrackInfo.getPhotoList().getPhoto(i).getDataPoint();
\r
35 * @param inNumCorrelated number of photos correlated
\r
37 public void setNumPhotosCorrelated(int inNumCorrelated)
\r
39 _numPhotosCorrelated = inNumCorrelated;
\r
43 * @return description of operation including parameters
\r
45 public String getDescription()
\r
47 return I18nManager.getText("undo.correlatephotos") + " (" + _numPhotosCorrelated + ")";
\r
52 * Perform the undo operation on the given Track
\r
53 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
55 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
57 // restore track to previous values
\r
58 inTrackInfo.getTrack().replaceContents(_contents);
\r
59 // restore photo association
\r
60 for (int i=0; i<_photoPoints.length; i++)
\r
62 Photo photo = inTrackInfo.getPhotoList().getPhoto(i);
\r
63 // Only need to look at connected photos, since correlation wouldn't disconnect
\r
64 if (photo.getCurrentStatus() == Photo.Status.CONNECTED)
\r
66 DataPoint prevPoint = _photoPoints[i];
\r
67 DataPoint currPoint = photo.getDataPoint();
\r
68 photo.setDataPoint(prevPoint);
\r
69 if (currPoint != null) {
\r
70 currPoint.setPhoto(null); // disconnect
\r
72 if (prevPoint != null) {
\r
73 prevPoint.setPhoto(photo); // reconnect to prev point
\r
78 inTrackInfo.getSelection().clearAll();
\r