BlockingColorer.java

  1. package org.opentrafficsim.animation.colorer;

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

  5. import org.opentrafficsim.animation.gtu.colorer.GtuColorer;
  6. import org.opentrafficsim.core.gtu.Gtu;
  7. import org.opentrafficsim.core.gtu.plan.tactical.TacticalPlanner;
  8. import org.opentrafficsim.road.gtu.lane.tactical.Blockable;

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

  19. public class BlockingColorer implements GtuColorer
  20. {

  21.     /** Blocking color. */
  22.     private static final Color BLOCKING = Color.RED;

  23.     /** Not blocking color. */
  24.     private static final Color NOT_BLOCKING = Color.WHITE;

  25.     /** Legend. */
  26.     private static final List<LegendEntry> LEGEND = new ArrayList<>();

  27.     static
  28.     {
  29.         LEGEND.add(new LegendEntry(Color.RED, "Not blocking", "Not blocking"));
  30.         LEGEND.add(new LegendEntry(Color.WHITE, "Blocking", "Blocking"));
  31.     }

  32.     /** {@inheritDoc} */
  33.     @Override
  34.     public List<LegendEntry> getLegend()
  35.     {
  36.         return LEGEND;
  37.     }

  38.     /** {@inheritDoc} */
  39.     @Override
  40.     public Color getColor(final Gtu gtu)
  41.     {
  42.         TacticalPlanner<?, ?> tact = gtu.getTacticalPlanner();
  43.         if (tact instanceof Blockable && ((Blockable) tact).isBlocking())
  44.         {
  45.             return BLOCKING;
  46.         }
  47.         return NOT_BLOCKING;
  48.     }

  49.     /** {@inheritDoc} */
  50.     @Override
  51.     public String toString()
  52.     {
  53.         return "Blocking";
  54.     }

  55. }