Class SwitchableGTUColorer

java.lang.Object
org.opentrafficsim.core.animation.gtu.colorer.SwitchableGTUColorer
All Implemented Interfaces:
Serializable, Colorer<GTU>, GTUColorer
Direct Known Subclasses:
DefaultSwitchableGTUColorer, LmrsSwitchableColorer

public class SwitchableGTUColorer
extends Object
implements GTUColorer, Serializable
GTU colorer that uses a coloring method that can be switched by the user of the program.

Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Version:
$Revision: 4742 $, $LastChangedDate: 2018-11-18 20:48:30 +0100 (Sun, 18 Nov 2018) $, by $Author: averbraeck $, initial version 28 mei 2015
Author:
Alexander Verbraeck, Peter Knoppers
See Also:
Serialized Form
  • Constructor Details

    • SwitchableGTUColorer

      public SwitchableGTUColorer​(int activeIndex, GTUColorer... colorers) throws IndexOutOfBoundsException
      Construct a new Switchable GTUColorer based on a list of colorers.
      Parameters:
      activeIndex - int; the index of the initially active colorer in the list (0-based).
      colorers - GTUColorer...; the list of GTUColorer. List cannot be empty.
      Throws:
      IndexOutOfBoundsException - when activeIndex < 0 or larger than or equal to the number of colorers.
  • Method Details

    • setGTUColorer

      public final void setGTUColorer​(int activeIndex) throws IndexOutOfBoundsException
      Replace the currently active GTUColorer.
      Parameters:
      activeIndex - int; the index of the new active colorer in the list (0-based).
      Throws:
      IndexOutOfBoundsException - when activeIndex < 0 or larger than or equal to the number of colorers.
    • getColor

      public final Color getColor​(GTU gtu)
      Get the color, based on the Drawable object.
      Specified by:
      getColor in interface Colorer<GTU>
      Parameters:
      gtu - D; the object to determine the color for
      Returns:
      the (fill, line) color of the drawable object
    • getLegend

      public final List<GTUColorer.LegendEntry> getLegend()
      Return a list of legend entries (useful to make a legend of the colors used to render the GTUs).
      Specified by:
      getLegend in interface GTUColorer
      Returns:
      List<LegendEntry>; the list of legend entries; the caller should not (try to) modify this List
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • getColorers

      public final List<GTUColorer> getColorers()
      Returns:
      the list of colorers.
    • builder

      public static final SwitchableGTUColorer.Builder builder()
      Returns a builder for SwitchableGTUColorer.
      Returns:
      Builder; builder for SwitchableGTUColorer