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 an interpolation
\r
10 public class UndoInterpolate implements UndoOperation
\r
12 private int _startIndex = 0;
\r
13 private int _totalInserted = 0;
\r
14 private DataPoint[] _points = null;
\r
19 * @param inTrackInfo track info object
\r
20 * @param inTotalInserted total number of points inserted
\r
22 public UndoInterpolate(TrackInfo inTrackInfo, int inTotalInserted)
\r
24 _startIndex = inTrackInfo.getSelection().getStart();
\r
25 _points = inTrackInfo.cloneSelectedRange();
\r
26 _totalInserted = inTotalInserted;
\r
31 * @return description of operation including parameters
\r
33 public String getDescription()
\r
35 return I18nManager.getText("undo.insert") + " (" + _totalInserted + ")";
\r
40 * Perform the undo operation on the given TrackInfo
\r
41 * @param inTrackInfo TrackInfo object on which to perform the operation
\r
43 public void performUndo(TrackInfo inTrackInfo) throws UndoException
\r
45 // Work out how many points were in the track before the interpolation
\r
46 final int newSize = inTrackInfo.getTrack().getNumPoints() - _totalInserted;
\r
47 DataPoint[] oldPoints = inTrackInfo.getTrack().cloneContents();
\r
48 DataPoint[] newPoints = new DataPoint[newSize];
\r
50 // Restore track to previous values
\r
51 System.arraycopy(oldPoints, 0, newPoints, 0, _startIndex);
\r
52 System.arraycopy(_points, 0, newPoints, _startIndex, _points.length);
\r
53 int endIndex = _startIndex + _points.length;
\r
54 System.arraycopy(oldPoints, endIndex + _totalInserted, newPoints, endIndex, newSize - endIndex);
\r
56 inTrackInfo.getTrack().replaceContents(newPoints);
\r
58 inTrackInfo.getSelection().clearAll();
\r