Package sim.util.gui

Class CompositeColorMap

java.lang.Object
sim.util.gui.CompositeColorMap
All Implemented Interfaces:
ColorMap

public class CompositeColorMap extends Object implements ColorMap
CompositeColorMap is a ColorMap which consists of an array of ColorMaps. In response to a color request, it queries each of the maps in turn until one of them indicates that the value is a valid level, at which point it gets the color from that map. If none of them think the value is valid, then the default value (and color) is used from the final map.

This is a simple way of defining multiple gradients from different colors in the same space (such as red->green->blue->white->black)

  • Constructor Details

    • CompositeColorMap

      public CompositeColorMap(ColorMap map1, ColorMap map2)
      Builds a CompositeColorMap with two subsidiary maps
    • CompositeColorMap

      public CompositeColorMap(ColorMap map1, ColorMap map2, ColorMap map3)
      Builds a CompositeColorMap with three subsidiary maps
    • CompositeColorMap

      public CompositeColorMap(ColorMap map1, ColorMap map2, ColorMap map3, ColorMap map4)
      Builds a CompositeColorMap with four subsidiary maps
    • CompositeColorMap

      public CompositeColorMap(ColorMap[] maps)
      Builds a CompositeColorMap with an arbitrary number (> 0) of subsidiary maps
  • Method Details

    • getColor

      public Color getColor(double level)
      Description copied from interface: ColorMap
      Returns a color for the given level
      Specified by:
      getColor in interface ColorMap
    • getRGB

      public int getRGB(double level)
      Description copied from interface: ColorMap
      Returns the RGB values, plus alpha, for a color for the given level. The byte ordering should be in the same fashion that Color.getRGB() is provided. This could be simply written as

      invalid input: '<'code return getColor(level).getRGB() ... however it's likely that this method could be written more efficiently than this.

      Why isn't this called getRGBA(...)? Because for some reason the underlying Color method is likewise getRGB(), even though it ought to be called getRGBA().

      Specified by:
      getRGB in interface ColorMap
    • getAlpha

      public int getAlpha(double level)
      Description copied from interface: ColorMap
      Returns the alpha value for a color for the given level. This could be simply written as

      return getRGB(level) >>> 24 ;

      ...or it could be written as:

      return getColor(level).getAlpha()

      ...however it's likely that it this method could be written more efficiently than either of these.

      Specified by:
      getAlpha in interface ColorMap
    • validLevel

      public boolean validLevel(double level)
      Description copied from interface: ColorMap
      Returns true if a level is "valid" (it provides a meaningful color)
      Specified by:
      validLevel in interface ColorMap
    • defaultValue

      public double defaultValue()
      Description copied from interface: ColorMap
      Returns some level which is valid (that is, validLevel(defaultValue()) should always return true). This is commonly provided to give the user a level to replace an "invalid" level he's typed in.
      Specified by:
      defaultValue in interface ColorMap