]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/profile/SpeedData.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / gui / profile / SpeedData.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 speed data for the profile chart
11  */
12 public class SpeedData extends ProfileData
13 {
14         /**
15          * Constructor
16          * @param inTrack track object
17          */
18         public SpeedData(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                                 // Get the speed either from the speed value or from the distances and timestamps
37                                 SpeedCalculator.calculateSpeed(_track, i, speed);
38                                 if (speed.isValid())
39                                 {
40                                         double speedValue = speed.getValue();
41                                         _pointValues[i] = speedValue;
42                                         if (speedValue < _minValue || _minValue == 0.0) {_minValue = speedValue;}
43                                         if (speedValue > _maxValue) {_maxValue = speedValue;}
44                                         _hasData = true;
45                                 }
46                                 _pointHasData[i] = speed.isValid();
47                         }
48                 }
49         }
50
51         /**
52          * @return text description including units
53          */
54         public String getLabel()
55         {
56                 return I18nManager.getText("fieldname.speed") + " ("
57                         + I18nManager.getText(_unitSet.getSpeedUnit().getShortnameKey()) + ")";
58         }
59
60         /**
61          * @return key for message when no speeds present
62          */
63         public String getNoDataKey() {
64                 return "display.notimestamps";
65         }
66 }