1 package tim.prune.undo;
3 import tim.prune.I18nManager;
4 import tim.prune.UpdateMessageBroker;
5 import tim.prune.data.DataPoint;
6 import tim.prune.data.Field;
7 import tim.prune.data.Track;
8 import tim.prune.data.TrackInfo;
11 * Undo lookup of altitudes from SRTM data
13 public class UndoLookupSrtm implements UndoOperation
15 /** DataPoint objects which didn't have altitudes before */
16 private DataPoint[] _points;
17 /** Altitude strings if present */
18 private String[] _altitudes;
23 * @param inTrackInfo track info object
25 public UndoLookupSrtm(TrackInfo inTrackInfo)
27 Track track = inTrackInfo.getTrack();
28 int numPoints = track.getNumPoints();
29 // Make arrays of points and altitudes
30 _points = new DataPoint[numPoints];
31 _altitudes = new String[numPoints];
32 for (int i=0; i<numPoints; i++)
34 DataPoint point = track.getPoint(i);
35 if (!point.hasAltitude() || point.getAltitude().getValue() == 0)
38 if (point.hasAltitude()) {
39 _altitudes[i] = point.getFieldValue(Field.ALTITUDE);
47 * @return description of operation
49 public String getDescription()
51 return I18nManager.getText("undo.lookupsrtm");
56 * Perform the undo operation on the given Track
57 * @param inTrackInfo TrackInfo object on which to perform the operation
59 public void performUndo(TrackInfo inTrackInfo) throws UndoException
61 // Loop through points again, and reset altitudes if they have one
62 final int numPoints = _points.length;
63 for (int i=0; i<numPoints; i++) {
64 DataPoint point = _points[i];
65 if (point != null && point.hasAltitude()) {
66 if (_altitudes[i] == null) {
67 point.setFieldValue(Field.ALTITUDE, null, true);
70 point.setFieldValue(Field.ALTITUDE, _altitudes[i], true);
75 UpdateMessageBroker.informSubscribers();