]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/CropToSelection.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / function / CropToSelection.java
1 package tim.prune.function;
2
3 import tim.prune.App;
4 import tim.prune.data.Track;
5
6 /**
7  * Class to provide the function to crop the track
8  * to the current selection
9  */
10 public class CropToSelection extends DeleteBitOfTrackFunction
11 {
12         /**
13          * Constructor
14          * @param inApp application object for callback
15          */
16         public CropToSelection(App inApp)
17         {
18                 super(inApp);
19         }
20
21         /** Get the name key */
22         public String getNameKey() {
23                 return "function.croptrack";
24         }
25
26         /**
27          * @return name key for undo operation
28          */
29         protected String getUndoNameKey() {
30                 return "undo.croptrack";
31         }
32
33         /**
34          * Begin the function
35          */
36         public void begin()
37         {
38                 // check track
39                 Track track = _app.getTrackInfo().getTrack();
40                 if (track == null || track.getNumPoints() <= 0) return;
41                 // check selection
42                 final int selStart = _app.getTrackInfo().getSelection().getStart();
43                 final int selEnd = _app.getTrackInfo().getSelection().getEnd();
44                 if (selStart < 0 || selEnd < 0 || selEnd <= selStart) return;
45                 // check for all selected
46                 if (selStart == 0 && selEnd == (track.getNumPoints() - 1)) return;
47
48                 // Pass indexes to parent class
49                 deleteTwoSections(0, selStart-1, selEnd+1, track.getNumPoints()-1);
50         }
51 }