View Javadoc
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   * <p>
25   * Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
26   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
27   * </p>
28   * @author Alexander Verbraeck
29   * @author Peter Knoppers
30   * @author Wouter Schakel
31   */
32  public class TJunctionDemo extends OtsSimulationApplication<TJunctionModel>
33  {
34      /** Serialization version UID. */
35      private static final long serialVersionUID = 20161211L;
36  
37      /**
38       * Create a T-Junction demo.
39       * @param title the title of the Frame
40       * @param panel the tabbed panel to display
41       * @param model the model
42       */
43      public TJunctionDemo(final String title, final OtsSimulationPanel panel, final TJunctionModel model)
44      {
45          super(model, panel);
46      }
47  
48      /**
49       * Main program.
50       * @param args the command line arguments (not used)
51       */
52      public static void main(final String[] args)
53      {
54          demo(true);
55      }
56  
57      /**
58       * Start the demo.
59       * @param exitOnClose when running stand-alone: true; when running as part of a demo: false
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       * The simulation model.
90       */
91      public static class TJunctionModel extends OtsXmlModel
92      {
93          /**
94           * Constructor.
95           * @param simulator the simulator for this model
96           */
97          public TJunctionModel(final OtsSimulatorInterface simulator)
98          {
99              super(simulator, "/resources/conflict/TJunction.xml");
100         }
101     }
102 }