]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/undo/UndoDeleteOperation.java
d99a9f68056637ae838788c709d40e9d061c68cc
[GpsPrune.git] / tim / prune / undo / UndoDeleteOperation.java
1 package tim.prune.undo;
2
3 import tim.prune.data.TrackInfo;
4
5 /**
6  * Abstract class to hold the selection handling required by all
7  * Undo operations which have undeleted something
8  */
9 public abstract class UndoDeleteOperation implements UndoOperation
10 {
11         /**
12          * Modify the current point/range selection after the delete operation is undone
13          * @param inTrackInfo track info object
14          * @param inStartIndex start index of reinserted range
15          * @param inEndIndex end index of reinserted range
16          */
17         protected static void modifySelection(TrackInfo inTrackInfo, int inStartIndex, int inEndIndex)
18         {
19                 final int numPointsInserted = inEndIndex - inStartIndex + 1;
20                 // See if there is a currently selected point, if so does it need to be modified
21                 final int currentPoint = inTrackInfo.getSelection().getCurrentPointIndex();
22                 if (currentPoint >= inStartIndex)
23                 {
24                         inTrackInfo.selectPoint(currentPoint + numPointsInserted);
25                 }
26                 // Same for currently selected range
27                 int rangeStart = inTrackInfo.getSelection().getStart();
28                 int rangeEnd   = inTrackInfo.getSelection().getEnd();
29                 if (rangeEnd >= inStartIndex && rangeEnd > rangeStart)
30                 {
31                         rangeEnd += numPointsInserted;
32                         if (rangeStart >= inStartIndex) {
33                                 rangeStart += numPointsInserted;
34                         }
35                         inTrackInfo.getSelection().selectRange(rangeStart, rangeEnd);
36                 }
37         }
38 }