]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/undo/UndoLoad.java
Version 19.2, December 2018
[GpsPrune.git] / src / 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         // Numbers of each media before operation\r
20         private int _numPhotos = -1, _numAudios = -1;\r
21 \r
22 \r
23         /**\r
24          * Constructor for appending\r
25          * @param inIndex index number of crop point\r
26          * @param inNumLoaded number of points loaded\r
27          */\r
28         public UndoLoad(int inIndex, int inNumLoaded)\r
29         {\r
30                 _cropIndex = inIndex;\r
31                 _numLoaded = inNumLoaded;\r
32                 _contents = null;\r
33         }\r
34 \r
35 \r
36         /**\r
37          * Constructor for replacing\r
38          * @param inOldTrackInfo track info being replaced\r
39          * @param inNumLoaded number of points loaded\r
40          * @param inPhotoList photo list, if any\r
41          */\r
42         public UndoLoad(TrackInfo inOldTrackInfo, int inNumLoaded, PhotoList inPhotoList)\r
43         {\r
44                 _cropIndex = -1;\r
45                 _numLoaded = inNumLoaded;\r
46                 _contents = inOldTrackInfo.getTrack().cloneContents();\r
47                 _oldFileInfo = inOldTrackInfo.getFileInfo().clone();\r
48                 _photoList = inPhotoList;\r
49         }\r
50 \r
51 \r
52         /**\r
53          * @return description of operation including number of points loaded\r
54          */\r
55         public String getDescription()\r
56         {\r
57                 String desc = I18nManager.getText("undo.load");\r
58                 if (_numLoaded > 0)\r
59                         desc = desc + " (" + _numLoaded + ")";\r
60                 return desc;\r
61         }\r
62 \r
63         /**\r
64          * Set the number of photos and audios before the load operation\r
65          * @param inNumPhotos number of photos\r
66          * @param inNumAudios number of audios\r
67          */\r
68         public void setNumPhotosAudios(int inNumPhotos, int inNumAudios)\r
69         {\r
70                 _numPhotos = inNumPhotos;\r
71                 _numAudios = inNumAudios;\r
72         }\r
73 \r
74         /**\r
75          * Perform the undo operation on the given Track\r
76          * @param inTrackInfo TrackInfo object on which to perform the operation\r
77          */\r
78         public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
79         {\r
80                 // remove source from fileinfo\r
81                 if (_oldFileInfo == null) {\r
82                         inTrackInfo.getFileInfo().removeSource();\r
83                 }\r
84                 else {\r
85                         inTrackInfo.setFileInfo(_oldFileInfo);\r
86                 }\r
87                 // Crop / replace\r
88                 if (_contents == null)\r
89                 {\r
90                         // crop track to previous size\r
91                         inTrackInfo.getTrack().cropTo(_cropIndex);\r
92                 }\r
93                 else\r
94                 {\r
95                         // replace photos how they were\r
96                         if (_photoList != null) {\r
97                                 inTrackInfo.getPhotoList().restore(_photoList);\r
98                         }\r
99                         // Crop media lists to previous size (if specified)\r
100                         if (_numPhotos > -1) {inTrackInfo.getPhotoList().cropTo(_numPhotos);}\r
101                         if (_numAudios > -1) {inTrackInfo.getAudioList().cropTo(_numAudios);}\r
102                         // replace track contents with old\r
103                         if (!inTrackInfo.getTrack().replaceContents(_contents))\r
104                         {\r
105                                 throw new UndoException(getDescription());\r
106                         }\r
107                 }\r
108                 // clear selection\r
109                 inTrackInfo.getSelection().clearAll();\r
110         }\r
111 }\r