]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoLoad.java
Version 4, January 2008
[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.PhotoList;\r
6 import tim.prune.data.TrackInfo;\r
7 \r
8 /**\r
9  * Operation to undo a load operation\r
10  */\r
11 public class UndoLoad implements UndoOperation\r
12 {\r
13         private int _cropIndex = -1;\r
14         private int _numLoaded = -1;\r
15         private DataPoint[] _contents = null;\r
16         private String _previousFilename = null;\r
17         private PhotoList _photoList = null;\r
18 \r
19 \r
20         /**\r
21          * Constructor for appending\r
22          * @param inIndex index number of crop point\r
23          * @param inNumLoaded number of points loaded\r
24          */\r
25         public UndoLoad(int inIndex, int inNumLoaded)\r
26         {\r
27                 _cropIndex = inIndex;\r
28                 _numLoaded = inNumLoaded;\r
29                 _contents = null;\r
30                 _previousFilename = 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                 if (inOldTrackInfo.getFileInfo().getNumFiles() == 1)\r
46                         _previousFilename = inOldTrackInfo.getFileInfo().getFilename();\r
47                 _photoList = inPhotoList;\r
48         }\r
49 \r
50 \r
51         /**\r
52          * @return description of operation including number of points loaded\r
53          */\r
54         public String getDescription()\r
55         {\r
56                 String desc = I18nManager.getText("undo.load");\r
57                 if (_numLoaded > 0)\r
58                         desc = desc + " (" + _numLoaded + ")";\r
59                 return desc;\r
60         }\r
61 \r
62 \r
63         /**\r
64          * Perform the undo operation on the given Track\r
65          * @param inTrackInfo TrackInfo object on which to perform the operation\r
66          */\r
67         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
68         {\r
69                 // remove file from fileinfo\r
70                 inTrackInfo.getFileInfo().removeFile();\r
71                 if (_previousFilename != null)\r
72                 {\r
73                         inTrackInfo.getFileInfo().setFile(_previousFilename);\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 }