]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/RearrangeWaypointsFunction.java
Version 15.2, November 2013
[GpsPrune.git] / tim / prune / function / RearrangeWaypointsFunction.java
1 package tim.prune.function;
2
3 import javax.swing.JOptionPane;
4
5 import tim.prune.App;
6 import tim.prune.GenericFunction;
7 import tim.prune.I18nManager;
8 import tim.prune.data.Track;
9 import tim.prune.undo.UndoRearrangeWaypoints;
10
11 /**
12  * Class to provide the function for rearranging waypoints
13  */
14 public class RearrangeWaypointsFunction extends GenericFunction
15 {
16
17         /** Enumeration for rearrange commands */
18         public enum Rearrange
19         {
20                 /** Rearrange all waypoints to start */
21                 TO_START,
22                 /** Rearrange all waypoints to end */
23                 TO_END,
24                 /** Rearrange each waypoint to nearest track point */
25                 TO_NEAREST
26         }
27
28         /**
29          * Constructor
30          * @param inApp app object
31          */
32         public RearrangeWaypointsFunction(App inApp)
33         {
34                 super(inApp);
35         }
36
37         /** Begin the rearrange (not needed) */
38         public void begin() {
39         }
40
41         /** Get the name key (not needed) */
42         public String getNameKey() {
43                 return null;
44         }
45
46         /**
47          * Rearrange the waypoints into track order
48          * @param inFunction nearest point, all to end or all to start
49          */
50         public void rearrangeWaypoints(Rearrange inFunction)
51         {
52                 Track track = _app.getTrackInfo().getTrack();
53                 UndoRearrangeWaypoints undo = new UndoRearrangeWaypoints(track);
54                 boolean success = false;
55                 if (inFunction == Rearrange.TO_START || inFunction == Rearrange.TO_END)
56                 {
57                         // Collect the waypoints to the start or end of the track
58                         success = track.collectWaypoints(inFunction == Rearrange.TO_START);
59                 }
60                 else
61                 {
62                         // Interleave the waypoints into track order
63                         success = track.interleaveWaypoints();
64                 }
65                 if (success)
66                 {
67                         _app.getTrackInfo().getSelection().clearAll(); // clear selected point and range
68                         _app.completeFunction(undo, I18nManager.getText("confirm.rearrangewaypoints"));
69                 }
70                 else
71                 {
72                         JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.rearrange.noop"),
73                                 I18nManager.getText("error.function.noop.title"), JOptionPane.WARNING_MESSAGE);
74                 }
75         }
76
77 }