]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/colour/ContinuousPointColourer.java
Version 17, September 2014
[GpsPrune.git] / tim / prune / gui / colour / ContinuousPointColourer.java
1 package tim.prune.gui.colour;
2
3 import java.awt.Color;
4
5 public abstract class ContinuousPointColourer extends PointColourer
6 {
7         /** array of colours to use */
8         private Color[] _colours = null;
9
10         /**
11          * Constructor
12          * @param inStartColour start colour
13          * @param inEndColour end colour
14          */
15         public ContinuousPointColourer(Color inStartColour, Color inEndColour)
16         {
17                 super(inStartColour, inEndColour);
18         }
19
20         /** Continuous colourers don't need a maximum count */
21         public static boolean isMaxColoursRequired() {
22                 return false;
23         }
24
25         /**
26          * Initialise the array to the right size
27          * @param inNumPoints number of points in the track
28          */
29         protected void init(int inNumPoints)
30         {
31                 if (_colours == null || _colours.length != inNumPoints)
32                 {
33                         // Array needs to be created or resized
34                         if (inNumPoints > 0) {
35                                 _colours = new Color[inNumPoints];
36                         }
37                         else {
38                                 _colours = null;
39                         }
40                 }
41         }
42
43         /**
44          * Set the colour at the given index
45          * @param inPointIndex point index
46          * @param inColour colour to use, or null
47          */
48         protected void setColour(int inPointIndex, Color inColour)
49         {
50                 if (_colours != null && _colours.length > inPointIndex && inPointIndex >= 0)
51                 {
52                         _colours[inPointIndex] = inColour;
53                 }
54         }
55
56         /**
57          * Get the colour for the given point index
58          * @param inPointIndex index of point in track
59          * @return colour object
60          */
61         public Color getColour(int inPointIndex)
62         {
63                 Color colour = null;
64                 if (_colours != null && _colours.length > inPointIndex && inPointIndex >= 0)
65                 {
66                         colour = _colours[inPointIndex];
67                 }
68                 if (colour == null) {
69                         // not found, use default
70                         colour = super.getDefaultColour();
71                 }
72                 return colour;
73         }
74 }