Class ColorScaleModel

java.lang.Object
cnuphys.magfield.ColorScaleModel

public class ColorScaleModel extends Object
  • Field Details Link icon

    • colors Link icon

      protected Color[] colors
      The array of colors
    • values Link icon

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

    • ColorScaleModel Link icon

      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 Link icon

      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 Link icon

      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 Link icon

    • getColor Link icon

      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 Link icon

      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 Link icon

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

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

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

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

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

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

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

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

      public int getNumberOfRows()
      Returns:
      the numberOfRows
    • setTooSmallColor Link icon

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

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