View Javadoc
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   * Demonstration of a crossing with traffic lights.
23   * <p>
24   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
26   * <p>
27   * $LastChangedDate: 2016-10-28 16:34:11 +0200 (Fri, 28 Oct 2016) $, @version $Revision: 2429 $, by $Author: pknoppers $,
28   * initial version 12 nov. 2014 <br>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   */
31  public class CrossingTrafficLightsSwing extends OTSSimulationApplication<CrossingTrafficLightsModel> implements UNITS
32  {
33      /** */
34      private static final long serialVersionUID = 1L;
35  
36      /**
37       * Create a CrossingTrafficLights Swing application.
38       * @param title String; the title of the Frame
39       * @param panel OTSAnimationPanel; the tabbed panel to display
40       * @param model CrossingTrafficLightsModel; the model
41       * @throws OTSDrawingException on animation error
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       * Main program.
53       * @param args String[]; the command line arguments (not used)
54       */
55      public static void main(final String[] args)
56      {
57          demo(true);
58      }
59  
60      /**
61       * Start the demo.
62       * @param exitOnClose boolean; when running stand-alone: true; when running as part of a demo: false
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  }