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