]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/TrackInfo.java
Version 6, October 2008
[GpsPrune.git] / tim / prune / data / TrackInfo.java
index b987ea9449d6dff66fd52f2af60031752f415413..4f3ce27e8f85b79c6b3582d5af20f27593f7fabb 100644 (file)
@@ -1,7 +1,7 @@
 package tim.prune.data;
 
-import java.util.List;
-
+import java.util.Iterator;
+import java.util.Set;
 import tim.prune.UpdateMessageBroker;
 
 /**
@@ -10,7 +10,6 @@ import tim.prune.UpdateMessageBroker;
  */
 public class TrackInfo
 {
-       private UpdateMessageBroker _broker = null;
        private Track _track = null;
        private Selection _selection = null;
        private FileInfo _fileInfo = null;
@@ -20,13 +19,11 @@ public class TrackInfo
        /**
         * Constructor
         * @param inTrack Track object
-        * @param inBroker broker object
         */
-       public TrackInfo(Track inTrack, UpdateMessageBroker inBroker)
+       public TrackInfo(Track inTrack)
        {
-               _broker = inBroker;
                _track = inTrack;
-               _selection = new Selection(_track, inBroker);
+               _selection = new Selection(_track);
                _fileInfo = new FileInfo();
                _photoList = new PhotoList();
        }
@@ -100,23 +97,24 @@ public class TrackInfo
 
 
        /**
-        * Add a List of Photos
-        * @param inList List containing Photo objects
+        * Add a Set of Photos
+        * @param inSet Set containing Photo objects
         * @return array containing number of photos and number of points added
         */
-       public int[] addPhotos(List inList)
+       public int[] addPhotos(Set inSet)
        {
-               // TODO: Should photos be sorted at load-time, either by filename or date?
                // Firstly count number of points and photos to add
                int numPhotosToAdd = 0;
                int numPointsToAdd = 0;
-               if (inList != null && !inList.isEmpty())
+               Iterator iterator = null;
+               if (inSet != null && !inSet.isEmpty())
                {
-                       for (int i=0; i<inList.size(); i++)
+                       iterator = inSet.iterator();
+                       while (iterator.hasNext())
                        {
                                try
                                {
-                                       Photo photo = (Photo) inList.get(i);
+                                       Photo photo = (Photo) iterator.next();
                                        if (photo != null && !_photoList.contains(photo))
                                        {
                                                numPhotosToAdd++;
@@ -136,11 +134,12 @@ public class TrackInfo
                        int pointNum = 0;
                        boolean hasAltitude = false;
                        // Add each Photo in turn
-                       for (int i=0; i<inList.size(); i++)
+                       iterator = inSet.iterator();
+                       while (iterator.hasNext())
                        {
                                try
                                {
-                                       Photo photo = (Photo) inList.get(i);
+                                       Photo photo = (Photo) iterator.next();
                                        if (photo != null && !_photoList.contains(photo))
                                        {
                                                // Add photo
@@ -196,7 +195,7 @@ public class TrackInfo
                if (_track.deletePoint(_selection.getCurrentPointIndex()))
                {
                        _selection.modifyPointDeleted();
-                       _broker.informSubscribers();
+                       UpdateMessageBroker.informSubscribers();
                        return true;
                }
                return false;
@@ -234,7 +233,7 @@ public class TrackInfo
                        }
                        // update subscribers
                        _selection.modifyPointDeleted();
-                       _broker.informSubscribers();
+                       UpdateMessageBroker.informSubscribers();
                }
                return true;
        }
@@ -248,8 +247,10 @@ public class TrackInfo
        public int compress(int inResolution)
        {
                int numDeleted = _track.compress(inResolution);
-               if (numDeleted > 0)
+               if (numDeleted > 0) {
                        _selection.clearAll();
+                       UpdateMessageBroker.informSubscribers();
+               }
                return numDeleted;
        }
 
@@ -261,8 +262,10 @@ public class TrackInfo
        public int deleteDuplicates()
        {
                int numDeleted = _track.deleteDuplicates();
-               if (numDeleted > 0)
+               if (numDeleted > 0) {
                        _selection.clearAll();
+                       UpdateMessageBroker.informSubscribers();
+               }
                return numDeleted;
        }
 
@@ -279,15 +282,15 @@ public class TrackInfo
 
        /**
         * Interpolate extra points between two selected ones
-        * @param inStartIndex start index of interpolation
         * @param inNumPoints num points to insert
         * @return true if successful
         */
        public boolean interpolate(int inNumPoints)
        {
                boolean success = _track.interpolate(_selection.getStart(), inNumPoints);
-               if (success)
+               if (success) {
                        _selection.selectRangeEnd(_selection.getEnd() + inNumPoints);
+               }
                return success;
        }
 
@@ -325,13 +328,4 @@ public class TrackInfo
                        _selection.selectPhotoAndPoint(-1, -1);
                }
        }
-
-
-       /**
-        * Fire a trigger to all data subscribers
-        */
-       public void triggerUpdate()
-       {
-               _broker.informSubscribers();
-       }
 }