1 package org.opentrafficsim.swing.gui;
2
3 import java.awt.Dimension;
4 import java.rmi.RemoteException;
5
6 import org.opentrafficsim.core.dsol.AbstractOtsModel;
7 import org.opentrafficsim.core.dsol.OtsAnimator;
8 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
9 import org.opentrafficsim.draw.OtsDrawingException;
10 import org.opentrafficsim.road.network.RoadNetwork;
11
12 import nl.tudelft.simulation.dsol.SimRuntimeException;
13 import nl.tudelft.simulation.language.DsolException;
14
15
16
17
18
19
20
21
22 public class CustomSimulation extends OtsSimulationApplication<CustomSimulation.CustomModel>
23 {
24
25 private static final long serialVersionUID = 20240418L;
26
27
28
29
30
31
32
33
34 public CustomSimulation(final String title, final OtsAnimationPanel panel, final CustomModel model)
35 throws OtsDrawingException
36 {
37 super(model, panel);
38 }
39
40
41
42
43
44
45
46 public static void demo(final boolean exitOnClose, final OtsAnimator simulator, final CustomModel model)
47 {
48 try
49 {
50 OtsAnimationPanel animationPanel = new OtsAnimationPanel(model.getNetwork().getExtent(), new Dimension(800, 600),
51 simulator, model, DEFAULT_COLORER, model.getNetwork());
52 CustomSimulation app = new CustomSimulation("Custom Simulation", animationPanel, model);
53 app.setExitOnClose(exitOnClose);
54 animationPanel.enableSimulationControlButtons();
55 }
56 catch (SimRuntimeException | RemoteException | OtsDrawingException | DsolException exception)
57 {
58 exception.printStackTrace();
59 }
60 }
61
62
63
64
65
66
67
68
69 public static class CustomModel extends AbstractOtsModel
70 {
71
72 private static final long serialVersionUID = 20240418L;
73
74
75 private RoadNetwork network;
76
77
78
79
80
81 public CustomModel(final OtsSimulatorInterface simulator)
82 {
83 super(simulator);
84 }
85
86
87
88
89
90 public void setNetwork(final RoadNetwork network)
91 {
92 this.network = network;
93 }
94
95
96 @Override
97 public void constructModel() throws SimRuntimeException
98 {
99
100 }
101
102
103 @Override
104 public RoadNetwork getNetwork()
105 {
106 return this.network;
107 }
108 }
109
110 }