1 package tim.prune.undo;
\r
3 import tim.prune.I18nManager;
\r
4 import tim.prune.data.DataPoint;
\r
5 import tim.prune.data.TrackInfo;
\r
8 * Operation to undo a delete of a single point
\r
10 public class UndoDeletePoint implements UndoOperation
\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
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
25 public UndoDeletePoint(int inPointIndex, DataPoint inPoint, int inPhotoIndex, boolean inSegmentStart)
\r
27 _pointIndex = inPointIndex;
\r
29 _photoIndex = inPhotoIndex;
\r
30 _segmentStart = inSegmentStart;
\r
35 * @return description of operation including point name if any
\r
37 public String getDescription()
\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
48 * Perform the undo operation on the given Track
\r
49 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
51 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
53 // restore point into track
\r
54 if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex))
\r
56 throw new UndoException(getDescription());
\r
58 // Re-attach / Re-insert photo into list if necessary
\r
59 if (_point.getPhoto() != null && _photoIndex > -1)
\r
61 // Check if photo is still in list
\r
62 if (!inTrackInfo.getPhotoList().contains(_point.getPhoto()))
\r
64 // photo has been removed - need to reinsert
\r
65 inTrackInfo.getPhotoList().addPhoto(_point.getPhoto(), _photoIndex);
\r
67 // Ensure that photo is associated with point
\r
68 _point.getPhoto().setDataPoint(_point);
\r
70 // Restore previous status of following track point if necessary
\r
73 // Deletion of point can only set following point to true, so only need to set it back to false
\r
74 DataPoint nextTrackPoint = inTrackInfo.getTrack().getNextTrackPoint(_pointIndex + 1);
\r
75 if (nextTrackPoint != null) {
\r
76 nextTrackPoint.setSegmentStart(false);
\r