1 package tim.prune.undo;
\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
10 * Operation to undo a load operation
\r
12 public class UndoLoad implements UndoOperation
\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
24 * Constructor for appending
\r
25 * @param inIndex index number of crop point
\r
26 * @param inNumLoaded number of points loaded
\r
28 public UndoLoad(int inIndex, int inNumLoaded)
\r
30 _cropIndex = inIndex;
\r
31 _numLoaded = inNumLoaded;
\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
42 public UndoLoad(TrackInfo inOldTrackInfo, int inNumLoaded, PhotoList inPhotoList)
\r
45 _numLoaded = inNumLoaded;
\r
46 _contents = inOldTrackInfo.getTrack().cloneContents();
\r
47 _oldFileInfo = inOldTrackInfo.getFileInfo().clone();
\r
48 _photoList = inPhotoList;
\r
53 * @return description of operation including number of points loaded
\r
55 public String getDescription()
\r
57 String desc = I18nManager.getText("undo.load");
\r
59 desc = desc + " (" + _numLoaded + ")";
\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
68 public void setNumPhotosAudios(int inNumPhotos, int inNumAudios)
\r
70 _numPhotos = inNumPhotos;
\r
71 _numAudios = inNumAudios;
\r
75 * Perform the undo operation on the given Track
\r
76 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
78 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
80 // remove source from fileinfo
\r
81 if (_oldFileInfo == null) {
\r
82 inTrackInfo.getFileInfo().removeSource();
\r
85 inTrackInfo.setFileInfo(_oldFileInfo);
\r
88 if (_contents == null)
\r
90 // crop track to previous size
\r
91 inTrackInfo.getTrack().cropTo(_cropIndex);
\r
95 // replace photos how they were
\r
96 if (_photoList != null) {
\r
97 inTrackInfo.getPhotoList().restore(_photoList);
\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
105 throw new UndoException(getDescription());
\r
109 inTrackInfo.getSelection().clearAll();
\r