1 package org.opentrafficsim.demo;
2
3 import java.awt.Dimension;
4 import java.rmi.RemoteException;
5
6 import javax.naming.NamingException;
7
8 import org.djunits.unit.util.UNITS;
9 import org.djunits.value.vdouble.scalar.Duration;
10 import org.djunits.value.vdouble.scalar.Time;
11 import org.opentrafficsim.core.dsol.OTSAnimator;
12 import org.opentrafficsim.draw.core.OTSDrawingException;
13 import org.opentrafficsim.road.network.OTSRoadNetwork;
14 import org.opentrafficsim.swing.gui.OTSAnimationPanel;
15 import org.opentrafficsim.swing.gui.OTSSimulationApplication;
16
17 import nl.tudelft.simulation.dsol.SimRuntimeException;
18 import nl.tudelft.simulation.dsol.swing.gui.inputparameters.TabbedParameterDialog;
19 import nl.tudelft.simulation.language.DSOLException;
20
21
22
23
24
25
26
27
28
29
30
31 public class CrossingTrafficLightsSwing extends OTSSimulationApplication<CrossingTrafficLightsModel> implements UNITS
32 {
33
34 private static final long serialVersionUID = 1L;
35
36
37
38
39
40
41
42
43 public CrossingTrafficLightsSwing(final String title, final OTSAnimationPanel panel, final CrossingTrafficLightsModel model)
44 throws OTSDrawingException
45 {
46 super(model, panel);
47 OTSRoadNetwork network = model.getNetwork();
48 System.out.println(network.getLinkMap());
49 }
50
51
52
53
54
55 public static void main(final String[] args)
56 {
57 demo(true);
58 }
59
60
61
62
63
64 public static void demo(final boolean exitOnClose)
65 {
66 try
67 {
68 OTSAnimator simulator = new OTSAnimator("CrossingTrafficLightsSwing");
69 final CrossingTrafficLightsModelml#CrossingTrafficLightsModel">CrossingTrafficLightsModel otsModel = new CrossingTrafficLightsModel(simulator);
70 if (TabbedParameterDialog.process(otsModel.getInputParameterMap()))
71 {
72 simulator.initialize(Time.ZERO, Duration.ZERO, Duration.instantiateSI(3600.0), otsModel);
73 OTSAnimationPanel animationPanel = new OTSAnimationPanel(otsModel.getNetwork().getExtent(),
74 new Dimension(800, 600), simulator, otsModel, DEFAULT_COLORER, otsModel.getNetwork());
75 CrossingTrafficLightsSwing app =
76 new CrossingTrafficLightsSwing("CrossingTrafficLights", animationPanel, otsModel);
77 app.setExitOnClose(exitOnClose);
78 animationPanel.enableSimulationControlButtons();
79 }
80 else
81 {
82 if (exitOnClose)
83 {
84 System.exit(0);
85 }
86 }
87 }
88 catch (SimRuntimeException | NamingException | RemoteException | OTSDrawingException | DSOLException exception)
89 {
90 exception.printStackTrace();
91 }
92 }
93 }