View Javadoc
1   package org.opentrafficsim.demo.geometry.shape;
2   
3   import java.awt.Dimension;
4   import java.awt.geom.Rectangle2D;
5   import java.io.IOException;
6   
7   import javax.naming.NamingException;
8   
9   import nl.tudelft.simulation.dsol.SimRuntimeException;
10  import nl.tudelft.simulation.dsol.animation.D2.AnimationPanel;
11  import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
12  import nl.tudelft.simulation.dsol.gui.swing.DSOLApplication;
13  import nl.tudelft.simulation.dsol.gui.swing.DSOLPanel;
14  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
15  import nl.tudelft.simulation.event.Event;
16  
17  import org.djunits.unit.TimeUnit;
18  import org.djunits.value.vdouble.scalar.DoubleScalar;
19  import org.opentrafficsim.core.OTS_SCALAR;
20  import org.opentrafficsim.core.dsol.OTSDEVSAnimator;
21  import org.opentrafficsim.core.dsol.OTSReplication;
22  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
23  
24  /**
25   * <p>
26   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
27   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
28   * <p>
29   * $LastChangedDate: 2015-09-03 13:38:07 +0200 (Thu, 03 Sep 2015) $, @version $Revision: 1379 $, by $Author: averbraeck $,
30   * initial version Aug 15, 2014 <br>
31   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
32   */
33  public class ShapeTestApplication extends DSOLApplication implements OTS_SCALAR
34  {
35      /**
36       * @param title String title of the application window
37       * @param panel DSOLPanel
38       */
39      public ShapeTestApplication(final String title,
40          final DSOLPanel<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> panel)
41      {
42          super(title, panel);
43      }
44  
45      /** */
46      private static final long serialVersionUID = 20140819L;
47  
48      /**
49       * @param args String[]; command line arguments
50       * @throws SimRuntimeException on ???
51       * @throws NamingException on ???
52       * @throws IOException on ???
53       */
54      public static void main(final String[] args) throws SimRuntimeException, NamingException, IOException
55      {
56          ShapeModel model = new ShapeModel();
57          OTSDEVSAnimator simulator = new OTSDEVSAnimator();
58          OTSReplication replication =
59              new OTSReplication("rep1", new OTSSimTimeDouble(new DoubleScalar.Abs<TimeUnit>(0.0, SECOND)), new Time.Rel(0.0,
60                  SECOND), new Time.Rel(7200.0, SECOND), model);
61          simulator.initialize(replication, ReplicationMode.TERMINATING);
62  
63          DSOLPanel<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> panel =
64              new DSOLPanel<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble>(model, simulator);
65  
66          Rectangle2D extent = new Rectangle2D.Double(65000.0, 440000.0, 55000.0, 30000.0);
67          Dimension size = new Dimension(1024, 768);
68          AnimationPanel animationPanel = new AnimationPanel(extent, size, simulator);
69          panel.getTabbedPane().addTab(0, "animation", animationPanel);
70  
71          // tell the animation panel to update its statistics
72          // TODO should be done automatically in DSOL!
73          animationPanel.notify(new Event(SimulatorInterface.START_REPLICATION_EVENT, simulator, null));
74  
75          new ShapeTestApplication("Network Transmission Model", panel);
76      }
77  
78  }