]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoAddAltitudeOffset.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / undo / UndoAddAltitudeOffset.java
1 package tim.prune.undo;
2
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;
8
9 /**
10  * Undo addition/subtraction of an altitude offset
11  */
12 public class UndoAddAltitudeOffset implements UndoOperation
13 {
14         /** Start index of section */
15         private int _startIndex;
16         /** altitude values before operation */
17         private Altitude[] _altitudes;
18
19
20         /**
21          * Constructor
22          * @param inTrackInfo track info object
23          */
24         public UndoAddAltitudeOffset(TrackInfo inTrackInfo)
25         {
26                 _startIndex = inTrackInfo.getSelection().getStart();
27                 final int endIndex = inTrackInfo.getSelection().getEnd();
28                 final int numPoints = endIndex - _startIndex + 1;
29                 // Make array of cloned altitude objects
30                 _altitudes = new Altitude[numPoints];
31                 for (int i=0; i<numPoints; i++) {
32                         Altitude a = inTrackInfo.getTrack().getPoint(_startIndex+i).getAltitude();
33                         if (a != null && a.isValid()) {
34                                 _altitudes[i] = a.clone();
35                         }
36                 }
37         }
38
39
40         /**
41          * @return description of operation including number of points adjusted
42          */
43         public String getDescription()
44         {
45                 return I18nManager.getText("undo.addaltitudeoffset") + " (" + (_altitudes.length) + ")";
46         }
47
48
49         /**
50          * Perform the undo operation on the given Track
51          * @param inTrackInfo TrackInfo object on which to perform the operation
52          */
53         public void performUndo(TrackInfo inTrackInfo) throws UndoException
54         {
55                 // Perform the inverse operation
56                 final int numPoints = _altitudes.length;
57                 for (int i=0; i<numPoints; i++)
58                 {
59                         DataPoint point = inTrackInfo.getTrack().getPoint(i+_startIndex);
60                         point.getAltitude().reset(_altitudes[i]);
61                         point.setModified(true);
62                 }
63                 _altitudes = null;
64                 inTrackInfo.getSelection().markInvalid();
65                 UpdateMessageBroker.informSubscribers();
66         }
67 }