]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoCorrelatePhotos.java
Version 11, August 2010
[GpsPrune.git] / tim / prune / undo / UndoCorrelatePhotos.java
1 package tim.prune.undo;\r
2 \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
7 \r
8 /**\r
9  * Operation to undo an auto-correlation of photos with points\r
10  */\r
11 public class UndoCorrelatePhotos implements UndoOperation\r
12 {\r
13         private DataPoint[] _contents = null;\r
14         private DataPoint[] _photoPoints = null;\r
15         private int _numPhotosCorrelated = -1;\r
16 \r
17 \r
18         /**\r
19          * Constructor\r
20          * @param inTrackInfo track information\r
21          */\r
22         public UndoCorrelatePhotos(TrackInfo inTrackInfo)\r
23         {\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
31                 }\r
32         }\r
33 \r
34         /**\r
35          * @param inNumCorrelated number of photos correlated\r
36          */\r
37         public void setNumPhotosCorrelated(int inNumCorrelated)\r
38         {\r
39                 _numPhotosCorrelated = inNumCorrelated;\r
40         }\r
41 \r
42         /**\r
43          * @return description of operation including parameters\r
44          */\r
45         public String getDescription()\r
46         {\r
47                 return I18nManager.getText("undo.correlate") + " (" + _numPhotosCorrelated + ")";\r
48         }\r
49 \r
50 \r
51         /**\r
52          * Perform the undo operation on the given Track\r
53          * @param inTrackInfo TrackInfo object on which to perform the operation\r
54          */\r
55         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
56         {\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
61                 {\r
62                         Photo photo = inTrackInfo.getPhotoList().getPhoto(i);\r
63                         // Only need to look at connected photos, if they're still tagged then leave them\r
64                         if (photo.getCurrentStatus() == Photo.Status.CONNECTED)\r
65                         {\r
66                                 DataPoint point = _photoPoints[i];\r
67                                 photo.setDataPoint(point);\r
68                                 if (point != null) {\r
69                                         point.setPhoto(photo);\r
70                                 }\r
71                         }\r
72                 }\r
73                 // clear selection\r
74                 inTrackInfo.getSelection().clearAll();\r
75         }\r
76 }