]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoDeletePoint.java
adb2ea397d0baffcb3d5f410c850c8d3cc3b3cd1
[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         private boolean _segmentStart = false;\r
16 \r
17 \r
18         /**\r
19          * Constructor\r
20          * @param inPointIndex index number of point within track\r
21          * @param inPoint data point\r
22          * @param inPhotoIndex index number of photo within photo list\r
23          * @param inSegmentStart true if following track point starts new segment\r
24          */\r
25         public UndoDeletePoint(int inPointIndex, DataPoint inPoint, int inPhotoIndex, boolean inSegmentStart)\r
26         {\r
27                 _pointIndex = inPointIndex;\r
28                 _point = inPoint;\r
29                 _photoIndex = inPhotoIndex;\r
30                 _segmentStart = inSegmentStart;\r
31         }\r
32 \r
33 \r
34         /**\r
35          * @return description of operation including point name if any\r
36          */\r
37         public String getDescription()\r
38         {\r
39                 String desc = I18nManager.getText("undo.deletepoint");\r
40                 String pointName = _point.getWaypointName();\r
41                 if (pointName != null && !pointName.equals(""))\r
42                         desc = desc + " " + pointName;\r
43                 return desc;\r
44         }\r
45 \r
46 \r
47         /**\r
48          * Perform the undo operation on the given Track\r
49          * @param inTrackInfo TrackInfo object on which to perform the operation\r
50          */\r
51         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
52         {\r
53                 // restore point into track\r
54                 if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex))\r
55                 {\r
56                         throw new UndoException(getDescription());\r
57                 }\r
58                 // Re-attach / Re-insert photo into list if necessary\r
59                 if (_point.getPhoto() != null && _photoIndex > -1)\r
60                 {\r
61                         // Check if photo is still in list\r
62                         if (!inTrackInfo.getPhotoList().contains(_point.getPhoto()))\r
63                         {\r
64                                 // photo has been removed - need to reinsert\r
65                                 inTrackInfo.getPhotoList().addPhoto(_point.getPhoto(), _photoIndex);\r
66                         }\r
67                         // Ensure that photo is associated with point\r
68                         if (_point.getPhoto().getDataPoint() != _point) {\r
69                                 _point.getPhoto().setDataPoint(_point);\r
70                         }\r
71                 }\r
72                 // Restore previous status of following track point if necessary\r
73                 if (!_segmentStart)\r
74                 {\r
75                         // Deletion of point can only set following point to true, so only need to set it back to false\r
76                         DataPoint nextTrackPoint = inTrackInfo.getTrack().getNextTrackPoint(_pointIndex + 1);\r
77                         if (nextTrackPoint != null) {\r
78                                 nextTrackPoint.setSegmentStart(false);\r
79                         }\r
80                 }\r
81         }\r
82 }\r