View Javadoc
1   package org.opentrafficsim.road.network.lane.object.trafficlight;
2   
3   import java.rmi.RemoteException;
4   
5   import javax.naming.NamingException;
6   
7   import org.djunits.value.vdouble.scalar.Length;
8   import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
9   import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
10  import org.opentrafficsim.core.network.NetworkException;
11  import org.opentrafficsim.road.network.lane.CrossSectionElement;
12  import org.opentrafficsim.road.network.lane.Lane;
13  import org.opentrafficsim.road.network.lane.object.AbstractLaneBasedObject;
14  import org.opentrafficsim.road.network.lane.object.LaneBasedObject;
15  
16  import nl.tudelft.simulation.language.Throw;
17  
18  /**
19   * <p>
20   * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22   * </p>
23   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
24   * initial version Nov 30, 2015 <br>
25   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
27   */
28  public class SimpleTrafficLight extends AbstractLaneBasedObject implements TrafficLight
29  {
30      /** */
31      private static final long serialVersionUID = 201601001L;
32  
33      /** The color of the traffic light. */
34      private TrafficLightColor trafficLightColor;
35  
36      /** Id of the traffic light. */
37      private final String id;
38  
39      /**
40       * @param id traffic light id
41       * @param lane lane where the traffic light is located
42       * @param longitudinalPosition position of the traffic light on the lane, in the design direction
43       * @param simulator simulator on which to schedule color changes
44       * @throws NetworkException on failure to place the object
45       */
46      public SimpleTrafficLight(final String id, final Lane lane, final Length longitudinalPosition,
47              final OTSDEVSSimulatorInterface simulator) throws NetworkException
48      {
49          super(lane, longitudinalPosition, LaneBasedObject.makeGeometry(lane, longitudinalPosition));
50          Throw.whenNull(id, "Id may not be null");
51          this.id = id;
52          this.trafficLightColor = TrafficLightColor.RED;
53  
54          try
55          {
56              new TrafficLightAnimation(this, simulator);
57          }
58          catch (RemoteException exception)
59          {
60              exception.printStackTrace();
61          }
62          catch (NamingException exception)
63          {
64              exception.printStackTrace();
65          }
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public final TrafficLightColor getTrafficLightColor()
71      {
72          return this.trafficLightColor;
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public final void setTrafficLightColor(final TrafficLightColor trafficLightColor)
78      {
79          this.trafficLightColor = trafficLightColor;
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      @SuppressWarnings("checkstyle:designforextension")
85      public String toString()
86      {
87          return "SimpleTrafficLight [trafficLightColor=" + this.trafficLightColor + "]";
88      }
89  
90      /** {@inheritDoc} */
91      @Override
92      public String getId()
93      {
94          return this.id;
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public SimpleTrafficLight clone(final CrossSectionElement newCSE, final OTSSimulatorInterface newSimulator,
100             final boolean animation) throws NetworkException
101     {
102         // TODO
103         return null;
104     }
105 
106 }