]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoDeletePhoto.java
cfc166271131eec1f41f6a79ba3bcfe8dd29a354
[GpsPrune.git] / tim / prune / undo / UndoDeletePhoto.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 delete of a single photo, either with or without point\r
10  */\r
11 public class UndoDeletePhoto implements UndoOperation\r
12 {\r
13         private int _photoIndex = -1;\r
14         private Photo _photo = null;\r
15         private int _pointIndex = -1;\r
16         private DataPoint _point = null;\r
17 \r
18 \r
19         /**\r
20          * Constructor\r
21          * @param inPhoto photo\r
22          * @param inPhotoIndex index number of photo within photo list\r
23          * @param inPoint data point\r
24          * @param inPointIndex index number of point within track\r
25          */\r
26         public UndoDeletePhoto(Photo inPhoto, int inPhotoIndex, DataPoint inPoint, int inPointIndex)\r
27         {\r
28                 _photo = inPhoto;\r
29                 _photoIndex = inPhotoIndex;\r
30                 _point = inPoint;\r
31                 _pointIndex = inPointIndex;\r
32         }\r
33 \r
34 \r
35         /**\r
36          * @return description of operation including photo name\r
37          */\r
38         public String getDescription()\r
39         {\r
40                 String desc = I18nManager.getText("undo.deletephoto") + " " + _photo.getFile().getName();\r
41                 return desc;\r
42         }\r
43 \r
44 \r
45         /**\r
46          * Perform the undo operation on the given Track\r
47          * @param inTrackInfo TrackInfo object on which to perform the operation\r
48          */\r
49         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
50         {\r
51                 // restore photo\r
52                 inTrackInfo.getPhotoList().addPhoto(_photo, _photoIndex);\r
53                 // if there's a point to restore, restore it\r
54                 if (_point != null)\r
55                 {\r
56                         if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex))\r
57                         {\r
58                                 throw new UndoException(getDescription());\r
59                         }\r
60                 }\r
61                 else\r
62                 {\r
63                         // update needed if not already triggered by track update\r
64                         inTrackInfo.triggerUpdate();\r
65                 }\r
66                 // Ensure that photo is associated with point and vice versa\r
67                 _photo.setDataPoint(_point);\r
68                 if (_point != null)\r
69                 {\r
70                         _point.setPhoto(_photo);\r
71                 }\r
72         }\r
73 }\r