]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/TrackInfo.java
Version 7, February 2009
[GpsPrune.git] / tim / prune / data / TrackInfo.java
index f8e3c844b8ac86bc46c7c45bf8b78c7bc976f88e..d58cc167d6353239983e846a4e41969d250e7c89 100644 (file)
@@ -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();
        }
@@ -85,31 +82,17 @@ public class TrackInfo
        }
 
 
-       /**
-        * Load the specified data into the Track
-        * @param inFieldArray array of Field objects describing fields
-        * @param inPointArray 2d object array containing data
-        * @param inAltFormat altitude format
-        */
-       public void loadTrack(Field[] inFieldArray, Object[][] inPointArray, int inAltFormat)
-       {
-               _track.cropTo(0);
-               _track.load(inFieldArray, inPointArray, inAltFormat);
-               _selection.clearAll();
-       }
-
-
        /**
         * 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(Set inSet)
+       public int[] addPhotos(Set<Photo> inSet)
        {
                // Firstly count number of points and photos to add
                int numPhotosToAdd = 0;
                int numPointsToAdd = 0;
-               Iterator iterator = null;
+               Iterator<Photo> iterator = null;
                if (inSet != null && !inSet.isEmpty())
                {
                        iterator = inSet.iterator();
@@ -117,7 +100,7 @@ public class TrackInfo
                        {
                                try
                                {
-                                       Photo photo = (Photo) iterator.next();
+                                       Photo photo = iterator.next();
                                        if (photo != null && !_photoList.contains(photo))
                                        {
                                                numPhotosToAdd++;
@@ -142,7 +125,7 @@ public class TrackInfo
                        {
                                try
                                {
-                                       Photo photo = (Photo) iterator.next();
+                                       Photo photo = iterator.next();
                                        if (photo != null && !_photoList.contains(photo))
                                        {
                                                // Add photo
@@ -198,7 +181,7 @@ public class TrackInfo
                if (_track.deletePoint(_selection.getCurrentPointIndex()))
                {
                        _selection.modifyPointDeleted();
-                       _broker.informSubscribers();
+                       UpdateMessageBroker.informSubscribers();
                        return true;
                }
                return false;
@@ -236,38 +219,22 @@ public class TrackInfo
                        }
                        // update subscribers
                        _selection.modifyPointDeleted();
-                       _broker.informSubscribers();
+                       UpdateMessageBroker.informSubscribers();
                }
                return true;
        }
 
 
        /**
-        * Compress the track to the given resolution
-        * @param inResolution resolution
-        * @return number of points deleted
-        */
-       public int compress(int inResolution)
-       {
-               int numDeleted = _track.compress(inResolution);
-               if (numDeleted > 0) {
-                       _selection.clearAll();
-                       _broker.informSubscribers();
-               }
-               return numDeleted;
-       }
-
-
-       /**
-        * Delete all the duplicate points in the track
+        * Delete all the points which have been marked for deletion
         * @return number of points deleted
         */
-       public int deleteDuplicates()
+       public int deleteMarkedPoints()
        {
-               int numDeleted = _track.deleteDuplicates();
+               int numDeleted = _track.deleteMarkedPoints();
                if (numDeleted > 0) {
                        _selection.clearAll();
-                       _broker.informSubscribers();
+                       UpdateMessageBroker.informSubscribers();
                }
                return numDeleted;
        }
@@ -285,15 +252,29 @@ 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;
+       }
+
+
+       /**
+        * Average selected points to create a new one
+        * @return true if successful
+        */
+       public boolean average()
+       {
+               boolean success = _track.average(_selection.getStart(), _selection.getEnd());
+               if (success) {
+                       _selection.selectPoint(_selection.getEnd()+1);
+               }
                return success;
        }
 
@@ -331,13 +312,4 @@ public class TrackInfo
                        _selection.selectPhotoAndPoint(-1, -1);
                }
        }
-
-
-       /**
-        * Fire a trigger to all data subscribers
-        */
-       public void triggerUpdate()
-       {
-               _broker.informSubscribers();
-       }
 }