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 nl.tudelft.simulation.dsol.SimRuntimeException;
8   import nl.tudelft.simulation.dsol.animation.D2.AnimationPanel;
9   import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
10  import nl.tudelft.simulation.dsol.gui.swing.DSOLApplication;
11  import nl.tudelft.simulation.dsol.gui.swing.DSOLPanel;
12  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
13  import nl.tudelft.simulation.event.Event;
14  
15  import org.opentrafficsim.core.dsol.OTSDEVSAnimator;
16  import org.opentrafficsim.core.dsol.OTSModelInterface;
17  import org.opentrafficsim.core.dsol.OTSReplication;
18  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
19  import org.opentrafficsim.core.unit.TimeUnit;
20  import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
21  
22  /**
23   * <p>
24   * Copyright (c) 2013-2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
26   * <p>
27   * @version Oct 16, 2014 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   */
30  public class TestGeometry extends DSOLApplication
31  {
32      /** */
33      private static final long serialVersionUID = 1L;
34  
35      /**
36       * @param title t
37       * @param panel p
38       */
39      public TestGeometry(final String title,
40          final DSOLPanel<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> panel)
41      {
42          super(title, panel);
43      }
44  
45      /**
46       * @param args args
47       * @throws RemoteException if error
48       * @throws SimRuntimeException if error
49       */
50      public static void main(final String[] args) throws RemoteException, SimRuntimeException
51      {
52          OTSModelInterface model = new TestModel();
53          OTSDEVSAnimator simulator = new OTSDEVSAnimator();
54          OTSReplication replication =
55              new OTSReplication("rep1", new OTSSimTimeDouble(new DoubleScalar.Abs<TimeUnit>(0.0, TimeUnit.SECOND)),
56                  new DoubleScalar.Rel<TimeUnit>(0.0, TimeUnit.SECOND),
57                  new DoubleScalar.Rel<TimeUnit>(1800.0, TimeUnit.SECOND), model);
58          simulator.initialize(replication, ReplicationMode.TERMINATING);
59          DSOLPanel<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> panel =
60              new DSOLPanel<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble>(model, simulator);
61  
62          Rectangle2D extent = new Rectangle2D.Double(-50, -50, 300, 100);
63          Dimension size = new Dimension(1024, 768);
64          AnimationPanel animationPanel = new AnimationPanel(extent, size, simulator);
65          panel.getTabbedPane().addTab(0, "animation", animationPanel);
66  
67          // tell the animation panel to update its statistics
68          animationPanel.notify(new Event(SimulatorInterface.START_REPLICATION_EVENT, simulator, null));
69  
70          new TestGeometry("TestGeometry", panel);
71      }
72  
73  }