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