]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoDeletePoint.java
daab9fd574c89d177737f9adaf2a34636d09e6bf
[GpsPrune.git] / tim / prune / undo / UndoDeletePoint.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.TrackInfo;\r
6 \r
7 /**\r
8  * Operation to undo a delete of a single point\r
9  */\r
10 public class UndoDeletePoint implements UndoOperation\r
11 {\r
12         private int _pointIndex = -1;\r
13         private DataPoint _point = null;\r
14         private int _photoIndex = -1;\r
15 \r
16 \r
17         /**\r
18          * Constructor\r
19          * @param inPointIndex index number of point within track\r
20          * @param inPoint data point\r
21          * @param inPhotoIndex index number of photo within photo list\r
22          */\r
23         public UndoDeletePoint(int inPointIndex, DataPoint inPoint, int inPhotoIndex)\r
24         {\r
25                 _pointIndex = inPointIndex;\r
26                 _point = inPoint;\r
27                 _photoIndex = inPhotoIndex;\r
28         }\r
29 \r
30 \r
31         /**\r
32          * @return description of operation including point name if any\r
33          */\r
34         public String getDescription()\r
35         {\r
36                 String desc = I18nManager.getText("undo.deletepoint");\r
37                 String pointName = _point.getWaypointName();\r
38                 if (pointName != null && !pointName.equals(""))\r
39                         desc = desc + " " + pointName;\r
40                 return desc;\r
41         }\r
42 \r
43 \r
44         /**\r
45          * Perform the undo operation on the given Track\r
46          * @param inTrackInfo TrackInfo object on which to perform the operation\r
47          */\r
48         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
49         {\r
50                 // restore point into track\r
51                 if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex))\r
52                 {\r
53                         throw new UndoException(getDescription());\r
54                 }\r
55                 // Re-attach / Re-insert photo into list if necessary\r
56                 if (_point.getPhoto() != null && _photoIndex > -1)\r
57                 {\r
58                         // Check if photo is still in list\r
59                         if (!inTrackInfo.getPhotoList().contains(_point.getPhoto()))\r
60                         {\r
61                                 // photo has been removed - need to reinsert\r
62                                 inTrackInfo.getPhotoList().addPhoto(_point.getPhoto(), _photoIndex);\r
63                         }\r
64                         // Ensure that photo is associated with point\r
65                         _point.getPhoto().setDataPoint(_point);\r
66                 }\r
67         }\r
68 }\r