Class TLcdColorMap
- All Implemented Interfaces:
Cloneable
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
- ]-inf, 100] - Black
- ]100,200[ - Something between Black and Green
- 200 - Green
- ]200,300[ - Something between Green and Blue
- [300, +inf[ - Blue
- 100, 200, 300
- Black, Green, Blue, Red
- ]-inf, 100[ - Black
- [100, 200[ - Green
- [200, 300[ - Blue
- [300, +inf[ - Red
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
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, ...
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe LevelInclusion determines how the levels are interpreted when retrieving values usingretrieveColor(double). -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newTLcdColorMap.TLcdColorMap(ILcdInterval aLevelInterval, double[] aLevels, Color[] aColors) Constructs a newTLcdColorMapwith the given levels and colors. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPropertyChangeListener(PropertyChangeListener aPropertyChangeListener) Add the givenPropertyChangeListener.clone()booleangetColor(int aIndex) Returns the color at the given index.intReturns the amount of colors.doublegetLevel(int aIndex) Returns the level at the given index.intReturns the amount of levels.Gets how the levels are interpreted when retrieving values usingretrieveColor(double).Returns the level interval.intReturns the master opacity.inthashCode()voidinsertColor(int aIndex, Color aColor) Inserts the color at the given index.voidinsertLevel(int aIndex, double aLevel) Inserts the level at the given index.booleanReturns true if the level count and color count are equal, false otherwise.booleanDeprecated.This method has been deprecated.voidRemoves all colors and levels.voidremoveColor(int aIndex) Removes the color at the given index.voidremoveLevel(int aIndex) Removes the level at the given index.voidremovePropertyChangeListener(PropertyChangeListener aPropertyChangeListener) Removes the givenPropertyChangeListener.retrieveColor(double aLevel) Retrieves the color at the given level.static voidsetClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated.voidSets the color at the given index.voidsetLevel(int aIndex, double aLevel) Sets the level at the given index.voidsetLevelInclusion(TLcdColorMap.LevelInclusion aLevelInclusion) Sets how the levels are interpreted when retrieving values usingretrieveColor(double).voidsetLevelInterval(ILcdInterval aLevelInterval) Sets the new level interval: the minimum and maximum values for the levels.voidsetMasterOpacity(int aMasterOpacity) Sets the master opacity.voidsetTraceOn(boolean aTraceOn) Deprecated.This method has been deprecated.toString()
-
Constructor Details
-
TLcdColorMap
public TLcdColorMap()Creates a newTLcdColorMap. The color map is initialized with an interval [0, 10000], one level and two colors.- See Also:
-
TLcdColorMap
Constructs a newTLcdColorMapwith 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 nullIllegalArgumentException- 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 istruethen 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 eithertrueorfalseas argument automatically turns off tracing for all other class instances for whichsetTraceOnhas not been called. If the argument isfalsethen 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.Returnstrueif tracing is enabled for this class.- Returns:
- true if tracing is enabled for this class, false otherwise.
-
addPropertyChangeListener
Add the givenPropertyChangeListener.- Parameters:
aPropertyChangeListener- The listener to be added.- See Also:
-
removePropertyChangeListener
Removes the givenPropertyChangeListener. 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. SeesetMasterOpacity(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
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
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
Returns the level interval.- Returns:
- the level interval.
- See Also:
-
setLevelInterval
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 thegetLevelInterval().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
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
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
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
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. Themaster opacityandlevel inclusionsettings 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
-
equals
-
hashCode
public int hashCode() -
toString
-