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