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++) {
33 DataPoint point = track.getPoint(i);
34 if (!point.hasAltitude() || point.getAltitude().getValue() == 0) {
36 if (point.hasAltitude()) {
37 _altitudes[i] = point.getFieldValue(Field.ALTITUDE);
45 * @return description of operation
47 public String getDescription()
49 return I18nManager.getText("undo.lookupsrtm");
54 * Perform the undo operation on the given Track
55 * @param inTrackInfo TrackInfo object on which to perform the operation
57 public void performUndo(TrackInfo inTrackInfo) throws UndoException
59 // Loop through points again, and reset altitudes if they have one
60 final int numPoints = _points.length;
61 for (int i=0; i<numPoints; i++) {
62 DataPoint point = _points[i];
63 if (point != null && point.hasAltitude()) {
64 if (_altitudes[i] == null) {
65 point.setFieldValue(Field.ALTITUDE, null, true);
68 point.setFieldValue(Field.ALTITUDE, _altitudes[i], true);
73 UpdateMessageBroker.informSubscribers();