SynchronizationColorer.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. import org.opentrafficsim.road.gtu.lane.tactical.Synchronizable;

  9. /**
  10.  * Color based on synchronization state.
  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://github.com/peter-knoppers">Peter Knoppers</a>
  17.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  18.  */
  19. public class SynchronizationColorer implements GtuColorer, Serializable
  20. {

  21.     /** */
  22.     private static final long serialVersionUID = 20180223L;

  23.     /** The legend. */
  24.     private static final List<LegendEntry> LEGEND;

  25.     /** Left color. */
  26.     private static final Color C_NONE = Color.WHITE;

  27.     /** No-left color. */
  28.     private static final Color C_SYNCHRONIZING = Color.ORANGE;

  29.     /** Right color. */
  30.     private static final Color C_INDICATING = Color.RED;

  31.     /** None color. */
  32.     private static final Color C_COOPERATING = new Color(0, 128, 0);

  33.     /** N/A color. */
  34.     protected static final Color NA = Color.YELLOW;

  35.     static
  36.     {
  37.         LEGEND = new ArrayList<>(6);
  38.         LEGEND.add(new LegendEntry(C_NONE, "None", "None"));
  39.         LEGEND.add(new LegendEntry(C_SYNCHRONIZING, "Synchronizing", "Synchonizing"));
  40.         LEGEND.add(new LegendEntry(C_INDICATING, "Indicating", "Indicating"));
  41.         LEGEND.add(new LegendEntry(C_COOPERATING, "Cooperating", "Cooperating"));
  42.         LEGEND.add(new LegendEntry(NA, "N/A", "N/A"));
  43.     }

  44.     @Override
  45.     public Color getColor(final Gtu gtu)
  46.     {
  47.         if (!(gtu.getTacticalPlanner() instanceof Synchronizable))
  48.         {
  49.             return NA;
  50.         }
  51.         Synchronizable.State state = ((Synchronizable) gtu.getTacticalPlanner()).getSynchronizationState();
  52.         if (state == null)
  53.         {
  54.             return NA;
  55.         }
  56.         switch (state)
  57.         {
  58.             case NONE:
  59.                 return C_NONE;
  60.             case COOPERATING:
  61.                 return C_COOPERATING;
  62.             case INDICATING:
  63.                 return C_INDICATING;
  64.             case SYNCHRONIZING:
  65.                 return C_SYNCHRONIZING;
  66.             default:
  67.                 return NA;
  68.         }
  69.     }

  70.     @Override
  71.     public List<LegendEntry> getLegend()
  72.     {
  73.         return LEGEND;
  74.     }

  75.     @Override
  76.     public final String getName()
  77.     {
  78.         return "Synchronization";
  79.     }

  80. }