]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/gui/colour/SegmentColourer.java
942622251e27c4f82084f97e9abfe8d6cbca07cd
[GpsPrune.git] / src / tim / prune / gui / colour / SegmentColourer.java
1 package tim.prune.gui.colour;
2
3 import java.awt.Color;
4
5 import tim.prune.data.DataPoint;
6 import tim.prune.data.Track;
7 import tim.prune.data.TrackInfo;
8
9 /**
10  * Point colourer using the segment indices
11  */
12 public class SegmentColourer extends DiscretePointColourer
13 {
14         /**
15          * Constructor
16          * @param inStartColour start colour of scale
17          * @param inEndColour end colour of scale
18          * @param inWrapLength number of unique colours before wrap
19          */
20         public SegmentColourer(Color inStartColour, Color inEndColour, int inWrapLength)
21         {
22                 super(inStartColour, inEndColour, inWrapLength);
23         }
24
25         /**
26          * Calculate the colours for each of the points in the given track
27          * @param inTrackInfo track info object
28          */
29         @Override
30         public void calculateColours(TrackInfo inTrackInfo)
31         {
32                 // initialise the array to the right size
33                 Track track = inTrackInfo == null ? null : inTrackInfo.getTrack();
34                 final int numPoints = track == null ? 0 : track.getNumPoints();
35                 init(numPoints);
36                 // loop over track points
37                 int c = -1; // first track point will increment this to 0
38                 for (int i=0; i<numPoints; i++)
39                 {
40                         DataPoint p = track.getPoint(i);
41                         if (p != null && !p.isWaypoint())
42                         {
43                                 if (p.getSegmentStart()) {
44                                         c++;
45                                 }
46                                 setColour(i, c);
47                         }
48                 }
49                 // generate the colours needed
50                 generateDiscreteColours(c+1);
51         }
52 }