View Javadoc
1   package org.opentrafficsim.core.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   
9   /**
10   * Color GTUs based on their id. If the id ends on one or more digits, the value that those digits constitute is used.
11   * Otherwise, the hash code of the string representation of the id is used.
12   * <p>
13   * Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15   * <p>
16   * @version $Revision: 3569 $, $LastChangedDate: 2017-04-28 03:35:59 +0200 (Fri, 28 Apr 2017) $, by $Author: averbraeck $,
17   *          initial version 28 mei 2015 <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   */
21  public class IDGTUColorer implements GTUColorer
22  {
23      /** The legend. */
24      public static final ArrayList<LegendEntry> LEGEND;
25  
26      /**
27       * Construct a new IDGTUColorer.
28       */
29      static
30      {
31          LEGEND = new ArrayList<LegendEntry>();
32          LEGEND.add(new LegendEntry(Color.BLACK, "black", "black"));
33          LEGEND.add(new LegendEntry(new Color(0xa5, 0x2a, 0x2a), "brown", "brown"));
34          LEGEND.add(new LegendEntry(Color.RED, "red", "red"));
35          LEGEND.add(new LegendEntry(Color.ORANGE, "orange", "orange"));
36          LEGEND.add(new LegendEntry(Color.YELLOW, "yellow", "yellow"));
37          LEGEND.add(new LegendEntry(Color.GREEN, "green", "green"));
38          LEGEND.add(new LegendEntry(Color.BLUE, "blue", "blue"));
39          LEGEND.add(new LegendEntry(Color.MAGENTA, "magenta", "magenta"));
40          LEGEND.add(new LegendEntry(Color.GRAY, "gray", "gray"));
41          LEGEND.add(new LegendEntry(Color.WHITE, "white", "white"));
42      }
43  
44      /** {@inheritDoc} */
45      @Override
46      public final Color getColor(final GTU gtu)
47      {
48          return gtu.getBaseColor();
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public final List<LegendEntry> getLegend()
54      {
55          return LEGEND;
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public final String toString()
61      {
62          return "ID";
63      }
64  
65  }