Class ColorScaleModel

java.lang.Object
cnuphys.magfield.ColorScaleModel

public class ColorScaleModel extends Object
  • Field Details

    • colors

      protected Color[] colors
      The array of colors
    • values

      protected double[] values
      The array of values
  • Constructor Details

    • ColorScaleModel

      public ColorScaleModel(double[] values, Color[] colors)
      This creates a ColorScaleModel for converting a value into a color. The values array should be sorted in ascending order. In any rate, it will be. Ideally, there is one more entry in the values array, so that each color fits in the space between 2 values. However, this is not a requirement. It will still give sensible results. Also, the value array is NOT assumed to be equally spaced.
      Parameters:
      values - the array of values.
      colors - the array of colors.
    • ColorScaleModel

      public ColorScaleModel(String comment, double[] values, Color[] colors)
      This creates a ColorScaleModel for converting a value into a color. The values array should be sorted in ascending order. In any rate, it will be. Ideally, there is one more entry in the values array, so that each color fits in the space between 2 values. However, this is not a requirement. It will still give sensible results. Also, the value array is NOT assumed to be equally spaced.
      Parameters:
      comment - an extra comment.
      values - the array of values.
      colors - the array of colors.
    • ColorScaleModel

      public ColorScaleModel(String comment, double[] values, Color[] colors, int precision, int numberOfRows)
      This creates a ColorScaleModel for converting a value into a color. The values array should be sorted in ascending order. In any rate, it will be. Ideally, there is one more entry in the values array, so that each color fits in the space between 2 values. However, this is not a requirement. It will still give sensible results. Also, the value array is NOT assumed to be equally spaced.
      Parameters:
      comment - an extra comment.
      values - the array of values.
      colors - the array of colors.
      precision - the number of decimals to display. Use 0 for integers.
      numberOfRows - the number of rows to us displaying the colors.
  • Method Details

    • getColor

      public Color getColor(double value)
      Given a value, returns the corresponding color. Example:

      values: {0, 2, 4, 6, 8}

      colors: {R, G, B, Y}

      then

      value = 1.77 -> R

      value = -1 -> tooSmallColor

      value = 8.01 -> tooBigColor

      value = 4 (exactly) -> G

      Parameters:
      value - the for which we want the color.
      Returns:
      the color corresponding to the value.
    • getColor

      public Color getColor(double value, boolean useColorInterpolation)
      Given a value, returns the corresponding color. Example:

      values: {0, 2, 4, 6, 8}

      colors: {R, G, B, Y}

      then

      value = 1.77 -> R

      value = -1 -> tooSmallColor

      value = 8.01 -> tooBigColor

      value = 4 (exactly) -> G

      Parameters:
      value - the for which we want the color.
      useColorInterpolation - if true, use color interpolation.
      Returns:
      the color corresponding to the value.
    • getMinValue

      public double getMinValue()
      Get the minimum value of the values array.
      Returns:
      the minimum value of the values array.
    • getMaxValue

      public double getMaxValue()
      Get the maximum value of the values array.
      Returns:
      the maximum value of the values array.
    • getColors

      public Color[] getColors()
      Get the color array.
      Returns:
      the color array.
    • getTooBigColor

      public Color getTooBigColor()
      Get the too-big color.
      Returns:
      the color used for a "too big" value.
    • getTooSmallColor

      public Color getTooSmallColor()
      Get the too-small color.
      Returns:
      the color used for a "too small" value.
    • getValues

      public double[] getValues()
      Get the values array.
      Returns:
      the values array.
    • getComment

      public String getComment()
      Get the comment of the color scale.
      Returns:
      the color scale comment.
    • getPrecision

      public int getPrecision()
      Get the precision used for display.
      Returns:
      the precision used for display.
    • getNumberOfRows

      public int getNumberOfRows()
      Returns:
      the numberOfRows
    • setTooSmallColor

      public void setTooSmallColor(Color tooSmallColor)
      Parameters:
      tooSmallColor - the tooSmallColor to set
    • setTooBigColor

      public void setTooBigColor(Color tooBigColor)
      Parameters:
      tooBigColor - the tooBigColor to set