1 package tim.prune.undo;
\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
9 * Operation to undo a load operation
\r
11 public class UndoLoad implements UndoOperation
\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
21 * Constructor for appending
\r
22 * @param inIndex index number of crop point
\r
23 * @param inNumLoaded number of points loaded
\r
25 public UndoLoad(int inIndex, int inNumLoaded)
\r
27 _cropIndex = inIndex;
\r
28 _numLoaded = inNumLoaded;
\r
30 _previousFilename = null;
\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
40 public UndoLoad(TrackInfo inOldTrackInfo, int inNumLoaded, PhotoList inPhotoList)
\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
52 * @return description of operation including number of points loaded
\r
54 public String getDescription()
\r
56 String desc = I18nManager.getText("undo.load");
\r
58 desc = desc + " (" + _numLoaded + ")";
\r
64 * Perform the undo operation on the given Track
\r
65 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
67 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
69 // remove file from fileinfo
\r
70 inTrackInfo.getFileInfo().removeFile();
\r
71 if (_previousFilename != null)
\r
73 inTrackInfo.getFileInfo().setFile(_previousFilename);
\r
76 if (_contents == null)
\r
78 // crop track to previous size
\r
79 inTrackInfo.getTrack().cropTo(_cropIndex);
\r
83 // replace photos how they were
\r
84 if (_photoList != null)
\r
86 inTrackInfo.getPhotoList().restore(_photoList);
\r
88 // replace track contents with old
\r
89 if (!inTrackInfo.getTrack().replaceContents(_contents))
\r
91 throw new UndoException(getDescription());
\r
95 inTrackInfo.getSelection().clearAll();
\r