]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/profile/AltitudeData.java
e3bfbea327dea79a2558a09fbe13cdb1976d0a77
[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                 {
35                         for (int i=0; i<_track.getNumPoints(); i++)
36                         {
37                                 try
38                                 {
39                                         DataPoint point = _track.getPoint(i);
40                                         if (point != null && point.hasAltitude())
41                                         {
42                                                 // Point has an altitude - if it's the first one, use its format
43                                                 if (_altitudeFormat == Altitude.Format.NO_FORMAT)
44                                                 {
45                                                         _altitudeFormat = point.getAltitude().getFormat();
46                                                         _minValue = _maxValue = point.getAltitude().getValue();
47                                                 }
48                                                 // Store the value and maintain max and min values
49                                                 double value = point.getAltitude().getValue(_altitudeFormat);
50                                                 _pointValues[i] = value;
51                                                 if (value < _minValue) {_minValue = value;}
52                                                 if (value > _maxValue) {_maxValue = value;}
53
54                                                 _hasData = true;
55                                                 _pointHasData[i] = true;
56                                         }
57                                         else _pointHasData[i] = false;
58                                 }
59                                 catch (ArrayIndexOutOfBoundsException obe)
60                                 {} // must be due to the track size changing during calculation
61                                    // assume that a redraw will be triggered
62                         }
63                 }
64         }
65
66         /**
67          * @return text description including units
68          */
69         public String getLabel()
70         {
71                 return I18nManager.getText("fieldname.altitude") + " ("
72                         + I18nManager.getText(_altitudeFormat==Altitude.Format.FEET?"units.feet.short":"units.metres.short")
73                         + ")";
74         }
75
76         /**
77          * @return key for message when no altitudes present
78          */
79         public String getNoDataKey() {
80                 return "display.noaltitudes";
81         }
82 }