]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/profile/GradientData.java
Version 17, September 2014
[GpsPrune.git] / tim / prune / gui / profile / GradientData.java
1 package tim.prune.gui.profile;
2
3 import tim.prune.I18nManager;
4 import tim.prune.data.GradientCalculator;
5 import tim.prune.data.SpeedValue;
6 import tim.prune.data.Track;
7 import tim.prune.data.UnitSet;
8
9 /**
10  * Class to provide a source of gradient data for the profile chart
11  * or for the point colourer
12  */
13 public class GradientData extends ProfileData
14 {
15         /**
16          * Constructor
17          * @param inTrack track object
18          */
19         public GradientData(Track inTrack) {
20                 super(inTrack);
21         }
22
23         /**
24          * Get the data and populate the instance arrays
25          */
26         public void init(UnitSet inUnitSet)
27         {
28                 setUnitSet(inUnitSet);
29                 initArrays();
30                 _hasData = false;
31                 _minValue = _maxValue = 0.0;
32                 SpeedValue speed = new SpeedValue();
33                 if (_track != null)
34                 {
35                         for (int i=0; i<_track.getNumPoints(); i++)
36                         {
37                                 // Get the gradient either from the speed values or from the distances and altitudes
38                                 GradientCalculator.calculateGradient(_track, i, speed);
39                                 if (speed.isValid())
40                                 {
41                                         double speedValue = speed.getValue();
42                                         _pointValues[i] = speedValue;
43                                         if (speedValue < _minValue || !_hasData) {_minValue = speedValue;}
44                                         if (speedValue > _maxValue || !_hasData) {_maxValue = speedValue;}
45                                         _hasData = true;
46                                 }
47                                 _pointHasData[i] = speed.isValid();
48                         }
49                 }
50         }
51
52         /**
53          * @return text description
54          */
55         public String getLabel()
56         {
57                 return I18nManager.getText("fieldname.gradient");
58         }
59
60         /**
61          * @return key for message when no altitudes present
62          */
63         public String getNoDataKey() {
64                 return "display.noaltitudes";
65         }
66 }