X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2FSelectSegmentFunction.java;fp=src%2Ftim%2Fprune%2Ffunction%2FSelectSegmentFunction.java;h=661eee063cba4868925195bcd68a868b6c520f1d;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/SelectSegmentFunction.java b/src/tim/prune/function/SelectSegmentFunction.java new file mode 100644 index 0000000..661eee0 --- /dev/null +++ b/src/tim/prune/function/SelectSegmentFunction.java @@ -0,0 +1,47 @@ +package tim.prune.function; + +import tim.prune.App; +import tim.prune.GenericFunction; +import tim.prune.data.Checker; +import tim.prune.data.DataPoint; + +/** + * Function to allow the selection of which tracks to load from the file / stream + */ +public class SelectSegmentFunction extends GenericFunction +{ + + /** + * Constructor + * @param inApp app object to use for load + */ + public SelectSegmentFunction(App inApp) + { + super(inApp); + } + + /** + * Start the function + */ + public void begin() + { + // If no point selected, or a waypoint is selected, then do nothing + DataPoint currPoint = _app.getTrackInfo().getCurrentPoint(); + if (currPoint != null && !currPoint.isWaypoint()) + { + // Find indexes of segment start and end + final int currIndex = _app.getTrackInfo().getSelection().getCurrentPointIndex(); + final int startIndex = Checker.getPreviousSegmentStart(_app.getTrackInfo().getTrack(), currIndex+1); + final int endIndex = Checker.getNextSegmentEnd(_app.getTrackInfo().getTrack(), currIndex); + // Select this range if there is one + if (endIndex > startIndex) { + _app.getTrackInfo().getSelection().selectRange(startIndex, endIndex); + } + } + } + + /** @return name key */ + public String getNameKey() { + return "function.selectsegment"; + } +}