]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoDeleteRange.java
4e526cd8193d99b5c73154d3326ff2c2a0f6b904
[GpsPrune.git] / tim / prune / undo / UndoDeleteRange.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.PhotoList;\r
6 import tim.prune.data.TrackInfo;\r
7 \r
8 /**\r
9  * Operation to undo a delete of a range of points\r
10  */\r
11 public class UndoDeleteRange implements UndoOperation\r
12 {\r
13         private int _startIndex = -1;\r
14         private DataPoint[] _points = null;\r
15         private PhotoList _photoList = null;\r
16 \r
17 \r
18         /**\r
19          * Constructor\r
20          * @param inIndex index number of point within track\r
21          * @param inPoint data point\r
22          */\r
23         public UndoDeleteRange(TrackInfo inTrackInfo)\r
24         {\r
25                 _startIndex = inTrackInfo.getSelection().getStart();\r
26                 _points = inTrackInfo.cloneSelectedRange();\r
27                 _photoList = inTrackInfo.getPhotoList().cloneList();\r
28         }\r
29 \r
30 \r
31         /**\r
32          * @return description of operation including range length\r
33          */\r
34         public String getDescription()\r
35         {\r
36                 return I18nManager.getText("undo.deleterange")\r
37                         + " (" + _points.length + ")";\r
38         }\r
39 \r
40 \r
41         /**\r
42          * Perform the undo operation on the given Track\r
43          * @param inTrackInfo TrackInfo object on which to perform the operation\r
44          */\r
45         public void performUndo(TrackInfo inTrackInfo)\r
46         {\r
47                 // restore photos to how they were before\r
48                 inTrackInfo.getPhotoList().restore(_photoList);\r
49                 // reconnect photos to points\r
50                 for (int i=0; i<_points.length; i++)\r
51                 {\r
52                         DataPoint point = _points[i];\r
53                         if (point != null && point.getPhoto() != null)\r
54                         {\r
55                                 point.getPhoto().setDataPoint(point);\r
56                         }\r
57                 }\r
58                 // restore point array into track\r
59                 inTrackInfo.getTrack().insertRange(_points, _startIndex);\r
60         }\r
61 }