X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fundo%2FUndoDeleteOperation.java;fp=tim%2Fprune%2Fundo%2FUndoDeleteOperation.java;h=d99a9f68056637ae838788c709d40e9d061c68cc;hb=326f489e36aa7f235bc19409a57bf4955cd50f24;hp=0000000000000000000000000000000000000000;hpb=8c8868ae29b3252f02e094c02307384cf61ba667;p=GpsPrune.git diff --git a/tim/prune/undo/UndoDeleteOperation.java b/tim/prune/undo/UndoDeleteOperation.java new file mode 100644 index 0000000..d99a9f6 --- /dev/null +++ b/tim/prune/undo/UndoDeleteOperation.java @@ -0,0 +1,38 @@ +package tim.prune.undo; + +import tim.prune.data.TrackInfo; + +/** + * Abstract class to hold the selection handling required by all + * Undo operations which have undeleted something + */ +public abstract class UndoDeleteOperation implements UndoOperation +{ + /** + * Modify the current point/range selection after the delete operation is undone + * @param inTrackInfo track info object + * @param inStartIndex start index of reinserted range + * @param inEndIndex end index of reinserted range + */ + protected static void modifySelection(TrackInfo inTrackInfo, int inStartIndex, int inEndIndex) + { + final int numPointsInserted = inEndIndex - inStartIndex + 1; + // See if there is a currently selected point, if so does it need to be modified + final int currentPoint = inTrackInfo.getSelection().getCurrentPointIndex(); + if (currentPoint >= inStartIndex) + { + inTrackInfo.selectPoint(currentPoint + numPointsInserted); + } + // Same for currently selected range + int rangeStart = inTrackInfo.getSelection().getStart(); + int rangeEnd = inTrackInfo.getSelection().getEnd(); + if (rangeEnd >= inStartIndex && rangeEnd > rangeStart) + { + rangeEnd += numPointsInserted; + if (rangeStart >= inStartIndex) { + rangeStart += numPointsInserted; + } + inTrackInfo.getSelection().selectRange(rangeStart, rangeEnd); + } + } +}