]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/gui/colour/FileColourer.java
Version 20.4, May 2021
[GpsPrune.git] / src / tim / prune / gui / colour / FileColourer.java
1 package tim.prune.gui.colour;
2
3 import java.awt.Color;
4 import java.util.ArrayList;
5
6 import tim.prune.data.DataPoint;
7 import tim.prune.data.FileInfo;
8 import tim.prune.data.SourceInfo;
9 import tim.prune.data.TrackInfo;
10
11 /**
12  * Colours points according to which file (or source) they came from
13  */
14 public class FileColourer extends DiscretePointColourer
15 {
16         /**
17          * Constructor
18          * @param inStartColour start colour of scale
19          * @param inEndColour end colour of scale
20          * @param inWrapLength number of unique colours before wrap
21          */
22         public FileColourer(Color inStartColour, Color inEndColour, int inWrapLength)
23         {
24                 super(inStartColour, inEndColour, inWrapLength);
25         }
26
27         /**
28          * Calculate the colours for each of the points in the given track
29          * @param inTrackInfo track info object
30          */
31         @Override
32         public void calculateColours(TrackInfo inTrackInfo)
33         {
34                 // initialise the array to the right size
35                 final int numPoints = inTrackInfo.getTrack().getNumPoints();
36                 init(numPoints);
37
38                 // loop over track points
39                 FileInfo fInfo = inTrackInfo.getFileInfo();
40                 ArrayList<SourceInfo> sourceList = new ArrayList<SourceInfo>();
41                 for (int i=0; i<numPoints; i++)
42                 {
43                         DataPoint p = inTrackInfo.getTrack().getPoint(i);
44                         if (p != null && !p.isWaypoint())
45                         {
46                                 SourceInfo sInfo = fInfo.getSourceForPoint(p);
47                                 // Is this info object already in the list?
48                                 int foundIndex = -1;
49                                 int sIndex = 0;
50                                 for (SourceInfo si : sourceList) {
51                                         if (si == sInfo) {
52                                                 foundIndex = sIndex;
53                                                 break;
54                                         }
55                                         sIndex++;
56                                 }
57                                 // Add source info to list
58                                 if (foundIndex < 0)
59                                 {
60                                         sourceList.add(sInfo);
61                                         foundIndex = sourceList.size()-1;
62                                 }
63                                 // use this foundIndex to find the colour
64                                 setColour(i, foundIndex);
65                         }
66                 }
67                 // generate the colours needed
68                 generateDiscreteColours(sourceList.size());
69         }
70 }