View Javadoc
1   package org.opentrafficsim.road.gtu.lane.object.animation;
2   
3   import java.awt.Color;
4   import java.awt.Graphics2D;
5   import java.awt.image.ImageObserver;
6   import java.rmi.RemoteException;
7   
8   import javax.naming.NamingException;
9   
10  import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
11  import nl.tudelft.simulation.language.d3.DirectedPoint;
12  
13  import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
14  import org.opentrafficsim.core.network.animation.PaintPolygons;
15  import org.opentrafficsim.road.gtu.lane.object.AbstractTrafficLightNew;
16  import org.opentrafficsim.road.gtu.lane.object.TrafficLight;
17  
18  /**
19   * Draw a traffic light on the road at th place where the cars are expected to stop.
20   * <p>
21   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
23   * <p>
24   * @version $Revision: 1401 $, $LastChangedDate: 2015-09-14 01:33:02 +0200 (Mon, 14 Sep 2015) $, by $Author: averbraeck $,
25   *          initial version 29 dec. 2014 <br>
26   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
28   */
29  public class TrafficLightAnimation extends Renderable2D
30  {
31      /** The point (0,0,0). */
32      private static final DirectedPoint POINT_000 = new DirectedPoint();
33  
34      /**
35       * Construct the DefaultCarAnimation for a LaneBlock (road block).
36       * @param source the CSEBlock to draw
37       * @param simulator the simulator to schedule on
38       * @throws NamingException in case of registration failure of the animation
39       * @throws RemoteException on communication failure
40       */
41      public TrafficLightAnimation(final AbstractTrafficLightNew source, final OTSSimulatorInterface simulator)
42          throws NamingException, RemoteException
43      {
44          super(source, simulator);
45          // setTranslate(false);
46          // setRotate(false);
47      }
48  
49      /**
50       * {@inheritDoc}
51       */
52      @Override
53      public final void paint(final Graphics2D graphics, final ImageObserver observer) throws RemoteException
54      {
55          TrafficLight trafficLight = (TrafficLight) this.getSource();
56          Color fillColor;
57          switch (trafficLight.getTrafficLightColor())
58          {
59              case RED:
60                  fillColor = Color.red;
61                  break;
62  
63              case YELLOW:
64                  fillColor = Color.yellow;
65                  break;
66  
67              case GREEN:
68                  fillColor = Color.green;
69                  break;
70  
71              default:
72                  fillColor = Color.black;
73                  break;
74          }
75  
76          PaintPolygons.paintMultiPolygon(graphics, fillColor, trafficLight.getLocation(), trafficLight.getGeometry(),
77              true);
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public final String toString()
83      {
84          return "TrafficLightAnimation [getSource()=" + this.getSource() + "]";
85      }
86  
87  }