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