View Javadoc
1   package org.opentrafficsim.road.gtu.colorer;
2   
3   import java.awt.Color;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import org.opentrafficsim.core.animation.gtu.colorer.GTUColorer;
8   import org.opentrafficsim.core.gtu.GTU;
9   import org.opentrafficsim.core.gtu.plan.tactical.TacticalPlanner;
10  import org.opentrafficsim.road.gtu.lane.tactical.Blockable;
11  
12  /**
13   * Displays whether a GTU is blocking conflicts.
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 7 sep. 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  
24  public class BlockingColorer implements GTUColorer
25  {
26  
27      /** Blocking color. */
28      private static final Color BLOCKING = Color.RED;
29  
30      /** Not blocking color. */
31      private static final Color NOT_BLOCKING = Color.WHITE;
32  
33      /** Legend. */
34      private static final List<LegendEntry> LEGEND = new ArrayList<>();
35  
36      static
37      {
38          LEGEND.add(new LegendEntry(Color.RED, "Not blocking", "Not blocking"));
39          LEGEND.add(new LegendEntry(Color.WHITE, "Blocking", "Blocking"));
40      }
41  
42      /** {@inheritDoc} */
43      @Override
44      public List<LegendEntry> getLegend()
45      {
46          return LEGEND;
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public Color getColor(final GTU gtu)
52      {
53          TacticalPlanner<?, ?> tact = gtu.getTacticalPlanner();
54          if (tact instanceof Blockable && ((Blockable) tact).isBlocking())
55          {
56              return BLOCKING;
57          }
58          return NOT_BLOCKING;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public String toString()
64      {
65          return "Blocking";
66      }
67  
68  }