View Javadoc
1   package org.opentrafficsim.road.gtu.colorer;
2   
3   import java.awt.Color;
4   import java.io.Serializable;
5   import java.util.ArrayList;
6   import java.util.List;
7   
8   import org.opentrafficsim.core.animation.gtu.colorer.GTUColorer;
9   import org.opentrafficsim.core.gtu.GTU;
10  import org.opentrafficsim.road.gtu.lane.tactical.Synchronizable;
11  
12  /**
13   * Color based on synchronization state.
14   * <p>
15   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 23 feb. 2018 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
21   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
22   */
23  public class SynchronizationColorer implements GTUColorer, Serializable
24  {
25  
26      /** */
27      private static final long serialVersionUID = 20180223L;
28  
29      /** The legend. */
30      private static final List<LegendEntry> LEGEND;
31  
32      /** Left color. */
33      private static final Color C_NONE = Color.WHITE;
34  
35      /** No-left color. */
36      private static final Color C_SYNCHRONIZING = Color.ORANGE;
37  
38      /** Right color. */
39      private static final Color C_INDICATING = Color.RED;
40  
41      /** None color. */
42      private static final Color C_COOPERATING = new Color(0, 128, 0);
43  
44      /** N/A color. */
45      protected static final Color NA = Color.YELLOW;
46  
47      static
48      {
49          LEGEND = new ArrayList<>(6);
50          LEGEND.add(new LegendEntry(C_NONE, "None", "None"));
51          LEGEND.add(new LegendEntry(C_SYNCHRONIZING, "Synchronizing", "Synchonizing"));
52          LEGEND.add(new LegendEntry(C_INDICATING, "Indicating", "Indicating"));
53          LEGEND.add(new LegendEntry(C_COOPERATING, "Cooperating", "Cooperating"));
54          LEGEND.add(new LegendEntry(NA, "N/A", "N/A"));
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public Color getColor(final GTU gtu)
60      {
61          if (!(gtu.getTacticalPlanner() instanceof Synchronizable))
62          {
63              return NA;
64          }
65          Synchronizable.State state = ((Synchronizable) gtu.getTacticalPlanner()).getSynchronizationState();
66          if (state == null)
67          {
68              return NA;
69          }
70          switch (state)
71          {
72              case NONE:
73                  return C_NONE;
74              case COOPERATING:
75                  return C_COOPERATING;
76              case INDICATING:
77                  return C_INDICATING;
78              case SYNCHRONIZING:
79                  return C_SYNCHRONIZING;
80              default:
81                  return NA;
82          }
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public List<LegendEntry> getLegend()
88      {
89          return LEGEND;
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public final String toString()
95      {
96          return "Sycnhronization";
97      }
98  
99  }