Class ColorScale


  • public final class ColorScale
    extends Object
    Utility class that helps to work with color scale for coloring GPX tracks etc.
    Since:
    7319
    • Method Detail

      • createFixedScale

        public static ColorScale createFixedScale​(Color[] colors)
        Gets a fixed color range.
        Parameters:
        colors - the fixed colors list
        Returns:
        The scale
        Since:
        15247
      • createHSBScale

        public static ColorScale createHSBScale​(int count)
        Gets a HSB color range.
        Parameters:
        count - The number of colors the scale should have
        Returns:
        The scale
      • createCyclicScale

        public static ColorScale createCyclicScale​(int count)
        Creates a cyclic color scale (red yellow green blue red)
        Parameters:
        count - The number of colors the scale should have
        Returns:
        The scale
      • weighted

        private static float weighted​(float x)
        transition function: w(0)=1, w(1)=0, 0<=w(x)<=1
        Parameters:
        x - number: 0<=x<=1
        Returns:
        the weighted value
      • setRange

        public void setRange​(double min,
                             double max)
        Sets the hint on the range this scale is for
        Parameters:
        min - The minimum value
        max - The maximum value
      • addBounds

        public void addBounds()
        Add standard colors for values below min or above max value
      • getColor

        public Color getColor​(double value)
        Gets a color for the given value.
        Parameters:
        value - The value
        Returns:
        The color for this value, this may be a special color if the value is outside the range but never null.
      • getColor

        public Color getColor​(Number value)
        Gets a color for the given value.
        Parameters:
        value - The value, may be null
        Returns:
        The color for this value, this may be a special color if the value is outside the range or the value is null but never null.
      • getNoDataColor

        public Color getNoDataColor()
        Get the color to use if there is no data
        Returns:
        The color
      • setNoDataColor

        public void setNoDataColor​(Color noDataColor)
        Sets the color to use if there is no data
        Parameters:
        noDataColor - The color
      • makeTransparent

        public ColorScale makeTransparent​(int alpha)
        Make all colors transparent
        Parameters:
        alpha - The alpha value all colors in the range should have, range 0..255
        Returns:
        This scale, for chaining
      • addTitle

        public ColorScale addTitle​(String title)
        Adds a title to this scale
        Parameters:
        title - The new title
        Returns:
        This scale, for chaining
      • setIntervalCount

        public ColorScale setIntervalCount​(int intervalCount)
        Sets the interval count for this scale
        Parameters:
        intervalCount - The interval count hint
        Returns:
        This scale, for chaining
      • drawColorBar

        public void drawColorBar​(Graphics2D g,
                                 int x,
                                 int y,
                                 int w,
                                 int h,
                                 double valueScale)
        Draws a color bar representing this scale on the given graphics
        Parameters:
        g - The graphics to draw on
        x - Rect x
        y - Rect y
        w - Rect width
        h - Rect height
        valueScale - The scale factor of the values