1 package org.opentrafficsim.demo.conflict;
2
3 import java.rmi.RemoteException;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.djunits.unit.SpeedUnit;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.opentrafficsim.animation.colorer.Colorer;
10 import org.opentrafficsim.animation.data.gtu.SpeedGtuColorer;
11 import org.opentrafficsim.core.dsol.OtsAnimator;
12 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
13 import org.opentrafficsim.core.gtu.Gtu;
14 import org.opentrafficsim.demo.conflict.TJunctionDemo.TJunctionModel;
15 import org.opentrafficsim.road.network.factory.xml.OtsXmlModel;
16 import org.opentrafficsim.swing.gui.OtsSimulationApplication;
17 import org.opentrafficsim.swing.gui.OtsSimulationPanel;
18 import org.opentrafficsim.swing.gui.OtsSimulationPanelDecorator;
19
20 import nl.tudelft.simulation.dsol.SimRuntimeException;
21 import nl.tudelft.simulation.language.DsolException;
22
23
24
25
26
27
28
29
30
31
32 public class TJunctionDemo extends OtsSimulationApplication<TJunctionModel>
33 {
34
35 private static final long serialVersionUID = 20161211L;
36
37
38
39
40
41
42
43 public TJunctionDemo(final String title, final OtsSimulationPanel panel, final TJunctionModel model)
44 {
45 super(model, panel);
46 }
47
48
49
50
51
52 public static void main(final String[] args)
53 {
54 demo(true);
55 }
56
57
58
59
60
61 public static void demo(final boolean exitOnClose)
62 {
63 try
64 {
65 OtsAnimator simulator = new OtsAnimator("TJunctionDemo");
66 final TJunctionModel junctionModel = new TJunctionModel(simulator);
67 OtsSimulationPanel simulationPanel =
68 new OtsSimulationPanel(junctionModel.getNetwork(), new OtsSimulationPanelDecorator()
69 {
70 @Override
71 public List<Colorer<? super Gtu>> getGtuColorers()
72 {
73 List<Colorer<? super Gtu>> colorers = new ArrayList<>(DEFAULT_GTU_COLORERS);
74 colorers.set(colorers.size() - 2, new SpeedGtuColorer(new Speed(60.0, SpeedUnit.KM_PER_HOUR)));
75 return colorers;
76 }
77 });
78 TJunctionDemo app = new TJunctionDemo("T-Junction demo", simulationPanel, junctionModel);
79 app.setExitOnClose(exitOnClose);
80 simulationPanel.enableSimulationControlButtons();
81 }
82 catch (SimRuntimeException | RemoteException | DsolException exception)
83 {
84 exception.printStackTrace();
85 }
86 }
87
88
89
90
91 public static class TJunctionModel extends OtsXmlModel
92 {
93
94
95
96
97 public TJunctionModel(final OtsSimulatorInterface simulator)
98 {
99 super(simulator, "/resources/conflict/TJunction.xml");
100 }
101 }
102 }