]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/SelectSegmentFunction.java
Version 17, September 2014
[GpsPrune.git] / tim / prune / function / SelectSegmentFunction.java
1 package tim.prune.function;
2
3 import tim.prune.App;
4 import tim.prune.GenericFunction;
5 import tim.prune.data.Checker;
6 import tim.prune.data.DataPoint;
7
8 /**
9  * Function to allow the selection of which tracks to load from the file / stream
10  */
11 public class SelectSegmentFunction extends GenericFunction
12 {
13
14         /**
15          * Constructor
16          * @param inApp app object to use for load
17          */
18         public SelectSegmentFunction(App inApp)
19         {
20                 super(inApp);
21         }
22
23         /**
24          * Start the function
25          */
26         public void begin()
27         {
28                 // If no point selected, or a waypoint is selected, then do nothing
29                 DataPoint currPoint = _app.getTrackInfo().getCurrentPoint();
30                 if (currPoint != null && !currPoint.isWaypoint())
31                 {
32                         // Find indexes of segment start and end
33                         final int currIndex = _app.getTrackInfo().getSelection().getCurrentPointIndex();
34                         final int startIndex = Checker.getPreviousSegmentStart(_app.getTrackInfo().getTrack(), currIndex+1);
35                         final int endIndex   = Checker.getNextSegmentEnd(_app.getTrackInfo().getTrack(), currIndex);
36                         // Select this range if there is one
37                         if (endIndex > startIndex) {
38                                 _app.getTrackInfo().getSelection().selectRange(startIndex, endIndex);
39                         }
40                 }
41         }
42
43         /** @return name key */
44         public String getNameKey() {
45                 return "function.selectsegment";
46         }
47 }