1 package tim.prune.data;
5 import tim.prune.UpdateMessageBroker;
8 * Class to hold all track information, including data
9 * and the selection information
11 public class TrackInfo
13 private UpdateMessageBroker _broker = null;
14 private Track _track = null;
15 private Selection _selection = null;
16 private FileInfo _fileInfo = null;
17 // TODO: How to store photos? In separate list to be maintained or dynamic? Only store pointless photos?
18 private PhotoList _photoList = null;
23 * @param inTrack Track object
24 * @param inBroker broker object
26 public TrackInfo(Track inTrack, UpdateMessageBroker inBroker)
30 _selection = new Selection(_track, inBroker);
31 _fileInfo = new FileInfo();
32 _photoList = new PhotoList();
37 * @return the Track object
39 public Track getTrack()
46 * @return the Selection object
48 public Selection getSelection()
55 * @return the FileInfo object
57 public FileInfo getFileInfo()
63 * @return the PhotoList object
65 public PhotoList getPhotoList()
71 * Get the currently selected point, if any
72 * @return DataPoint if single point selected, otherwise null
74 public DataPoint getCurrentPoint()
76 return _track.getPoint(_selection.getCurrentPointIndex());
81 * Load the specified data into the Track
82 * @param inFieldArray array of Field objects describing fields
83 * @param inPointArray 2d object array containing data
84 * @param inAltFormat altitude format
86 public void loadTrack(Field[] inFieldArray, Object[][] inPointArray, int inAltFormat)
89 _track.load(inFieldArray, inPointArray, inAltFormat);
90 _selection.clearAll();
95 * Add a List of Photos
96 * @param inList List containing Photo objects
97 * @return number of photos added
99 public int addPhotos(List inList)
101 // Firstly count number to add to make array
102 int numPhotosToAdd = 0;
103 if (inList != null && !inList.isEmpty())
105 for (int i=0; i<inList.size(); i++)
109 Photo photo = (Photo) inList.get(i);
110 if (photo != null && !_photoList.contains(photo))
115 catch (ClassCastException ce) {}
118 // If there are any photos to add, add them
119 if (numPhotosToAdd > 0)
121 DataPoint[] dataPoints = new DataPoint[numPhotosToAdd];
123 // Add each Photo in turn
124 for (int i=0; i<inList.size(); i++)
128 Photo photo = (Photo) inList.get(i);
129 if (photo != null && !_photoList.contains(photo))
131 _photoList.addPhoto(photo);
132 dataPoints[pointNum] = photo.getDataPoint();
136 catch (ClassCastException ce) {}
138 _track.appendPoints(dataPoints);
140 return numPhotosToAdd;
145 * Delete the currently selected range of points
146 * @return true if successful
148 public boolean deleteRange()
150 // TODO: Check whether to delete photos associated with this range
151 int currPoint = _selection.getCurrentPointIndex();
152 int startSel = _selection.getStart();
153 int endSel = _selection.getEnd();
154 boolean answer = _track.deleteRange(startSel, endSel);
155 // clear range selection
156 _selection.modifyRangeDeleted();
162 * Delete the currently selected point
163 * @return true if point deleted
165 public boolean deletePoint()
167 if (_track.deletePoint(_selection.getCurrentPointIndex()))
169 // TODO: Check whether to delete photo associated with this point
170 _selection.modifyPointDeleted();
171 _broker.informSubscribers();
179 * Compress the track to the given resolution
180 * @param inResolution resolution
181 * @return number of points deleted
183 public int compress(int inResolution)
185 int numDeleted = _track.compress(inResolution);
187 _selection.clearAll();
193 * Delete all the duplicate points in the track
194 * @return number of points deleted
196 public int deleteDuplicates()
198 int numDeleted = _track.deleteDuplicates();
200 _selection.clearAll();
206 * Clone the selected range of data points
207 * @return shallow copy of DataPoint objects
209 public DataPoint[] cloneSelectedRange()
211 return _track.cloneRange(_selection.getStart(), _selection.getEnd());
216 * Interpolate extra points between two selected ones
217 * @param inStartIndex start index of interpolation
218 * @param inNumPoints num points to insert
219 * @return true if successful
221 public boolean interpolate(int inNumPoints)
223 boolean success = _track.interpolate(_selection.getStart(), inNumPoints);
225 _selection.selectRangeEnd(_selection.getEnd() + inNumPoints);
231 * Select the given DataPoint
232 * @param inPoint DataPoint object to select
234 public void selectPoint(DataPoint inPoint)
236 // get the index of the given Point
237 int index = _track.getPointIndex(inPoint);
239 _selection.selectPoint(index);