]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/TrackInfo.java
Version 1, September 2006
[GpsPrune.git] / tim / prune / data / TrackInfo.java
1 package tim.prune.data;
2
3 import tim.prune.UpdateMessageBroker;
4
5 /**
6  * Class to hold all track information, including data
7  * and the selection information
8  */
9 public class TrackInfo
10 {
11         private UpdateMessageBroker _broker = null;
12         private Track _track = null;
13         private Selection _selection = null;
14         private FileInfo _fileInfo = null;
15
16         /**
17          * Constructor
18          * @param inTrack Track object
19          * @param inBroker broker object
20          */
21         public TrackInfo(Track inTrack, UpdateMessageBroker inBroker)
22         {
23                 _broker = inBroker;
24                 _track = inTrack;
25                 _selection = new Selection(_track, inBroker);
26                 _fileInfo = new FileInfo();
27         }
28
29
30         /**
31          * @return the Track object
32          */
33         public Track getTrack()
34         {
35                 return _track;
36         }
37
38
39         /**
40          * @return the Selection object
41          */
42         public Selection getSelection()
43         {
44                 return _selection;
45         }
46
47
48         /**
49          * @return the FileInfo object
50          */
51         public FileInfo getFileInfo()
52         {
53                 return _fileInfo;
54         }
55
56         /**
57          * Get the currently selected point, if any
58          * @return DataPoint if single point selected, otherwise null
59          */
60         public DataPoint getCurrentPoint()
61         {
62                 return _track.getPoint(_selection.getCurrentPointIndex());
63         }
64
65
66         /**
67          * Load the specified data into the Track
68          * @param inFieldArray array of Field objects describing fields
69          * @param inPointArray 2d object array containing data
70          * @param inAltFormat altitude format
71          */
72         public void loadTrack(Field[] inFieldArray, Object[][] inPointArray, int inAltFormat)
73         {
74                 _track.cropTo(0);
75                 _track.load(inFieldArray, inPointArray, inAltFormat);
76                 _selection.clearAll();
77         }
78
79
80         /**
81          * Delete the currently selected range of points
82          * @return true if successful
83          */
84         public boolean deleteRange()
85         {
86                 int currPoint = _selection.getCurrentPointIndex();
87                 int startSel = _selection.getStart();
88                 int endSel = _selection.getEnd();
89                 boolean answer = _track.deleteRange(startSel, endSel);
90                 // clear range selection
91                 _selection.modifyRangeDeleted();
92                 return answer;
93         }
94
95
96         /**
97          * Delete the currently selected point
98          * @return true if point deleted
99          */
100         public boolean deletePoint()
101         {
102                 if (_track.deletePoint(_selection.getCurrentPointIndex()))
103                 {
104                         _selection.modifyPointDeleted();
105                         _broker.informSubscribers();
106                         return true;
107                 }
108                 return false;
109         }
110
111
112         /**
113          * Compress the track to the given resolution
114          * @param inResolution resolution
115          * @return number of points deleted
116          */
117         public int compress(int inResolution)
118         {
119                 int numDeleted = _track.compress(inResolution);
120                 if (numDeleted > 0)
121                         _selection.clearAll();
122                 return numDeleted;
123         }
124
125
126         /**
127          * Delete all the duplicate points in the track
128          * @return number of points deleted
129          */
130         public int deleteDuplicates()
131         {
132                 int numDeleted = _track.deleteDuplicates();
133                 if (numDeleted > 0)
134                         _selection.clearAll();
135                 return numDeleted;
136         }
137
138
139         /**
140          * Clone the selected range of data points
141          * @return shallow copy of DataPoint objects
142          */
143         public DataPoint[] cloneSelectedRange()
144         {
145                 return _track.cloneRange(_selection.getStart(), _selection.getEnd());
146         }
147
148
149         /**
150          * Interpolate extra points between two selected ones
151          * @param inStartIndex start index of interpolation
152          * @param inNumPoints num points to insert
153          * @return true if successful
154          */
155         public boolean interpolate(int inNumPoints)
156         {
157                 boolean success = _track.interpolate(_selection.getStart(), inNumPoints);
158                 if (success)
159                         _selection.selectRangeEnd(_selection.getEnd() + inNumPoints);
160                 return success;
161         }
162 }