1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
package tim.prune.undo;
import tim.prune.I18nManager;
import tim.prune.data.DataPoint;
import tim.prune.data.TrackInfo;
/**
* Operation to undo an interpolation
*/
public class UndoInterpolate implements UndoOperation
{
private int _startIndex = 0;
private int _totalInserted = 0;
private DataPoint[] _points = null;
/**
* Constructor
* @param inTrackInfo track info object
* @param inTotalInserted total number of points inserted
*/
public UndoInterpolate(TrackInfo inTrackInfo, int inTotalInserted)
{
_startIndex = inTrackInfo.getSelection().getStart();
_points = inTrackInfo.cloneSelectedRange();
_totalInserted = inTotalInserted;
}
/**
* @return description of operation including parameters
*/
public String getDescription()
{
return I18nManager.getText("undo.insert") + " (" + _totalInserted + ")";
}
/**
* Perform the undo operation on the given TrackInfo
* @param inTrackInfo TrackInfo object on which to perform the operation
*/
public void performUndo(TrackInfo inTrackInfo) throws UndoException
{
// Work out how many points were in the track before the interpolation
final int newSize = inTrackInfo.getTrack().getNumPoints() - _totalInserted;
DataPoint[] oldPoints = inTrackInfo.getTrack().cloneContents();
DataPoint[] newPoints = new DataPoint[newSize];
// Restore track to previous values
System.arraycopy(oldPoints, 0, newPoints, 0, _startIndex);
System.arraycopy(_points, 0, newPoints, _startIndex, _points.length);
int endIndex = _startIndex + _points.length;
System.arraycopy(oldPoints, endIndex + _totalInserted, newPoints, endIndex, newSize - endIndex);
inTrackInfo.getTrack().replaceContents(newPoints);
// reset selection
inTrackInfo.getSelection().clearAll();
}
}
|