X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fgui%2Fcolour%2FContinuousPointColourer.java;fp=src%2Ftim%2Fprune%2Fgui%2Fcolour%2FContinuousPointColourer.java;h=64a9583aa8351dda4fcf0c8b3502218963cb1a71;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/gui/colour/ContinuousPointColourer.java b/src/tim/prune/gui/colour/ContinuousPointColourer.java new file mode 100644 index 0000000..64a9583 --- /dev/null +++ b/src/tim/prune/gui/colour/ContinuousPointColourer.java @@ -0,0 +1,74 @@ +package tim.prune.gui.colour; + +import java.awt.Color; + +public abstract class ContinuousPointColourer extends PointColourer +{ + /** array of colours to use */ + private Color[] _colours = null; + + /** + * Constructor + * @param inStartColour start colour + * @param inEndColour end colour + */ + public ContinuousPointColourer(Color inStartColour, Color inEndColour) + { + super(inStartColour, inEndColour); + } + + /** Continuous colourers don't need a maximum count */ + public static boolean isMaxColoursRequired() { + return false; + } + + /** + * Initialise the array to the right size + * @param inNumPoints number of points in the track + */ + protected void init(int inNumPoints) + { + if (_colours == null || _colours.length != inNumPoints) + { + // Array needs to be created or resized + if (inNumPoints > 0) { + _colours = new Color[inNumPoints]; + } + else { + _colours = null; + } + } + } + + /** + * Set the colour at the given index + * @param inPointIndex point index + * @param inColour colour to use, or null + */ + protected void setColour(int inPointIndex, Color inColour) + { + if (_colours != null && _colours.length > inPointIndex && inPointIndex >= 0) + { + _colours[inPointIndex] = inColour; + } + } + + /** + * Get the colour for the given point index + * @param inPointIndex index of point in track + * @return colour object + */ + public Color getColour(int inPointIndex) + { + Color colour = null; + if (_colours != null && _colours.length > inPointIndex && inPointIndex >= 0) + { + colour = _colours[inPointIndex]; + } + if (colour == null) { + // not found, use default + colour = super.getDefaultColour(); + } + return colour; + } +}