File: RearrangeWaypointsFunction.java

package info (click to toggle)
gpsprune 13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,008 kB
  • sloc: java: 28,802; sh: 25; makefile: 17; python: 15
file content (76 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download | duplicates (2)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package tim.prune.function;

import javax.swing.JOptionPane;

import tim.prune.App;
import tim.prune.GenericFunction;
import tim.prune.I18nManager;
import tim.prune.data.Track;
import tim.prune.undo.UndoRearrangeWaypoints;

/**
 * Class to provide the function for rearranging waypoints
 */
public class RearrangeWaypointsFunction extends GenericFunction
{

	/** Enumeration for rearrange commands */
	public enum Rearrange
	{
		/** Rearrange all waypoints to start */
		TO_START,
		/** Rearrange all waypoints to end */
		TO_END,
		/** Rearrange each waypoint to nearest track point */
		TO_NEAREST
	}

	/**
	 * Constructor
	 * @param inApp app object
	 */
	public RearrangeWaypointsFunction(App inApp)
	{
		super(inApp);
	}

	/** Begin the rearrange (not needed) */
	public void begin() {
	}

	/** Get the name key (not needed) */
	public String getNameKey() {
		return null;
	}

	/**
	 * Rearrange the waypoints into track order
	 * @param inFunction nearest point, all to end or all to start
	 */
	public void rearrangeWaypoints(Rearrange inFunction)
	{
		Track track = _app.getTrackInfo().getTrack();
		UndoRearrangeWaypoints undo = new UndoRearrangeWaypoints(track);
		boolean success = false;
		if (inFunction == Rearrange.TO_START || inFunction == Rearrange.TO_END)
		{
			// Collect the waypoints to the start or end of the track
			success = track.collectWaypoints(inFunction == Rearrange.TO_START);
		}
		else
		{
			// Interleave the waypoints into track order
			success = track.interleaveWaypoints();
		}
		if (success)
		{
			_app.completeFunction(undo, I18nManager.getText("confirm.rearrangewaypoints"));
		}
		else
		{
			JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.rearrange.noop"),
				I18nManager.getText("error.function.noop.title"), JOptionPane.WARNING_MESSAGE);
		}
	}

}