X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FSourceInfo.java;h=d71280db8a5e45c28d594b0306b3b82c10797b16;hb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465;hp=bbe8baa3d9cfb269eb9efcbd268b4a48976a2d8f;hpb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;p=GpsPrune.git diff --git a/tim/prune/data/SourceInfo.java b/tim/prune/data/SourceInfo.java index bbe8baa..d71280d 100644 --- a/tim/prune/data/SourceInfo.java +++ b/tim/prune/data/SourceInfo.java @@ -3,14 +3,13 @@ package tim.prune.data; import java.io.File; /** - * Class to hold the source of the point data, - * including original file and file type, and - * also file offsets for source copying + * Class to hold the source of the point data, including the original file + * and file type, and references to each of the point objects */ public class SourceInfo { /** File type of source file */ - public enum FILE_TYPE {TEXT, GPX, KML, NMEA, GPSBABEL, GPSIES}; + public enum FILE_TYPE {TEXT, GPX, KML, NMEA, GPSBABEL, GPSIES, JSON}; /** Source file */ private File _sourceFile = null; @@ -18,9 +17,15 @@ public class SourceInfo private String _sourceName = null; /** File type */ private FILE_TYPE _fileType = null; + /** File title, if any */ + private String _fileTitle = null; /** Array of datapoints */ private DataPoint[] _points = null; + /** Number of points */ + private int _numPoints = 0; + /** Array of point indices (if necessary) */ + private int[] _pointIndices = null; /** @@ -47,6 +52,14 @@ public class SourceInfo _fileType = inType; } + /** + * @param inTitle title of file, eg from tag in gpx + */ + public void setFileTitle(String inTitle) + { + _fileTitle = inTitle; + } + /** * @return source file */ @@ -71,12 +84,35 @@ public class SourceInfo return _fileType; } + /** + * @return title of file + */ + public String getFileTitle() + { + return _fileTitle; + } + /** * @return number of points from this source */ public int getNumPoints() { - return _points.length; + return _numPoints; + } + + /** + * Set the indices of the points selected out of a loaded track + * @param inSelectedFlags array of booleans showing whether each point in the original data was loaded or not + */ + public void setPointIndices(boolean[] inSelectedFlags) + { + _numPoints = inSelectedFlags.length; + _pointIndices = new int[_numPoints]; + int p=0; + for (int i=0; i<_numPoints; i++) { + if (inSelectedFlags[i]) {_pointIndices[p++] = i;} + } + // Now the point indices array holds the index of each of the selected points } /** @@ -86,6 +122,7 @@ public class SourceInfo */ public void populatePointObjects(Track inTrack, int inNumPoints) { + if (_numPoints == 0) {_numPoints = inNumPoints;} if (inNumPoints > 0) { _points = new DataPoint[inNumPoints]; @@ -103,9 +140,15 @@ public class SourceInfo public int getIndex(DataPoint inPoint) { int idx = -1; - for (int i=0; i<_points.length && (idx < 0); i++) { - if (_points[i] == inPoint) {idx = i;} + for (int i=0; i<_points.length; i++) + { + if (_points[i] == inPoint) { + idx = i; + break; + } } - return idx; + if (idx == -1) {return idx;} // point not found + if (_pointIndices == null) {return idx;} // All points loaded + return _pointIndices[idx]; // use point index mapping } }