]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/settings/SetAltitudeTolerance.java
Version 18.6, December 2016
[GpsPrune.git] / tim / prune / function / settings / SetAltitudeTolerance.java
1 package tim.prune.function.settings;
2
3 import tim.prune.App;
4 import tim.prune.DataSubscriber;
5 import tim.prune.UpdateMessageBroker;
6 import tim.prune.config.Config;
7 import tim.prune.data.Unit;
8 import tim.prune.function.SingleNumericParameterFunction;
9
10 /**
11  * Function to set the tolerance for the altitude range calculations
12  */
13 public class SetAltitudeTolerance extends SingleNumericParameterFunction
14 {
15
16         /**
17          * Constructor
18          * @param inApp App object
19          */
20         public SetAltitudeTolerance(App inApp) {
21                 super(inApp, 0, 100);
22         }
23
24         /** @return name key */
25         public String getNameKey() {
26                 return "function.setaltitudetolerance";
27         }
28
29         /**
30          * @return description key
31          */
32         public String getDescriptionKey()
33         {
34                 // Two different keys for feet and metres
35                 final boolean isMetres = Config.getUnitSet().getAltitudeUnit().isStandard();
36                 return "dialog.setaltitudetolerance.text." + (isMetres ? "metres" : "feet");
37         }
38
39         /**
40          * @return the current value to display
41          */
42         public int getCurrentParamValue()
43         {
44                 int configVal = Config.getConfigInt(Config.KEY_ALTITUDE_TOLERANCE);
45                 // Convert this to feet if necessary
46                 Unit altUnit = Config.getUnitSet().getAltitudeUnit();
47                 if (altUnit.isStandard()) {
48                         return configVal / 100;
49                 }
50                 return (int) (configVal * altUnit.getMultFactorFromStd() / 100.0);
51         }
52
53         /**
54          * Run function
55          */
56         public void begin()
57         {
58                 // Not required, because this function is started from a ChooseSingleParameter function
59                 // and goes directly to the completeFunction method.
60         }
61
62         /**
63          * Complete the function using the given tolerance parameter
64          */
65         public void completeFunction(int inTolerance)
66         {
67                 // Convert back from feet into metres again
68                 Unit altUnit = Config.getUnitSet().getAltitudeUnit();
69                 int configVal = inTolerance * 100;
70                 if (!altUnit.isStandard()) {
71                         configVal = (int) (inTolerance * 100.0 / altUnit.getMultFactorFromStd());
72                 }
73                 Config.setConfigInt(Config.KEY_ALTITUDE_TOLERANCE, configVal);
74                 UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED);
75         }
76 }