--- /dev/null
+package tim.prune.undo;\r
+\r
+import tim.prune.I18nManager;\r
+import tim.prune.data.DataPoint;\r
+import tim.prune.data.TrackInfo;\r
+\r
+/**\r
+ * Operation to undo a delete of a single point\r
+ */\r
+public class UndoDeletePoint extends UndoDeleteOperation\r
+{\r
+ private int _pointIndex = -1;\r
+ private DataPoint _point = null;\r
+ private int _photoIndex = -1;\r
+ private int _audioIndex = -1;\r
+ private boolean _segmentStart = false;\r
+\r
+\r
+ /**\r
+ * Constructor\r
+ * @param inPointIndex index number of point within track\r
+ * @param inPoint data point\r
+ * @param inPhotoIndex index number of photo within photo list\r
+ * @param inAudioIndex index number of audio within audio list\r
+ * @param inSegmentStart true if following track point starts new segment\r
+ */\r
+ public UndoDeletePoint(int inPointIndex, DataPoint inPoint, int inPhotoIndex, int inAudioIndex,\r
+ boolean inSegmentStart)\r
+ {\r
+ _pointIndex = inPointIndex;\r
+ _point = inPoint;\r
+ _photoIndex = inPhotoIndex;\r
+ _audioIndex = inAudioIndex;\r
+ _segmentStart = inSegmentStart;\r
+ }\r
+\r
+\r
+ /**\r
+ * @return description of operation including point name if any\r
+ */\r
+ public String getDescription()\r
+ {\r
+ String desc = I18nManager.getText("undo.deletepoint");\r
+ String pointName = _point.getWaypointName();\r
+ if (pointName != null && !pointName.equals(""))\r
+ desc = desc + " " + pointName;\r
+ return desc;\r
+ }\r
+\r
+\r
+ /**\r
+ * Perform the undo operation on the given Track\r
+ * @param inTrackInfo TrackInfo object on which to perform the operation\r
+ */\r
+ public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
+ {\r
+ // restore point into track\r
+ if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex))\r
+ {\r
+ throw new UndoException(getDescription());\r
+ }\r
+ // Re-attach / Re-insert photo into list if necessary\r
+ if (_point.getPhoto() != null && _photoIndex > -1)\r
+ {\r
+ // Check if photo is still in list\r
+ if (!inTrackInfo.getPhotoList().contains(_point.getPhoto()))\r
+ {\r
+ // photo has been removed - need to reinsert\r
+ inTrackInfo.getPhotoList().addPhoto(_point.getPhoto(), _photoIndex);\r
+ }\r
+ // Ensure that photo is associated with point\r
+ if (_point.getPhoto().getDataPoint() != _point) {\r
+ _point.getPhoto().setDataPoint(_point);\r
+ }\r
+ }\r
+ // Re-add audio as well if necessary\r
+ if (_point.getAudio() != null && _audioIndex > -1)\r
+ {\r
+ // add audio object to list\r
+ inTrackInfo.getAudioList().addAudio(_point.getAudio(), _audioIndex);\r
+ _point.getAudio().setDataPoint(_point);\r
+ }\r
+ // Restore previous status of following track point if necessary\r
+ if (!_segmentStart)\r
+ {\r
+ // Deletion of point can only set following point to true, so only need to set it back to false\r
+ DataPoint nextTrackPoint = inTrackInfo.getTrack().getNextTrackPoint(_pointIndex + 1);\r
+ if (nextTrackPoint != null) {\r
+ nextTrackPoint.setSegmentStart(false);\r
+ }\r
+ }\r
+ // If there's a current point or range selected, maybe need to adjust start and/or end\r
+ modifySelection(inTrackInfo, _pointIndex, _pointIndex);\r
+ }\r
+}\r