X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fgui%2Fprofile%2FAltitudeData.java;fp=tim%2Fprune%2Fgui%2Fprofile%2FAltitudeData.java;h=90130cc19a1f0985e2655da2c55f36ac34cc7305;hb=c0387c124840c9407e040600fda88f3c3e8f6aa6;hp=0000000000000000000000000000000000000000;hpb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;p=GpsPrune.git diff --git a/tim/prune/gui/profile/AltitudeData.java b/tim/prune/gui/profile/AltitudeData.java new file mode 100644 index 0000000..90130cc --- /dev/null +++ b/tim/prune/gui/profile/AltitudeData.java @@ -0,0 +1,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"; + } +}