1 package tim.prune.gui.profile;
3 import tim.prune.I18nManager;
4 import tim.prune.data.Altitude;
5 import tim.prune.data.DataPoint;
6 import tim.prune.data.Track;
9 * Class to provide a source of altitude data for the profile chart
11 public class AltitudeData extends ProfileData
13 /** Altitude format for values */
14 private Altitude.Format _altitudeFormat = Altitude.Format.NO_FORMAT;
19 * @param inTrack track object
21 public AltitudeData(Track inTrack) {
26 * Get the data and populate the instance arrays
32 _altitudeFormat = Altitude.Format.NO_FORMAT;
35 for (int i=0; i<_track.getNumPoints(); i++)
39 DataPoint point = _track.getPoint(i);
40 if (point != null && point.hasAltitude())
42 // Point has an altitude - if it's the first one, use its format
43 if (_altitudeFormat == Altitude.Format.NO_FORMAT)
45 _altitudeFormat = point.getAltitude().getFormat();
46 _minValue = _maxValue = point.getAltitude().getValue();
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;}
55 _pointHasData[i] = true;
57 else _pointHasData[i] = false;
59 catch (ArrayIndexOutOfBoundsException obe)
60 {} // must be due to the track size changing during calculation
61 // assume that a redraw will be triggered
67 * @return text description including units
69 public String getLabel()
71 return I18nManager.getText("fieldname.altitude") + " ("
72 + I18nManager.getText(_altitudeFormat==Altitude.Format.FEET?"units.feet.short":"units.metres.short")
77 * @return key for message when no altitudes present
79 public String getNoDataKey() {
80 return "display.noaltitudes";