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 extends UndoDeleteOperation
\r
12 private int _pointIndex = -1;
\r
13 private DataPoint _point = null;
\r
14 private int _photoIndex = -1;
\r
15 private int _audioIndex = -1;
\r
16 private boolean _segmentStart = false;
\r
21 * @param inPointIndex index number of point within track
\r
22 * @param inPoint data point
\r
23 * @param inPhotoIndex index number of photo within photo list
\r
24 * @param inAudioIndex index number of audio within audio list
\r
25 * @param inSegmentStart true if following track point starts new segment
\r
27 public UndoDeletePoint(int inPointIndex, DataPoint inPoint, int inPhotoIndex, int inAudioIndex,
\r
28 boolean inSegmentStart)
\r
30 _pointIndex = inPointIndex;
\r
32 _photoIndex = inPhotoIndex;
\r
33 _audioIndex = inAudioIndex;
\r
34 _segmentStart = inSegmentStart;
\r
39 * @return description of operation including point name if any
\r
41 public String getDescription()
\r
43 String desc = I18nManager.getText("undo.deletepoint");
\r
44 String pointName = _point.getWaypointName();
\r
45 if (pointName != null && !pointName.equals(""))
\r
46 desc = desc + " " + pointName;
\r
52 * Perform the undo operation on the given Track
\r
53 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
55 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
57 // restore point into track
\r
58 if (!inTrackInfo.getTrack().insertPoint(_point, _pointIndex))
\r
60 throw new UndoException(getDescription());
\r
62 // Re-attach / Re-insert photo into list if necessary
\r
63 if (_point.getPhoto() != null && _photoIndex > -1)
\r
65 // Check if photo is still in list
\r
66 if (!inTrackInfo.getPhotoList().contains(_point.getPhoto()))
\r
68 // photo has been removed - need to reinsert
\r
69 inTrackInfo.getPhotoList().addPhoto(_point.getPhoto(), _photoIndex);
\r
71 // Ensure that photo is associated with point
\r
72 if (_point.getPhoto().getDataPoint() != _point) {
\r
73 _point.getPhoto().setDataPoint(_point);
\r
76 // Re-add audio as well if necessary
\r
77 if (_point.getAudio() != null && _audioIndex > -1)
\r
79 // add audio object to list
\r
80 inTrackInfo.getAudioList().addAudio(_point.getAudio(), _audioIndex);
\r
81 _point.getAudio().setDataPoint(_point);
\r
83 // Restore previous status of following track point if necessary
\r
86 // Deletion of point can only set following point to true, so only need to set it back to false
\r
87 DataPoint nextTrackPoint = inTrackInfo.getTrack().getNextTrackPoint(_pointIndex + 1);
\r
88 if (nextTrackPoint != null) {
\r
89 nextTrackPoint.setSegmentStart(false);
\r
92 // If there's a current point or range selected, maybe need to adjust start and/or end
\r
93 modifySelection(inTrackInfo, _pointIndex, _pointIndex);
\r