]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoLoadPhotos.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / undo / UndoLoadPhotos.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 a load photos operation\r
10  */\r
11 public class UndoLoadPhotos implements UndoOperation\r
12 {\r
13         private int _numPhotos = -1;\r
14         private int _numPoints = -1;\r
15 \r
16 \r
17         /**\r
18          * Constructor\r
19          * @param inNumPhotos number of photos loaded\r
20          * @param inNumPoints number of points loaded\r
21          */\r
22         public UndoLoadPhotos(int inNumPhotos, int inNumPoints)\r
23         {\r
24                 _numPhotos = inNumPhotos;\r
25                 _numPoints = inNumPoints;\r
26         }\r
27 \r
28 \r
29         /**\r
30          * @return description of operation including number of photos loaded\r
31          */\r
32         public String getDescription()\r
33         {\r
34                 String desc = I18nManager.getText("undo.loadphotos");\r
35                 if (_numPhotos > 0)\r
36                         desc = desc + " (" + _numPhotos + ")";\r
37                 return desc;\r
38         }\r
39 \r
40 \r
41         /**\r
42          * Perform the undo operation on the given Track\r
43          * Delete both track points and Photo objects\r
44          * @param inTrackInfo TrackInfo object on which to perform the operation\r
45          */\r
46         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
47         {\r
48                 int cropIndex;\r
49                 // crop track to previous size\r
50                 if (_numPoints > 0)\r
51                 {\r
52                         cropIndex = inTrackInfo.getTrack().getNumPoints() - _numPoints;\r
53                         inTrackInfo.getTrack().cropTo(cropIndex);\r
54                 }\r
55                 else\r
56                 {\r
57                         // Loop through the points (if any) and detach them\r
58                         for (int i=0; i<_numPhotos; i++)\r
59                         {\r
60                                 Photo photo = inTrackInfo.getPhotoList().getPhoto(inTrackInfo.getPhotoList().getNumPhotos() - 1 - i);\r
61                                 if (photo.isConnected()) {\r
62                                         DataPoint point = photo.getDataPoint();\r
63                                         if (point != null) {point.setPhoto(null);}\r
64                                 }\r
65                         }\r
66                 }\r
67                 // crop photo list to previous size\r
68                 cropIndex = inTrackInfo.getPhotoList().getNumPhotos() - _numPhotos;\r
69                 inTrackInfo.getPhotoList().cropTo(cropIndex);\r
70                 // clear selection\r
71                 inTrackInfo.getSelection().clearAll();\r
72         }\r
73 }