Package sim.util.gui

Class AbstractColorMap

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

public abstract class AbstractColorMap extends Object implements ColorMap
AbstractColorMap is a ColorMap with all methods implemented except for getColor(...). The validLevel(...) method is implemented to always return true, and thus the defaultValue() method is implemented to return an arbitrary default level (set to 0).

This class is intended to make it easy to implement a ColorMap which responds to any numerical value to provide a Color: you only need to implement the obvious method, getColor(...). However it's not particularly efficient, since the other methods call getColor(...), then extract the RGBA values out of the

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns some level which is valid (that is, validLevel(defaultValue()) should always return true).
    int
    getAlpha(double level)
    Returns the alpha value for a color for the given level.
    abstract Color
    getColor(double level)
    Returns a color for the given level
    int
    getRGB(double level)
    Returns the RGB values, plus alpha, for a color for the given level.
    boolean
    validLevel(double level)
    Returns true if a level is "valid" (it provides a meaningful color)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractColorMap

      public AbstractColorMap()
  • Method Details

    • getColor

      public abstract 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