File: SetAltitudeTolerance.java

package info (click to toggle)
gpsprune 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,824 kB
  • sloc: java: 52,154; sh: 25; makefile: 21; python: 15
file content (67 lines) | stat: -rw-r--r-- 1,841 bytes parent folder | download | duplicates (4)
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
package tim.prune.function.settings;

import tim.prune.App;
import tim.prune.DataSubscriber;
import tim.prune.UpdateMessageBroker;
import tim.prune.config.Config;
import tim.prune.data.Unit;
import tim.prune.function.SingleNumericParameterFunction;

/**
 * Function to set the tolerance for the altitude range calculations
 */
public class SetAltitudeTolerance extends SingleNumericParameterFunction
{

	/**
	 * Constructor
	 * @param inApp App object
	 */
	public SetAltitudeTolerance(App inApp) {
		super(inApp, 0, 100);
	}

	/** @return name key */
	public String getNameKey() {
		return "function.setaltitudetolerance";
	}

	/**
	 * @return description key
	 */
	public String getDescriptionKey()
	{
		// Two different keys for feet and metres
		final boolean isMetres = getConfig().getUnitSet().getAltitudeUnit().isStandard();
		return "dialog.setaltitudetolerance.text." + (isMetres ? "metres" : "feet");
	}

	/**
	 * @return the current value to display
	 */
	public int getCurrentParamValue()
	{
		int configVal = getConfig().getConfigInt(Config.KEY_ALTITUDE_TOLERANCE);
		// Convert this to feet if necessary
		Unit altUnit = getConfig().getUnitSet().getAltitudeUnit();
		if (altUnit.isStandard()) {
			return configVal / 100;
		}
		return (int) (configVal * altUnit.getMultFactorFromStd() / 100.0);
	}

	/**
	 * Complete the function using the given tolerance parameter
	 */
	public void completeFunction(int inTolerance)
	{
		// Convert back from feet into metres again
		Unit altUnit = getConfig().getUnitSet().getAltitudeUnit();
		int configVal = inTolerance * 100;
		if (!altUnit.isStandard()) {
			configVal = (int) (inTolerance * 100.0 / altUnit.getMultFactorFromStd());
		}
		getConfig().setConfigInt(Config.KEY_ALTITUDE_TOLERANCE, configVal);
		UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED);
	}
}