X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fundo%2FUndoInterpolate.java;fp=src%2Ftim%2Fprune%2Fundo%2FUndoInterpolate.java;h=975a7314394d6800fa8cd0b1d8cb7631ef0b6c6b;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/undo/UndoInterpolate.java b/src/tim/prune/undo/UndoInterpolate.java new file mode 100644 index 0000000..975a731 --- /dev/null +++ b/src/tim/prune/undo/UndoInterpolate.java @@ -0,0 +1,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(); + } +}