]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/profile/VerticalSpeedData.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / gui / profile / VerticalSpeedData.java
1 package tim.prune.gui.profile;
2
3 import tim.prune.I18nManager;
4 import tim.prune.data.SpeedCalculator;
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 vertical speed data for the profile chart
11  */
12 public class VerticalSpeedData extends ProfileData
13 {
14         /**
15          * Constructor
16          * @param inTrack track object
17          */
18         public VerticalSpeedData(Track inTrack) {
19                 super(inTrack);
20         }
21
22         /**
23          * Get the data and populate the instance arrays
24          */
25         public void init(UnitSet inUnitSet)
26         {
27                 setUnitSet(inUnitSet);
28                 initArrays();
29                 _hasData = false;
30                 _minValue = _maxValue = 0.0;
31                 SpeedValue speed = new SpeedValue();
32                 if (_track != null)
33                 {
34                         for (int i=0; i<_track.getNumPoints(); i++)
35                         {
36                                 SpeedCalculator.calculateVerticalSpeed(_track, i, speed);
37                                 // Check whether we got a value from either method
38                                 if (speed.isValid())
39                                 {
40                                         // Store the value and maintain max and min values
41                                         double speedValue = speed.getValue();
42                                         _pointValues[i] = speedValue;
43                                         if (speedValue < _minValue || _minValue == 0.0) {_minValue = speedValue;}
44                                         if (speedValue > _maxValue) {_maxValue = speedValue;}
45                                         _hasData = true;
46                                 }
47                                 _pointHasData[i] = speed.isValid();
48                         }
49                 }
50         }
51
52         /**
53          * @return text description including units
54          */
55         public String getLabel()
56         {
57                 return I18nManager.getText("fieldname.verticalspeed") + " ("
58                         + I18nManager.getText(_unitSet.getVerticalSpeedUnit().getShortnameKey()) + ")";
59         }
60
61         /**
62          * @return key for message when no speeds present
63          */
64         public String getNoDataKey()
65         {
66                 if (!_track.hasAltitudeData()) {
67                         return "display.noaltitudes";
68                 }
69                 return "display.notimestamps";
70         }
71 }