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
*/\r
public class UndoLoadPhotos implements UndoOperation\r
{\r
- private int _numLoaded = -1;\r
+ private int _numPhotos = -1;\r
+ private int _numPoints = -1;\r
\r
- // TODO: Handle possibility of photos not having datapoints (yet)\r
\r
/**\r
* Constructor\r
- * @param inNumLoaded number of photos loaded\r
+ * @param inNumPhotos number of photos loaded\r
+ * @param inNumPoints number of points loaded\r
*/\r
- public UndoLoadPhotos(int inNumLoaded)\r
+ public UndoLoadPhotos(int inNumPhotos, int inNumPoints)\r
{\r
- _numLoaded = inNumLoaded;\r
+ _numPhotos = inNumPhotos;\r
+ _numPoints = inNumPoints;\r
}\r
\r
\r
public String getDescription()\r
{\r
String desc = I18nManager.getText("undo.loadphotos");\r
- if (_numLoaded > 0)\r
- desc = desc + " (" + _numLoaded + ")";\r
+ if (_numPhotos > 0)\r
+ desc = desc + " (" + _numPhotos + ")";\r
return desc;\r
}\r
\r
*/\r
public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
{\r
+ int cropIndex;\r
// crop track to previous size\r
- int cropIndex = inTrackInfo.getTrack().getNumPoints() - _numLoaded;\r
- inTrackInfo.getTrack().cropTo(cropIndex);\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
- // (currently it is assumed that the number of points is the same as number of photos)\r
- cropIndex = inTrackInfo.getPhotoList().getNumPhotos() - _numLoaded;\r
+ cropIndex = inTrackInfo.getPhotoList().getNumPhotos() - _numPhotos;\r
inTrackInfo.getPhotoList().cropTo(cropIndex);\r
// clear selection\r
inTrackInfo.getSelection().clearAll();\r