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