1 package org.opentrafficsim.road.gtu.lane;
2
3 import java.rmi.RemoteException;
4
5 import javax.naming.NamingException;
6
7 import nl.tudelft.simulation.dsol.SimRuntimeException;
8
9 import org.opentrafficsim.core.dsol.OTSAnimatorInterface;
10 import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
11 import org.opentrafficsim.core.gtu.GTUException;
12 import org.opentrafficsim.core.network.NetworkException;
13 import org.opentrafficsim.road.gtu.animation.DefaultBlockOnOffAnimation;
14 import org.opentrafficsim.road.network.lane.Lane;
15
16
17
18
19
20
21
22
23
24
25
26
27 public class LaneBlockOnOff extends AbstractTrafficLight
28 {
29
30 private static final long serialVersionUID = 20150624L;
31
32
33
34
35
36
37
38
39
40
41 public LaneBlockOnOff(final String name, final Lane lane, final Length.Rel position,
42 final OTSDEVSSimulatorInterface simulator) throws GTUException, NetworkException, NamingException
43 {
44 super(name, lane, position, simulator);
45
46 try
47 {
48 new DefaultBlockOnOffAnimation(this, getSimulator());
49
50 if (simulator instanceof OTSAnimatorInterface)
51 {
52
53 }
54 getSimulator().scheduleEventRel(new Time.Rel(60.0, SECOND), this, this, "changeColorTime", null);
55 }
56 catch (RemoteException | SimRuntimeException exception)
57 {
58 exception.printStackTrace();
59 }
60 }
61
62 protected void changeColorTime()
63 {
64 setBlocked(!isBlocked());
65
66 try
67 {
68 getSimulator().scheduleEventRel(new Time.Rel(60.0, SECOND), this, this, "changeColorTime", null);
69 }
70 catch (SimRuntimeException exception)
71 {
72 exception.printStackTrace();
73 }
74 }
75
76
77 @Override
78 public String toString()
79 {
80 return "LaneBlockOnOff [lane=" + this.lane + ", position=" + this.position + "]";
81 }
82
83 }