1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 select the whole segment to which the current track point belongs
*/
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";
}
}
|