View Javadoc
1   package org.opentrafficsim.demo.geometry;
2   
3   import java.awt.Dimension;
4   import java.awt.geom.Rectangle2D;
5   import java.rmi.RemoteException;
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.OTSModelInterface;
23  import org.opentrafficsim.core.dsol.OTSReplication;
24  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
25  
26  /**
27   * <p>
28   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
29   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
30   * <p>
31   * $LastChangedDate: 2015-12-29 03:56:14 +0100 (Tue, 29 Dec 2015) $, @version $Revision: 1668 $, by $Author: averbraeck $,
32   * initial version Oct 16, 2014 <br>
33   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
34   */
35  public class TestGeometry extends DSOLApplication implements UNITS
36  {
37      /** */
38      private static final long serialVersionUID = 1L;
39  
40      /**
41       * @param title t
42       * @param panel p
43       */
44      public TestGeometry(final String title,
45          final DSOLPanel<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> panel)
46      {
47          super(title, panel);
48      }
49  
50      /**
51       * @param args args
52       * @throws RemoteException if error
53       * @throws SimRuntimeException if error
54       * @throws NamingException if error
55       */
56      public static void main(final String[] args) throws SimRuntimeException, NamingException, RemoteException
57      {
58          OTSModelInterface model = new TestModel();
59          OTSDEVSAnimator simulator = new OTSDEVSAnimator();
60          OTSReplication replication =
61              new OTSReplication("rep1", new OTSSimTimeDouble(new DoubleScalar.Abs<TimeUnit>(0.0, SECOND)), new Time.Rel(
62                  0.0, SECOND), new Time.Rel(1800.0, SECOND), model);
63          simulator.initialize(replication, ReplicationMode.TERMINATING);
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(-50, -50, 300, 100);
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          animationPanel.notify(new Event(SimulatorInterface.START_REPLICATION_EVENT, simulator, null));
74  
75          new TestGeometry("TestGeometry", panel);
76      }
77  
78  }