View Javadoc
1   package org.opentrafficsim.road.gtu.animation;
2   
3   import java.awt.Color;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import org.opentrafficsim.core.gtu.GTU;
8   import org.opentrafficsim.core.gtu.animation.GTUColorer;
9   import org.opentrafficsim.core.gtu.plan.tactical.TacticalPlanner;
10  
11  /**
12   * Displays whether a GTU is blocking conflicts.
13   * <p>
14   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version $Revision$, $LastChangedDate$, by $Author$, initial version 7 sep. 2018 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
21   */
22  
23  public class BlockingColorer implements GTUColorer
24  {
25  
26      /** Blocking color. */
27      private static final Color BLOCKING = Color.RED;
28  
29      /** Not blocking color. */
30      private static final Color NOT_BLOCKING = Color.WHITE;
31  
32      /** Legend. */
33      private static final List<LegendEntry> LEGEND = new ArrayList<>();
34  
35      static
36      {
37          LEGEND.add(new LegendEntry(Color.RED, "Not blocking", "Not blocking"));
38          LEGEND.add(new LegendEntry(Color.WHITE, "Blocking", "Blocking"));
39      }
40  
41      /** {@inheritDoc} */
42      @Override
43      public List<LegendEntry> getLegend()
44      {
45          return LEGEND;
46      }
47  
48      /** {@inheritDoc} */
49      @Override
50      public Color getColor(final GTU gtu)
51      {
52          TacticalPlanner<?, ?> tact = gtu.getTacticalPlanner();
53          if (tact instanceof Blockable && ((Blockable) tact).isBlocking())
54          {
55              return BLOCKING;
56          }
57          return NOT_BLOCKING;
58      }
59      
60      /** {@inheritDoc} */
61      @Override
62      public String toString()
63      {
64          return "Blocking";
65      }
66  
67  }