IncentiveColorer.java

  1. package org.opentrafficsim.road.gtu.animation;

  2. import java.awt.Color;

  3. import org.opentrafficsim.core.gtu.GTU;
  4. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Desire;
  5. import org.opentrafficsim.road.gtu.lane.tactical.util.lmrs.Incentive;

  6. /**
  7.  * Colorer for desire from a specific incentive.
  8.  * <p>
  9.  * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  10.  * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
  11.  * <p>
  12.  * @version $Revision$, $LastChangedDate$, by $Author$, initial version 14 apr. 2017 <br>
  13.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  14.  * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
  15.  * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
  16.  */
  17. public class IncentiveColorer extends DesireColorer
  18. {

  19.     /** */
  20.     private static final long serialVersionUID = 20170414L;

  21.     /** Incentive class. */
  22.     private Class<? extends Incentive> incentiveClass;

  23.     /**
  24.      * @param incentiveClass incentive class
  25.      */
  26.     public IncentiveColorer(final Class<? extends Incentive> incentiveClass)
  27.     {
  28.         this.incentiveClass = incentiveClass;
  29.     }

  30.     /** {@inheritDoc} */
  31.     @Override
  32.     public final Color getColor(final GTU gtu)
  33.     {
  34.         if (!(gtu.getTacticalPlanner() instanceof DesireBased))
  35.         {
  36.             return NA;
  37.         }
  38.         Desire d = ((DesireBased) gtu.getTacticalPlanner()).getLatestDesire(this.incentiveClass);
  39.         if (d != null)
  40.         {
  41.             return getColor(d.getLeft(), d.getRight());
  42.         }
  43.         return NA;
  44.     }

  45.     /** {@inheritDoc} */
  46.     @Override
  47.     public final String toString()
  48.     {
  49.         return this.incentiveClass.getSimpleName();
  50.     }

  51. }