private Track _track = null;
private int _currentPoint = -1;
private boolean _valid = false;
+ private int _prevNumPoints = 0;
private int _startIndex = -1, _endIndex = -1;
private int _currentPhotoIndex = -1;
+ private int _currentAudioIndex = -1;
private IntegerRange _altitudeRange = null;
private int _climb = -1, _descent = -1;
private Altitude.Format _altitudeFormat = Altitude.Format.NO_FORMAT;
private long _totalSeconds = 0L, _movingSeconds = 0L;
private double _angDistance = -1.0, _angMovingDistance = -1.0;
+ private int _numSegments = 0;
/**
/**
- * Reset selection to be recalculated
+ * Mark selection invalid so it will be recalculated
*/
- private void reset()
+ public void markInvalid()
{
_valid = false;
}
- /**
- * Select the point at the given index
- * @param inIndex index number of selected point
- */
- public void selectPoint(int inIndex)
- {
- if (inIndex >= -1)
- {
- _currentPoint = inIndex;
- check();
- }
- }
-
- /**
- * Select the specified point and range in one go
- * @param inPointIndex point selection
- * @param inStart range start
- * @param inEnd range end
- */
- public void select(int inPointIndex, int inStart, int inEnd)
- {
- _currentPoint = inPointIndex;
- _startIndex = inStart;
- _endIndex = inEnd;
- reset();
- check();
- }
-
-
- /**
- * Select the previous point
- */
- public void selectPreviousPoint()
- {
- if (_currentPoint > 0)
- selectPoint(_currentPoint - 1);
- }
-
- /**
- * Select the next point
- */
- public void selectNextPoint()
- {
- selectPoint(_currentPoint + 1);
- }
-
/**
* @return the current point index
*/
private void recalculate()
{
_altitudeFormat = Altitude.Format.NO_FORMAT;
- if (_track.getNumPoints() > 0 && hasRangeSelected())
+ _numSegments = 0;
+ final int numPoints = _track.getNumPoints();
+ // Recheck if the number of points has changed
+ if (numPoints != _prevNumPoints) {
+ _prevNumPoints = numPoints;
+ check();
+ }
+ if (numPoints > 0 && hasRangeSelected())
{
_altitudeRange = new IntegerRange();
_climb = 0;
{
double radians = DataPoint.calculateRadiansBetween(lastPoint, currPoint);
_angDistance += radians;
- if (!currPoint.getSegmentStart()) {
+ if (currPoint.getSegmentStart()) {
+ _numSegments++;
+ }
+ else {
_angMovingDistance += radians;
}
}
lastPoint = currPoint;
+ // If it's a track point then there must be at least one segment
+ if (_numSegments == 0) {_numSegments = 1;}
}
}
if (endTime != null) {
}
/**
- * Clear selected point and range
+ * @return number of segments in selection
+ */
+ public int getNumSegments()
+ {
+ return _numSegments;
+ }
+
+ /**
+ * Clear selected point, range, photo and audio
*/
public void clearAll()
{
_currentPoint = -1;
- deselectRange();
- deselectPhoto();
+ selectRange(-1, -1);
+ _currentPhotoIndex = -1;
+ _currentAudioIndex = -1;
+ check();
}
/**
- * Deselect range
+ * Select range from start to end
+ * @param inStartIndex index of start of range
+ * @param inEndIndex index of end of range
*/
- public void deselectRange()
+ public void selectRange(int inStartIndex, int inEndIndex)
{
- _startIndex = _endIndex = -1;
- reset();
+ _startIndex = inStartIndex;
+ _endIndex = inEndIndex;
+ markInvalid();
check();
}
* Set the index for the start of the range selection
* @param inStartIndex start index
*/
- public void selectRangeStart(int inStartIndex)
+ private void selectRangeStart(int inStartIndex)
{
if (inStartIndex < 0)
{
_endIndex = _track.getNumPoints() - 1;
}
}
- reset();
+ markInvalid();
UpdateMessageBroker.informSubscribers();
}
{
_endIndex = inEndIndex;
// Move start of selection to min if necessary
- if (_startIndex > _endIndex || _startIndex < 0)
- {
+ if (_startIndex > _endIndex || _startIndex < 0) {
_startIndex = 0;
}
}
- reset();
+ markInvalid();
UpdateMessageBroker.informSubscribers();
}
_endIndex--;
if (_currentPoint < _startIndex)
_startIndex--;
- reset();
+ markInvalid();
}
check();
}
- /**
- * Deselect photo
- */
- public void deselectPhoto()
- {
- _currentPhotoIndex = -1;
- check();
- }
-
-
/**
* Select the specified photo and point
- * @param inPhotoIndex index of selected photo in PhotoList
* @param inPointIndex index of selected point
+ * @param inPhotoIndex index of selected photo in PhotoList
+ * @param inAudioIndex index of selected audio item
*/
- public void selectPhotoAndPoint(int inPhotoIndex, int inPointIndex)
+ public void selectPointPhotoAudio(int inPointIndex, int inPhotoIndex, int inAudioIndex)
{
+ _currentPoint = inPointIndex;
_currentPhotoIndex = inPhotoIndex;
- if (inPointIndex > -1)
- {
- // select associated point, if any
- selectPoint(inPointIndex);
- }
- else
- {
- // Check if not already done
- check();
- }
+ _currentAudioIndex = inAudioIndex;
+ check();
}
return _currentPhotoIndex;
}
+ /**
+ * @return currently selected audio index
+ */
+ public int getCurrentAudioIndex()
+ {
+ return _currentAudioIndex;
+ }
+
/**
* Check that the selection still makes sense
* and fire update message to listeners
*/
private void check()
{
- if (_track != null)
+ if (_track != null && _track.getNumPoints() > 0)
{
- if (_track.getNumPoints() > 0)
+ int maxIndex = _track.getNumPoints() - 1;
+ if (_currentPoint > maxIndex)
{
- int maxIndex = _track.getNumPoints() - 1;
- if (_currentPoint > maxIndex)
- {
- _currentPoint = maxIndex;
- }
- if (_endIndex > maxIndex)
- {
- _endIndex = maxIndex;
- }
- if (_startIndex > maxIndex)
- {
- _startIndex = maxIndex;
- }
+ _currentPoint = maxIndex;
}
- else
+ if (_endIndex > maxIndex)
{
- // track is empty, clear selections
- _currentPoint = _startIndex = _endIndex = -1;
+ _endIndex = maxIndex;
}
+ if (_startIndex > maxIndex)
+ {
+ _startIndex = maxIndex;
+ }
+ }
+ else
+ {
+ // track is empty, clear selections
+ _currentPoint = _startIndex = _endIndex = -1;
}
UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED);
}