Class TLcdColorMap

java.lang.Object
com.luciad.util.TLcdColorMap
All Implemented Interfaces:
Cloneable

public class TLcdColorMap extends Object implements Cloneable
This object represents an ordered collection of levels and associated colors. It can for example be used to create raster color models, directly or using a factory. There is a user interface available to edit it.

If the number of levels equals the number of colors, the color map is said to be gradient. An example with 3 levels and 3 colors:

  • 100, 200, 300
  • Black, Green, Blue
which means:
  • ]-inf, 100] - Black
  • ]100,200[ - Something between Black and Green
  • 200 - Green
  • ]200,300[ - Something between Green and Blue
  • [300, +inf[ - Blue
If there is one more color than the number of levels, the color map is said to be not gradient (piecewise constant). An example with 3 levels and 4 colors:
  • 100, 200, 300
  • Black, Green, Blue, Red
which means:
  • ]-inf, 100[ - Black
  • [100, 200[ - Green
  • [200, 300[ - Blue
  • [300, +inf[ - Red
These colors can be retrieved using retrieveColor. This method returns the color at a given level. In case of a gradient color map, it will interpolate the colors (including alpha).

These levels could be anything. For example, an altitude in meters, or a pressure in Pascal.

The object also has a level interval, which is the minimum and maximum allowed level.

For non-gradient color maps, you can specify whether or not to include the end point of each color level. Changing the default TLcdColorMap.LevelInclusion.EXCLUDES_END_POINT to TLcdColorMap.LevelInclusion.INCLUDES_END_POINT would alter the piece-wise constant example above to:

  • ]-inf, 100] - Black
  • ]100, 200] - Green
  • ]200, 300] - Blue
  • ]300, +inf[ - Red
The user of this class is fully responsible to make sure that the levels remain ordered and to make sure that all levels remain within the valid interval. So getLevel(i) <= getLevel(i+1) and getLevelInterval().getMin() <= getLevel(i) <= getLevelInterval().getMax().

Furthermore the user of this class is responsible to maintain the correct color count and level count. So getLevelCount() == getColorCount() or getLevelCount() == (getColorCount() - 1)

This object fires property changes about all changes made to it.

If trace is enabled (e.g. setClassTraceOn(true)), this object will print a warning when retrieveColor is used and the object is in an inconsistent state. E.g. levels not ordered, a color is null, ...

  • Constructor Details

    • TLcdColorMap

      public TLcdColorMap()
      Creates a new TLcdColorMap. The color map is initialized with an interval [0, 10000], one level and two colors.
      See Also:
    • TLcdColorMap

      public TLcdColorMap(ILcdInterval aLevelInterval, double[] aLevels, Color[] aColors)
      Constructs a new TLcdColorMap with the given levels and colors.
      Parameters:
      aLevelInterval - The minimum and maximum allowed level value. The aLevelInterval must not be modified after it is passed to this constructor.
      aLevels - The ordered levels. aLevels[i] <= aLevels[i+1] and aLevelInterval.getMin() <= aLevels[i] <= aLevelInterval.getMax()
      aColors - The associated colors for the levels. aLevels.length == aColors.length or aLevels.length == (aColors.length - 1)
      Throws:
      NullPointerException - If any of the arguments is null
      IllegalArgumentException - If any or the arguments is invalid.
  • Method Details

    • setClassTraceOn

      public static void setClassTraceOn(boolean aClassTraceOn)
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Enables tracing for all instances of this class. If the argument is true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
      Parameters:
      aClassTraceOn - if true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
    • setTraceOn

      public void setTraceOn(boolean aTraceOn)
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Enables tracing for this class instance. Calling this method with either true or false as argument automatically turns off tracing for all other class instances for which setTraceOn has not been called. If the argument is false then only the informative, warning and error log messages are recorded.
      Parameters:
      aTraceOn - if true then all log messages are recorded for this instance. If false, then only the informative, warning and error log messages are recorded.
    • isTraceOn

      public boolean isTraceOn()
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Returns true if tracing is enabled for this class.
      Returns:
      true if tracing is enabled for this class, false otherwise.
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      Add the given PropertyChangeListener.
      Parameters:
      aPropertyChangeListener - The listener to be added.
      See Also:
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      Removes the given PropertyChangeListener. Does nothing if the listener was never added (or already removed).
      Parameters:
      aPropertyChangeListener - The listener to remove.
      See Also:
    • getMasterOpacity

      public int getMasterOpacity()
      Returns the master opacity. See setMasterOpacity(int).
      Returns:
      the master opacity.
    • setMasterOpacity

      public void setMasterOpacity(int aMasterOpacity)
      Sets the master opacity. Every color has its own alpha value, which is then combined with the master opacity. This allows to conveniently change the transparency of all colors at once, without changing the individual alpha values of the colors. Default value is 255.
      Parameters:
      aMasterOpacity - The master opacity, between 0 (fully transparent) and 255 (fully opaque).
      See Also:
    • getLevelInclusion

      public TLcdColorMap.LevelInclusion getLevelInclusion()

      Gets how the levels are interpreted when retrieving values using retrieveColor(double).

      TLcdColorMap.LevelInclusion.EXCLUDES_END_POINT - [100, 200[
      TLcdColorMap.LevelInclusion.INCLUDES_END_POINT - ]100, 200]

      Returns:
      the level inclusion.
      Since:
      2019.1
    • setLevelInclusion

      public void setLevelInclusion(TLcdColorMap.LevelInclusion aLevelInclusion)

      Sets how the levels are interpreted when retrieving values using retrieveColor(double).

      TLcdColorMap.LevelInclusion.EXCLUDES_END_POINT - [100, 200[
      TLcdColorMap.LevelInclusion.INCLUDES_END_POINT - ]100, 200]

      Parameters:
      aLevelInclusion - the level inclusion.
      Since:
      2019.1
    • getLevelInterval

      public ILcdInterval getLevelInterval()
      Returns the level interval.
      Returns:
      the level interval.
      See Also:
    • setLevelInterval

      public void setLevelInterval(ILcdInterval aLevelInterval)
      Sets the new level interval: the minimum and maximum values for the levels.

      This method will fire a property change.

      Parameters:
      aLevelInterval - The new level interval. aLevelInterval.getMin() <= aLevels[i] <= aLevelInterval.getMax() for every i. The aLevelInterval must not be modified after it is passed to this method.
      See Also:
    • getLevelCount

      public int getLevelCount()
      Returns the amount of levels.
      Returns:
      the amount of levels.
    • getLevel

      public double getLevel(int aIndex)
      Returns the level at the given index. Note that the levels are ordered: aLevels[i] <= aLevels[i+1].
      Parameters:
      aIndex - The index for which to retrieve the level.
      Returns:
      the level at the given index.
      See Also:
    • setLevel

      public void setLevel(int aIndex, double aLevel)
      Sets the level at the given index. It is the responsibility of the user of this method to make sure that the levels remain ordered and that they remain within the getLevelInterval().

      This method will fire a "level" property change.

      Parameters:
      aIndex - The index at which to set the level.
      aLevel - The new level. getLevel( aIndex - 1 ) <= aLevel <= getLevel( aIndex + 1 )

      Furthermore getLevelInterval().getMin() <= aLevel <= getLevelInterval().getMax()

      See Also:
    • insertLevel

      public void insertLevel(int aIndex, double aLevel)
      Inserts the level at the given index. It is the responsibility of the user of this method to make sure that the levels remain ordered and to make sure that the correct color count and level count are maintained. So getLevelCount() == getColorCount() or getLevelCount() == (getColorCount() - 1)

      This method will fire a "levelCount" property change.

      Parameters:
      aIndex - The index at which to insert the level. 0 <= aIndex <= getLevelCount(). If aIndex == getLevelCount() the level is inserted at the end.
      aLevel - The level to insert. getLevel( aIndex - 1 ) <= aLevel <= getLevel( aIndex )
      See Also:
    • removeLevel

      public void removeLevel(int aIndex)
      Removes the level at the given index. It is the responsibility of the user of this method to make sure that the correct color count and level count are maintained. So getLevelCount() == getColorCount() or getLevelCount() == (getColorCount() - 1)

      This method will fire a "levelCount" property change.

      Parameters:
      aIndex - The index at which to remove the level.
      See Also:
    • insertColor

      public void insertColor(int aIndex, Color aColor)
      Inserts the color at the given index. It is the responsibility of the user of this method to make sure that the correct color count and level count are maintained. So getLevelCount() == getColorCount() or getLevelCount() == (getColorCount() - 1)

      This method will fire a "colorCount" property change.

      Parameters:
      aIndex - The index at which to insert the color. 0 <= aIndex <= getLevelCount(). If aIndex == getLevelCount() the color is inserted at the end.
      aColor - The color to insert.
      See Also:
    • removeColor

      public void removeColor(int aIndex)
      Removes the color at the given index. It is the responsibility of the user of this method to make sure that the correct color count and level count are maintained. So getLevelCount() == getColorCount() or getLevelCount() == (getColorCount() - 1)

      This method will fire a "colorCount" property change.

      Parameters:
      aIndex - The index at which to remove the level.
      See Also:
    • removeAll

      public void removeAll()
      Removes all colors and levels. This method will fire a null property change to indicate that some set of properties are changed: "colorCount" and "levelCount".
    • getColorCount

      public int getColorCount()
      Returns the amount of colors.
      Returns:
      the amount of colors.
    • getColor

      public Color getColor(int aIndex)
      Returns the color at the given index.
      Parameters:
      aIndex - The index to retrieve the color for.
      Returns:
      the color at the given index.
      See Also:
    • setColor

      public void setColor(int aIndex, Color aColor)
      Sets the color at the given index.

      This method will fire a "color" property change.

      Parameters:
      aIndex - The index to set the color at.
      aColor - The color to set.
      See Also:
    • isGradient

      public boolean isGradient()
      Returns true if the level count and color count are equal, false otherwise.
      Returns:
      true if the level count and color count are equal, false otherwise.
      See Also:
    • retrieveColor

      public Color retrieveColor(double aLevel)
      Retrieves the color at the given level. This method will respect the gradient or piece wise constant mode of this color map. In case the color map is gradient, it will interpolate between the colors (including alpha) to retrieve the color at the given level, otherwise the correct color will be selected. The master opacity and level inclusion settings are also respected.

      Also refer to the class comment.

      Parameters:
      aLevel - The level to retrieve the color for. getLevelInterval.getMin() <= aLevel <= getLevelInterval.getMax()
      Returns:
      the color at the given level.
      See Also:
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object