Class FixedColorMap

  • All Implemented Interfaces:
    ColorMap
    Direct Known Subclasses:
    DoubleRangeColorMap, RangeColorMap, TripleRangeColorMap

    public class FixedColorMap
    extends java.lang.Object
    implements ColorMap
    An object used to map integer values to colors. It is used by LayeredDrawer 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

    • Constructor Summary

      Constructors 
      Constructor Description
      FixedColorMap()
      Create a color map.
      FixedColorMap​(int colors)
      Create a color map with an initial capacity of mapping positions.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addColor​(int value, int red, int green, int blue)
      Add a color to the map.
      void addColor​(int value, java.awt.Color color)
      Add a color to the map.
      java.awt.Color 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.
      int getColorIndex​(double value)
      Return the color index.
      int getColorIndex​(int value)
      Return the color index.
      java.awt.Color getMappedColor​(int value)
      Map the given value with the right color.
      java.awt.Color[] toArray()
      Return the color list.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • 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 Detail

      • addColor

        public void addColor​(int value,
                             java.awt.Color color)
        Add a color to the map.
        Parameters:
        value - The integer value that maps to the given color.
        color - The color to be mapped.
      • 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.
      • getColor

        public java.awt.Color getColor​(int index)
        Return the color to at the given index position.
        Parameters:
        index - The value to be mapped.
        Returns:
        The color corresponding to the value.
      • toArray

        public java.awt.Color[] 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: ColorMap
        Return the components of the color stored at given index.
        Specified by:
        getColorComponents in interface ColorMap
        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:
        getColorIndex in interface ColorMap
        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:
        getColorIndex in interface ColorMap
        Parameters:
        value - The value to be mapped.
        Returns:
        The index of the color list mapping the value.
      • getMappedColor

        public java.awt.Color getMappedColor​(int value)
        Map the given value with the right color.
        Parameters:
        index - The value to be mapped.
        Returns:
        The color corresponding to the value.