]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoLoad.java
Version 9, February 2010
[GpsPrune.git] / tim / prune / undo / UndoLoad.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.FileInfo;\r
6 import tim.prune.data.PhotoList;\r
7 import tim.prune.data.TrackInfo;\r
8 \r
9 /**\r
10  * Operation to undo a load operation\r
11  */\r
12 public class UndoLoad implements UndoOperation\r
13 {\r
14         private int _cropIndex = -1;\r
15         private int _numLoaded = -1;\r
16         private DataPoint[] _contents = null;\r
17         private PhotoList _photoList = null;\r
18         private FileInfo _oldFileInfo = null;\r
19 \r
20 \r
21         /**\r
22          * Constructor for appending\r
23          * @param inIndex index number of crop point\r
24          * @param inNumLoaded number of points loaded\r
25          */\r
26         public UndoLoad(int inIndex, int inNumLoaded)\r
27         {\r
28                 _cropIndex = inIndex;\r
29                 _numLoaded = inNumLoaded;\r
30                 _contents = null;\r
31         }\r
32 \r
33 \r
34         /**\r
35          * Constructor for replacing\r
36          * @param inOldTrackInfo track info being replaced\r
37          * @param inNumLoaded number of points loaded\r
38          * @param inPhotoList photo list, if any\r
39          */\r
40         public UndoLoad(TrackInfo inOldTrackInfo, int inNumLoaded, PhotoList inPhotoList)\r
41         {\r
42                 _cropIndex = -1;\r
43                 _numLoaded = inNumLoaded;\r
44                 _contents = inOldTrackInfo.getTrack().cloneContents();\r
45                 _oldFileInfo = inOldTrackInfo.getFileInfo().clone();\r
46                 _photoList = inPhotoList;\r
47         }\r
48 \r
49 \r
50         /**\r
51          * @return description of operation including number of points loaded\r
52          */\r
53         public String getDescription()\r
54         {\r
55                 String desc = I18nManager.getText("undo.load");\r
56                 if (_numLoaded > 0)\r
57                         desc = desc + " (" + _numLoaded + ")";\r
58                 return desc;\r
59         }\r
60 \r
61 \r
62         /**\r
63          * Perform the undo operation on the given Track\r
64          * @param inTrackInfo TrackInfo object on which to perform the operation\r
65          */\r
66         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
67         {\r
68                 // remove source from fileinfo\r
69                 if (_oldFileInfo == null) {\r
70                         inTrackInfo.getFileInfo().removeSource();\r
71                 }\r
72                 else {\r
73                         inTrackInfo.setFileInfo(_oldFileInfo);\r
74                 }\r
75                 // Crop / replace\r
76                 if (_contents == null)\r
77                 {\r
78                         // crop track to previous size\r
79                         inTrackInfo.getTrack().cropTo(_cropIndex);\r
80                 }\r
81                 else\r
82                 {\r
83                         // replace photos how they were\r
84                         if (_photoList != null)\r
85                         {\r
86                                 inTrackInfo.getPhotoList().restore(_photoList);\r
87                         }\r
88                         // replace track contents with old\r
89                         if (!inTrackInfo.getTrack().replaceContents(_contents))\r
90                         {\r
91                                 throw new UndoException(getDescription());\r
92                         }\r
93                 }\r
94                 // clear selection\r
95                 inTrackInfo.getSelection().clearAll();\r
96         }\r
97 }