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.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.core.network.OTSNetwork;
13 import org.opentrafficsim.draw.core.OTSDrawingException;
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
20
21
22
23
24
25
26
27
28
29
30 public class CrossingTrafficLightsSwing extends OTSSimulationApplication<CrossingTrafficLightsModel> implements UNITS
31 {
32
33 private static final long serialVersionUID = 1L;
34
35
36
37
38
39
40
41
42 public CrossingTrafficLightsSwing(final String title, final OTSAnimationPanel panel, final CrossingTrafficLightsModel model)
43 throws OTSDrawingException
44 {
45 super(model, panel);
46 OTSNetwork network = model.getNetwork();
47 System.out.println(network.getLinkMap());
48 }
49
50
51
52
53
54 public static void main(final String[] args)
55 {
56 demo(true);
57 }
58
59
60
61
62
63 public static void demo(final boolean exitOnClose)
64 {
65 try
66 {
67 OTSAnimator simulator = new OTSAnimator();
68 final CrossingTrafficLightsModel otsModel = new CrossingTrafficLightsModel(simulator);
69 if (TabbedParameterDialog.process(otsModel.getInputParameterMap()))
70 {
71 simulator.initialize(Time.ZERO, Duration.ZERO, Duration.createSI(3600.0), otsModel);
72 OTSAnimationPanel animationPanel = new OTSAnimationPanel(otsModel.getNetwork().getExtent(),
73 new Dimension(800, 600), simulator, otsModel, DEFAULT_COLORER, otsModel.getNetwork());
74 CrossingTrafficLightsSwing app =
75 new CrossingTrafficLightsSwing("CrossingTrafficLights", animationPanel, otsModel);
76 app.setExitOnClose(exitOnClose);
77 }
78 else
79 {
80 if (exitOnClose)
81 {
82 System.exit(0);
83 }
84 }
85 }
86 catch (SimRuntimeException | NamingException | RemoteException | OTSDrawingException exception)
87 {
88 exception.printStackTrace();
89 }
90 }
91 }