Class FixedColorMap
java.lang.Object
microsim.gui.colormap.FixedColorMap
- All Implemented Interfaces:
ColorMap
- Direct Known Subclasses:
DoubleRangeColorMap, RangeColorMap, TripleRangeColorMap
An object used to map integer values to colors.
It is used by
Layered<Type>Drawer to draw objects of the
LayeredSurfaceFrame.
Title: JAS
Description: Java Agent-based Simulation library
Copyright (C) 2002 Michele Sonnessa
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.- Author:
- Michele Sonnessa
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a color map.FixedColorMap(int colors) Create a color map with an initial capacity of mapping positions. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddColor(int value, int red, int green, int blue) Add a color to the map.voidAdd a color to the map.getColor(int index) Return the color to at the given index position.int[]getColorComponents(int index) Return the components of the color stored at given index.intgetColorIndex(double value) Return the color index.intgetColorIndex(int value) Return the color index.getMappedColor(int value) Map the given value with the right color.Color[]toArray()Return the color list.
-
Field Details
-
colorList
-
colorComponents
protected int[][] colorComponents -
colors
protected int colors -
mapper
-
-
Constructor Details
-
FixedColorMap
public FixedColorMap()Create a color map. -
FixedColorMap
public FixedColorMap(int colors) Create a color map with an initial capacity of mapping positions.- Parameters:
colors- The number of colors to be mapped. Must be a non-zero positive.
-
-
Method Details
-
addColor
Add a color to the map.- Parameters:
value- The integer value that maps to the given color.color- The color to be mapped.- Throws:
ArrayIndexOutOfBoundsException- If value is greather than the defined mapped colors.
-
addColor
public void addColor(int value, int red, int green, int blue) Add a color to the map.- Parameters:
value- The integer value that maps to the given color.red- The red component of the color to be mapped. [0-255] range accepted.green- The green component of the color to be mapped. [0-255] range accepted.blue- The blue component of the color to be mapped. [0-255] range accepted.- Throws:
ArrayIndexOutOfBoundsException- If one of the three color components is out of (0, 255) range.
-
getColor
Return the color to at the given index position.- Parameters:
index- The value to be mapped.- Returns:
- The color corresponding to the value.
-
toArray
Return the color list.- Returns:
- An array of Color. The index represent the mapping value.
-
getColorComponents
public int[] getColorComponents(int index) Description copied from interface:ColorMapReturn the components of the color stored at given index.- Specified by:
getColorComponentsin interfaceColorMap- Parameters:
index- The index of the color. It is a 0-based index of the color corresponding to the adding order.- Returns:
- An array of 3 integers representing the RGB components of the color.
-
getColorIndex
public int getColorIndex(int value) Return the color index.- Specified by:
getColorIndexin interfaceColorMap- Parameters:
value- The value to be mapped.- Returns:
- The index of the color list mapping the value.
-
getColorIndex
public int getColorIndex(double value) Return the color index.- Specified by:
getColorIndexin interfaceColorMap- Parameters:
value- The value to be mapped.- Returns:
- The index of the color list mapping the value.
-
getMappedColor
Map the given value with the right color.- Parameters:
value- The value to be mapped.- Returns:
- The color corresponding to the value.
-