]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/profile/AltitudeData.java
90130cc19a1f0985e2655da2c55f36ac34cc7305
[GpsPrune.git] / tim / prune / gui / profile / AltitudeData.java
1 package tim.prune.gui.profile;
2
3 import tim.prune.I18nManager;
4 import tim.prune.data.Altitude;
5 import tim.prune.data.DataPoint;
6 import tim.prune.data.Track;
7
8 /**
9  * Class to provide a source of altitude data for the profile chart
10  */
11 public class AltitudeData extends ProfileData
12 {
13         /** Altitude format for values */
14         private Altitude.Format _altitudeFormat = Altitude.Format.NO_FORMAT;
15
16
17         /**
18          * Constructor
19          * @param inTrack track object
20          */
21         public AltitudeData(Track inTrack) {
22                 super(inTrack);
23         }
24
25         /**
26          * Get the data and populate the instance arrays
27          */
28         public void init()
29         {
30                 initArrays();
31                 _hasData = false;
32                 _altitudeFormat = Altitude.Format.NO_FORMAT;
33                 if (_track != null) {
34                         for (int i=0; i<_track.getNumPoints(); i++)
35                         {
36                                 DataPoint point = _track.getPoint(i);
37                                 if (point != null && point.hasAltitude())
38                                 {
39                                         // Point has an altitude - if it's the first one, use its format
40                                         if (_altitudeFormat == Altitude.Format.NO_FORMAT)
41                                         {
42                                                 _altitudeFormat = point.getAltitude().getFormat();
43                                                 _minValue = _maxValue = point.getAltitude().getValue();
44                                         }
45                                         // Store the value and maintain max and min values
46                                         double value = point.getAltitude().getValue(_altitudeFormat);
47                                         _pointValues[i] = value;
48                                         if (value < _minValue) {_minValue = value;}
49                                         if (value > _maxValue) {_maxValue = value;}
50
51                                         _hasData = true;
52                                         _pointHasData[i] = true;
53                                 }
54                         }
55                 }
56         }
57
58         /**
59          * @return text description including units
60          */
61         public String getLabel()
62         {
63                 return I18nManager.getText("fieldname.altitude") + " ("
64                         + I18nManager.getText(_altitudeFormat==Altitude.Format.FEET?"units.feet.short":"units.metres.short")
65                         + ")";
66         }
67
68         /**
69          * @return key for message when no altitudes present
70          */
71         public String getNoDataKey() {
72                 return "display.noaltitudes";
73         }
74 }