]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/Track.java
Version 4, January 2008
[GpsPrune.git] / tim / prune / data / Track.java
index e73fa736eb6731d1d7c86ee5d48dffc6bf35b0eb..1188a7c5a83d6edef42a2d8f66c1b7bf59f608df 100644 (file)
@@ -32,9 +32,8 @@ public class Track
 
 
        /**
-        * Constructor giving arrays of Fields and Objects
-        * @param inFieldArray field array
-        * @param inPointArray 2d array of field values
+        * Constructor for empty track
+        * @param inBroker message broker object
         */
        public Track(UpdateMessageBroker inBroker)
        {
@@ -57,6 +56,11 @@ public class Track
         */
        public void load(Field[] inFieldArray, Object[][] inPointArray, int inAltFormat)
        {
+               if (inFieldArray == null || inPointArray == null)
+               {
+                       _numPoints = 0;
+                       return;
+               }
                // copy field list
                _masterFieldList = new FieldList(inFieldArray);
                // make DataPoint object from each point in inPointList
@@ -148,7 +152,8 @@ public class Track
                for (int i=0; i<_numPoints; i++)
                {
                        boolean keepPoint = true;
-                       if (!_dataPoints[i].isWaypoint())
+                       // Don't delete waypoints or photo points
+                       if (!_dataPoints[i].isWaypoint() && _dataPoints[i].getPhoto() == null)
                        {
                                // go through newPointArray to check for range
                                for (int j=0; j<numCopied && keepPoint; j++)
@@ -176,7 +181,6 @@ public class Track
                        System.arraycopy(newPointArray, 0, _dataPoints, 0, numCopied);
                        _numPoints = _dataPoints.length;
                        _scaled = false;
-                       _broker.informSubscribers();
                }
                return numDeleted;
        }
@@ -206,6 +210,7 @@ public class Track
 
        /**
         * Delete the specified point
+        * @param inIndex point index
         * @return true if successful
         */
        public boolean deletePoint(int inIndex)
@@ -223,7 +228,6 @@ public class Track
         */
        public boolean deleteRange(int inStart, int inEnd)
        {
-               // TODO: Check for deleting photos?
                if (inStart < 0 || inEnd < 0 || inEnd < inStart)
                {
                        // no valid range selected so can't delete
@@ -243,7 +247,7 @@ public class Track
                        System.arraycopy(_dataPoints, inEnd + 1, newPointArray, inStart,
                                _numPoints - inEnd - 1);
                }
-               // Copy points over original array (careful!)
+               // Copy points over original array
                _dataPoints = newPointArray;
                _numPoints -= numToDelete;
                // needs to be scaled again
@@ -293,7 +297,6 @@ public class Track
                        _dataPoints = newPointArray;
                        _numPoints = _dataPoints.length;
                        _scaled = false;
-                       _broker.informSubscribers();
                }
                return numDupes;
        }
@@ -301,6 +304,8 @@ public class Track
 
        /**
         * Reverse the specified range of points
+        * @param inStart start index
+        * @param inEnd end index
         * @return true if successful, false otherwise
         */
        public boolean reverseRange(int inStart, int inEnd)
@@ -438,7 +443,6 @@ public class Track
                return true;
        }
 
-       // TODO: Need to rearrange photo points too?
 
        /**
         * Interpolate extra points between two selected ones
@@ -614,13 +618,12 @@ public class Track
                // loop over points and copy all waypoints into list
                for (int i=0; i<=_numPoints-1; i++)
                {
-                       if (_dataPoints[i].isWaypoint())
+                       if (_dataPoints[i] != null && _dataPoints[i].isWaypoint())
                        {
                                inList.add(_dataPoints[i]);
                        }
                }
        }
-       // TODO: Make similar method to get list of photos
 
 
        /**
@@ -845,6 +848,7 @@ public class Track
        /**
         * Replace the track contents with the given point array
         * @param inContents array of DataPoint objects
+        * @return true on success
         */
        public boolean replaceContents(DataPoint[] inContents)
        {
@@ -869,14 +873,24 @@ public class Track
        {
                if (inPoint != null && inEditList != null && inEditList.getNumEdits() > 0)
                {
+                       // remember if coordinates have changed
+                       boolean coordsChanged = false;
                        // go through edits one by one
                        int numEdits = inEditList.getNumEdits();
                        for (int i=0; i<numEdits; i++)
                        {
                                FieldEdit edit = inEditList.getEdit(i);
                                inPoint.setFieldValue(edit.getField(), edit.getValue());
+                               // check coordinates
+                               coordsChanged |= (edit.getField().equals(Field.LATITUDE)
+                                       || edit.getField().equals(Field.LONGITUDE) || edit.getField().equals(Field.ALTITUDE));
+                       }
+                       // set photo status if coordinates have changed
+                       if (inPoint.getPhoto() != null && coordsChanged)
+                       {
+                               inPoint.getPhoto().setCurrentStatus(PhotoStatus.CONNECTED);
                        }
-                       // possibly needs to be scaled again
+                       // point possibly needs to be scaled again
                        _scaled = false;
                        // trigger listeners
                        _broker.informSubscribers();