]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoInterpolate.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / undo / UndoInterpolate.java
1 package tim.prune.undo;\r
2 \r
3 import tim.prune.I18nManager;\r
4 import tim.prune.data.DataPoint;\r
5 import tim.prune.data.TrackInfo;\r
6 \r
7 /**\r
8  * Operation to undo an interpolation\r
9  */\r
10 public class UndoInterpolate implements UndoOperation\r
11 {\r
12         private int _startIndex = 0;\r
13         private int _totalInserted = 0;\r
14         private DataPoint[] _points = null;\r
15 \r
16 \r
17         /**\r
18          * Constructor\r
19          * @param inTrackInfo track info object\r
20          * @param inTotalInserted total number of points inserted\r
21          */\r
22         public UndoInterpolate(TrackInfo inTrackInfo, int inTotalInserted)\r
23         {\r
24                 _startIndex = inTrackInfo.getSelection().getStart();\r
25                 _points = inTrackInfo.cloneSelectedRange();\r
26                 _totalInserted = inTotalInserted;\r
27         }\r
28 \r
29 \r
30         /**\r
31          * @return description of operation including parameters\r
32          */\r
33         public String getDescription()\r
34         {\r
35                 return I18nManager.getText("undo.insert") + " (" + _totalInserted + ")";\r
36         }\r
37 \r
38 \r
39         /**\r
40          * Perform the undo operation on the given TrackInfo\r
41          * @param inTrackInfo TrackInfo object on which to perform the operation\r
42          */\r
43         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
44         {\r
45                 // Work out how many points were in the track before the interpolation\r
46                 final int newSize = inTrackInfo.getTrack().getNumPoints() - _totalInserted;\r
47                 DataPoint[] oldPoints = inTrackInfo.getTrack().cloneContents();\r
48                 DataPoint[] newPoints = new DataPoint[newSize];\r
49 \r
50                 // Restore track to previous values\r
51                 System.arraycopy(oldPoints, 0, newPoints, 0, _startIndex);\r
52                 System.arraycopy(_points, 0, newPoints, _startIndex, _points.length);\r
53                 int endIndex = _startIndex + _points.length;\r
54                 System.arraycopy(oldPoints, endIndex + _totalInserted, newPoints, endIndex, newSize - endIndex);\r
55 \r
56                 inTrackInfo.getTrack().replaceContents(newPoints);\r
57                 // reset selection\r
58                 inTrackInfo.getSelection().clearAll();\r
59         }\r
60 }\r