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