X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;ds=sidebyside;f=tim%2Fprune%2Fdata%2FSelection.java;h=cdbe58ecca33035a7a012d5ee5e3be402e422ccc;hb=ca9bdb3916f9c39adbbf95d06ac95c21dafbb4e6;hp=c375e820b4a05b022682deef2b675ee27a82b8d8;hpb=312fec956e43f5d0a38617da5d0add9c62563e2c;p=GpsPrune.git diff --git a/tim/prune/data/Selection.java b/tim/prune/data/Selection.java index c375e82..cdbe58e 100644 --- a/tim/prune/data/Selection.java +++ b/tim/prune/data/Selection.java @@ -1,5 +1,6 @@ package tim.prune.data; +import tim.prune.DataSubscriber; import tim.prune.UpdateMessageBroker; /** @@ -9,10 +10,10 @@ import tim.prune.UpdateMessageBroker; public class Selection { private Track _track = null; - private UpdateMessageBroker _broker = null; private int _currentPoint = -1; private boolean _valid = false; private int _startIndex = -1, _endIndex = -1; + private int _currentPhotoIndex = -1; private IntegerRange _altitudeRange = null; private int _climb = -1, _descent = -1; private int _altitudeFormat = Altitude.FORMAT_NONE; @@ -23,12 +24,10 @@ public class Selection /** * Constructor * @param inTrack track object - * @param inBroker broker object */ - public Selection(Track inTrack, UpdateMessageBroker inBroker) + public Selection(Track inTrack) { _track = inTrack; - _broker = inBroker; } @@ -242,12 +241,12 @@ public class Selection /** - * @param inFormat distance units to use, from class Distance + * @param inUnits distance units to use, from class Distance * @return distance of Selection in specified units */ public double getDistance(int inUnits) { - return Distance.convertRadians(_angDistance, inUnits); + return Distance.convertRadiansToDistance(_angDistance, inUnits); } @@ -258,6 +257,7 @@ public class Selection { _currentPoint = -1; deselectRange(); + deselectPhoto(); } @@ -301,7 +301,7 @@ public class Selection } } reset(); - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); } @@ -334,7 +334,7 @@ public class Selection } } reset(); - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(); } @@ -377,28 +377,75 @@ public class Selection } + /** + * 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 + */ + public void selectPhotoAndPoint(int inPhotoIndex, int inPointIndex) + { + _currentPhotoIndex = inPhotoIndex; + if (inPointIndex > -1) + { + // select associated point, if any + selectPoint(inPointIndex); + } + else + { + // Check if not already done + check(); + } + } + + + /** + * @return currently selected photo index + */ + public int getCurrentPhotoIndex() + { + return _currentPhotoIndex; + } + /** * Check that the selection still makes sense * and fire update message to listeners */ private void check() { - if (_track != null && _track.getNumPoints() > 0) + if (_track != null) { - int maxIndex = _track.getNumPoints() - 1; - if (_currentPoint > maxIndex) - { - _currentPoint = maxIndex; - } - if (_endIndex > maxIndex) + if (_track.getNumPoints() > 0) { - _endIndex = maxIndex; + int maxIndex = _track.getNumPoints() - 1; + if (_currentPoint > maxIndex) + { + _currentPoint = maxIndex; + } + if (_endIndex > maxIndex) + { + _endIndex = maxIndex; + } + if (_startIndex > maxIndex) + { + _startIndex = maxIndex; + } } - if (_startIndex > maxIndex) + else { - _startIndex = maxIndex; + // track is empty, clear selections + _currentPoint = _startIndex = _endIndex = -1; } } - _broker.informSubscribers(); + UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED); } }