X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2FCropToSelection.java;fp=src%2Ftim%2Fprune%2Ffunction%2FCropToSelection.java;h=e8575afb32fbb6112c513270151f92fb8cc508ac;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/CropToSelection.java b/src/tim/prune/function/CropToSelection.java new file mode 100644 index 0000000..e8575af --- /dev/null +++ b/src/tim/prune/function/CropToSelection.java @@ -0,0 +1,51 @@ +package tim.prune.function; + +import tim.prune.App; +import tim.prune.data.Track; + +/** + * Class to provide the function to crop the track + * to the current selection + */ +public class CropToSelection extends DeleteBitOfTrackFunction +{ + /** + * Constructor + * @param inApp application object for callback + */ + public CropToSelection(App inApp) + { + super(inApp); + } + + /** Get the name key */ + public String getNameKey() { + return "function.croptrack"; + } + + /** + * @return name key for undo operation + */ + protected String getUndoNameKey() { + return "undo.croptrack"; + } + + /** + * Begin the function + */ + public void begin() + { + // check track + Track track = _app.getTrackInfo().getTrack(); + if (track == null || track.getNumPoints() <= 0) return; + // check selection + final int selStart = _app.getTrackInfo().getSelection().getStart(); + final int selEnd = _app.getTrackInfo().getSelection().getEnd(); + if (selStart < 0 || selEnd < 0 || selEnd <= selStart) return; + // check for all selected + if (selStart == 0 && selEnd == (track.getNumPoints() - 1)) return; + + // Pass indexes to parent class + deleteTwoSections(0, selStart-1, selEnd+1, track.getNumPoints()-1); + } +}