View Javadoc
1   package org.opentrafficsim.animation.data;
2   
3   import java.awt.Color;
4   
5   import org.opentrafficsim.draw.road.TrafficLightAnimation.TrafficLightData;
6   import org.opentrafficsim.road.network.lane.object.trafficlight.TrafficLight;
7   
8   /**
9    * Animation data of a TrafficLight.
10   * <p>
11   * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
12   * <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/wjschakel">Wouter Schakel</a>
16   */
17  public class AnimationTrafficLightData extends AnimationLaneBasedObjectData<TrafficLight> implements TrafficLightData
18  {
19      
20      /**
21       * Constructor.
22       * @param trafficLight TrafficLight; traffic light.
23       */
24      public AnimationTrafficLightData(final TrafficLight trafficLight)
25      {
26          super(trafficLight);
27      }
28  
29      /** {@inheritDoc} */
30      @Override
31      public Color getColor()
32      {
33          switch (getObject().getTrafficLightColor())
34          {
35              case RED:
36              {
37                  return Color.RED;
38              }
39              case GREEN:
40              case PREGREEN:
41              {
42                  return Color.GREEN;
43              }
44              case YELLOW:
45              {
46                  return Color.YELLOW;
47              }
48              default:
49              {
50                  return Color.BLACK;
51              }
52          }
53      }
54      
55      /** {@inheritDoc} */
56      @Override
57      public String toString()
58      {
59          return "Traffic light " + getObject().getFullId();
60      }
61      
62  }