1 package tim.prune.undo;
3 import tim.prune.data.TrackInfo;
6 * Abstract class to hold the selection handling required by all
7 * Undo operations which have undeleted something
9 public abstract class UndoDeleteOperation implements UndoOperation
11 /** Flag to remember whether the deleted point was at the beginning or end of the selected range */
12 private boolean _isAtBoundaryOfSelectedRange = false;
15 * @param inAtBoundary true if deleted point was at the beginning or end of the selected range
17 public void setAtBoundaryOfSelectedRange(boolean inAtBoundary)
19 _isAtBoundaryOfSelectedRange = inAtBoundary;
23 * Modify the current point/range selection after the delete operation is undone
24 * @param inTrackInfo track info object
25 * @param inStartIndex start index of reinserted range
26 * @param inEndIndex end index of reinserted range
28 protected void modifySelection(TrackInfo inTrackInfo, int inStartIndex, int inEndIndex)
30 final int numPointsInserted = inEndIndex - inStartIndex + 1;
31 // See if there is a currently selected point, if so does it need to be modified
32 final int currentPoint = inTrackInfo.getSelection().getCurrentPointIndex();
33 if (currentPoint >= inStartIndex)
35 inTrackInfo.selectPoint(currentPoint + numPointsInserted);
37 // Same for currently selected range
38 int rangeStart = inTrackInfo.getSelection().getStart();
39 int rangeEnd = inTrackInfo.getSelection().getEnd();
40 // Was the deleted point at the start or end of the selected range?
41 final boolean wasAtStart = numPointsInserted == 1 && inStartIndex == rangeStart && _isAtBoundaryOfSelectedRange;
42 final boolean wasAtEnd = numPointsInserted == 1 && inStartIndex == (rangeEnd+1) && _isAtBoundaryOfSelectedRange;
43 if (rangeEnd >= inStartIndex && rangeEnd > rangeStart || wasAtStart || wasAtEnd)
45 rangeEnd += numPointsInserted;
46 if (rangeStart >= inStartIndex) {
47 rangeStart += numPointsInserted;
49 // Extend selection if the deleted point was at the start or end
53 inTrackInfo.getSelection().selectRange(rangeStart, rangeEnd);