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