1 package tim.prune.undo;
\r
3 import tim.prune.I18nManager;
\r
4 import tim.prune.data.DataPoint;
\r
5 import tim.prune.data.TrackInfo;
\r
8 * Operation to undo a load operation
\r
10 public class UndoLoad implements UndoOperation
\r
12 private int _cropIndex = -1;
\r
13 private int _numLoaded = -1;
\r
14 private DataPoint[] _contents = null;
\r
15 private String _previousFilename = null;
\r
19 * Constructor for appending
\r
20 * @param inIndex index number of crop point
\r
21 * @param inNumLoaded number of points loaded
\r
23 public UndoLoad(int inIndex, int inNumLoaded)
\r
25 _cropIndex = inIndex;
\r
26 _numLoaded = inNumLoaded;
\r
28 _previousFilename = null;
\r
33 * Constructor for replacing
\r
34 * @param inOldTrack track being replaced
\r
35 * @param inNumLoaded number of points loaded
\r
37 public UndoLoad(TrackInfo inOldTrackInfo, int inNumLoaded)
\r
40 _numLoaded = inNumLoaded;
\r
41 _contents = inOldTrackInfo.getTrack().cloneContents();
\r
42 if (inOldTrackInfo.getFileInfo().getNumFiles() == 1)
\r
43 _previousFilename = inOldTrackInfo.getFileInfo().getFilename();
\r
48 * @return description of operation including number of points loaded
\r
50 public String getDescription()
\r
52 String desc = I18nManager.getText("undo.load");
\r
54 desc = desc + " (" + _numLoaded + ")";
\r
60 * Perform the undo operation on the given Track
\r
61 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
63 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
65 // remove file from fileinfo
\r
66 inTrackInfo.getFileInfo().removeFile();
\r
67 if (_previousFilename != null)
\r
69 inTrackInfo.getFileInfo().setFile(_previousFilename);
\r
72 if (_contents == null)
\r
74 // crop track to previous size
\r
75 inTrackInfo.getTrack().cropTo(_cropIndex);
\r
79 // replace track contents with old
\r
80 if (!inTrackInfo.getTrack().replaceContents(_contents))
\r
82 throw new UndoException(getDescription());
\r
86 inTrackInfo.getSelection().clearAll();
\r