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