]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoCompress.java
50582215aaf82aeb265c52b3cddac6ca5cb7b7b7
[GpsPrune.git] / tim / prune / undo / UndoCompress.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.Track;\r
6 import tim.prune.data.TrackInfo;\r
7 \r
8 /**\r
9  * Operation to undo a track compression\r
10  */\r
11 public class UndoCompress implements UndoOperation\r
12 {\r
13         private DataPoint[] _contents = null;\r
14         protected int _numPointsDeleted = -1;\r
15         private boolean[] _segmentStarts = null;\r
16 \r
17 \r
18         /**\r
19          * Constructor\r
20          * @param inTrack track contents to copy\r
21          */\r
22         public UndoCompress(Track inTrack)\r
23         {\r
24                 _contents = inTrack.cloneContents();\r
25                 // Copy boolean segment start flags\r
26                 _segmentStarts = new boolean[inTrack.getNumPoints()];\r
27                 for (int i=0; i<inTrack.getNumPoints(); i++) {\r
28                         _segmentStarts[i] = inTrack.getPoint(i).getSegmentStart();\r
29                 }\r
30         }\r
31 \r
32 \r
33         /**\r
34          * Set the number of points deleted\r
35          * (only known after attempted compression)\r
36          * @param inNum number of points deleted\r
37          */\r
38         public void setNumPointsDeleted(int inNum)\r
39         {\r
40                 _numPointsDeleted = inNum;\r
41         }\r
42 \r
43 \r
44         /**\r
45          * @return description of operation including parameters\r
46          */\r
47         public String getDescription()\r
48         {\r
49                 String desc = I18nManager.getText("undo.compress");\r
50                 if (_numPointsDeleted > 0)\r
51                         desc = desc + " (" + _numPointsDeleted + ")";\r
52                 return desc;\r
53         }\r
54 \r
55 \r
56         /**\r
57          * Perform the undo operation on the given Track\r
58          * @param inTrackInfo TrackInfo object on which to perform the operation\r
59          */\r
60         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
61         {\r
62                 // restore track to previous values\r
63                 inTrackInfo.getTrack().replaceContents(_contents);\r
64                 // Copy boolean segment start flags\r
65                 Track track = inTrackInfo.getTrack();\r
66                 if (_segmentStarts.length != track.getNumPoints())\r
67                         throw new UndoException("Cannot undo compress - track length no longer matches");\r
68                 for (int i=0; i<_segmentStarts.length; i++) {\r
69                         track.getPoint(i).setSegmentStart(_segmentStarts[i]);\r
70                 }\r
71                 // clear selection\r
72                 inTrackInfo.getSelection().clearAll();\r
73         }\r
74 }