1 package tim.prune.undo;
\r
3 import tim.prune.I18nManager;
\r
4 import tim.prune.UpdateMessageBroker;
\r
5 import tim.prune.data.DataPoint;
\r
6 import tim.prune.data.Field;
\r
7 import tim.prune.data.Track;
\r
8 import tim.prune.data.TrackInfo;
\r
11 * Operation to undo a conversion from names to times
\r
13 public class UndoConvertNamesToTimes implements UndoOperation
\r
15 /** Start and end indices of section */
\r
16 private int _startIndex, _endIndex;
\r
17 /** Waypoint names before operation */
\r
18 private String[] _waypointNames = null;
\r
19 /** Timestamp strings before operation */
\r
20 private String[] _timestamps = null;
\r
24 * @param inTrackInfo track info object to copy values from
\r
26 public UndoConvertNamesToTimes(TrackInfo inTrackInfo)
\r
28 _startIndex = inTrackInfo.getSelection().getStart();
\r
29 _endIndex = inTrackInfo.getSelection().getEnd();
\r
30 final int numPoints = _endIndex - _startIndex + 1;
\r
31 _waypointNames = new String[numPoints];
\r
32 _timestamps = new String[numPoints];
\r
33 // Loop over points in selection, and copy names and timestamps
\r
34 for (int i=_startIndex; i<=_endIndex; i++)
\r
36 DataPoint point = inTrackInfo.getTrack().getPoint(i);
\r
37 if (point.isWaypoint())
\r
39 _waypointNames[i-_startIndex] = point.getWaypointName();
\r
40 _timestamps[i-_startIndex] = point.getFieldValue(Field.TIMESTAMP);
\r
47 * @return description of operation
\r
49 public String getDescription()
\r
51 return I18nManager.getText("undo.convertnamestotimes");
\r
56 * Perform the undo operation on the given Track
\r
57 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
59 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
62 Track track = inTrackInfo.getTrack();
\r
63 if (track.getNumPoints() <= _endIndex || _endIndex <= _startIndex) {
\r
64 throw new UndoException("Cannot undo conversion, track length doesn't match");
\r
66 // Loop over points in selection and replace names and timestamps
\r
67 for (int i=_startIndex; i<=_endIndex; i++)
\r
69 String storedName = _waypointNames[i-_startIndex];
\r
70 if (storedName != null)
\r
72 // point had a name before the operation, so might have been converted
\r
73 DataPoint point = track.getPoint(i);
\r
74 point.setFieldValue(Field.WAYPT_NAME, storedName, true);
\r
75 point.setFieldValue(Field.TIMESTAMP, _timestamps[i-_startIndex], true);
\r
78 track.requestRescale();
\r
79 UpdateMessageBroker.informSubscribers();
\r