1 package tim.prune.undo;
3 import tim.prune.I18nManager;
4 import tim.prune.UpdateMessageBroker;
5 import tim.prune.data.Altitude;
6 import tim.prune.data.DataPoint;
7 import tim.prune.data.TrackInfo;
10 * Undo removing (ie: restore the original) altitude from points
12 public class UndoRemoveAltitudes implements UndoOperation
14 /** Start index of section */
15 private int _startIndex;
16 /** altitude values before operation */
17 private Altitude[] _altitudes;
22 * @param inTrackInfo track info object
24 public UndoRemoveAltitudes(TrackInfo inTrackInfo, int inStart, int inEnd)
26 _startIndex = inStart;
27 final int numPoints = inEnd - inStart + 1;
28 // Make array of cloned altitude objects
29 _altitudes = new Altitude[numPoints];
30 for (int i=0; i<numPoints; i++) {
31 Altitude a = inTrackInfo.getTrack().getPoint(_startIndex+i).getAltitude();
32 if (a != null && a.isValid()) {
33 _altitudes[i] = a.clone();
40 * @return description of operation including number of points adjusted
42 public String getDescription()
44 return I18nManager.getText("undo.removealtitudes") + " (" + (_altitudes.length) + ")";
49 * Perform the undo operation on the given Track
50 * @param inTrackInfo TrackInfo object on which to perform the operation
52 public void performUndo(TrackInfo inTrackInfo) throws UndoException
54 // Perform the inverse operation
55 final int numPoints = _altitudes.length;
56 for (int i=0; i<numPoints; i++)
58 DataPoint point = inTrackInfo.getTrack().getPoint(i+_startIndex);
59 point.resetAltitude(_altitudes[i]);
62 inTrackInfo.getSelection().markInvalid();
63 UpdateMessageBroker.informSubscribers();