FixedColor.java

  1. package org.opentrafficsim.animation.colorer;

  2. import java.awt.Color;
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.List;

  6. import org.opentrafficsim.animation.gtu.colorer.GtuColorer;
  7. import org.opentrafficsim.core.gtu.Gtu;

  8. /**
  9.  * Fixed color colorer.
  10.  * <p>
  11.  * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  12.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  13.  * </p>
  14.  * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
  15.  * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a>
  16.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  17.  */
  18. public class FixedColor implements GtuColorer, Serializable
  19. {

  20.     /** */
  21.     private static final long serialVersionUID = 20180117L;

  22.     /** The color. */
  23.     private final Color color;

  24.     /** Color name. */
  25.     private final String name;

  26.     /**
  27.      * Constructor.
  28.      * @param color Color; the color
  29.      * @param name String; color name
  30.      */
  31.     public FixedColor(final Color color, final String name)
  32.     {
  33.         this.color = color;
  34.         this.name = name;
  35.     }

  36.     /**
  37.      * Constructor.
  38.      * @param color Color; the color
  39.      */
  40.     public FixedColor(final Color color)
  41.     {
  42.         this(color, "Fixed color");
  43.     }

  44.     /** {@inheritDoc} */
  45.     @Override
  46.     public Color getColor(final Gtu gtu)
  47.     {
  48.         return this.color;
  49.     }

  50.     /** {@inheritDoc} */
  51.     @Override
  52.     public List<LegendEntry> getLegend()
  53.     {
  54.         return new ArrayList<>();
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public String toString()
  59.     {
  60.         return this.name;
  61.     }

  62. }