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 org.djunits.unit.util.UNITS;
10  import org.djunits.value.vdouble.scalar.Duration;
11  import org.djunits.value.vdouble.scalar.Time;
12  import org.opentrafficsim.core.animation.gtu.colorer.DefaultSwitchableGTUColorer;
13  import org.opentrafficsim.core.dsol.OTSAnimator;
14  import org.opentrafficsim.core.dsol.OTSModelInterface;
15  import org.opentrafficsim.core.dsol.OTSReplication;
16  import org.opentrafficsim.draw.core.OTSDrawingException;
17  import org.opentrafficsim.draw.factory.DefaultAnimationFactory;
18  import org.opentrafficsim.swing.gui.AnimationToggles;
19  import org.opentrafficsim.swing.gui.OTSAnimationPanel;
20  import org.opentrafficsim.swing.gui.OTSSwingApplication;
21  
22  import nl.tudelft.simulation.dsol.SimRuntimeException;
23  import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
24  import nl.tudelft.simulation.dsol.simtime.SimTimeDoubleUnit;
25  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
26  import nl.tudelft.simulation.dsol.swing.gui.DSOLApplication;
27  import nl.tudelft.simulation.dsol.swing.gui.DSOLPanel;
28  import nl.tudelft.simulation.event.Event;
29  
30  /**
31   * <p>
32   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
33   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
34   * <p>
35   * $LastChangedDate: 2020-01-23 11:14:19 +0100 (Thu, 23 Jan 2020) $, @version $Revision: 6010 $, by $Author: averbraeck $,
36   * initial version Oct 16, 2014 <br>
37   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
38   */
39  public class TestGeometry extends DSOLApplication implements UNITS
40  {
41      /** */
42      private static final long serialVersionUID = 1L;
43  
44      /**
45       * @param title String; t
46       * @param panel DSOLPanel&lt;Time,Duration,SimTimeDoubleUnit&gt;; p
47       */
48      public TestGeometry(final String title, final DSOLPanel<Time, Duration, SimTimeDoubleUnit> panel)
49      {
50          super(title, panel);
51      }
52  
53      /**
54       * @param args String[]; args
55       * @throws RemoteException if error
56       * @throws SimRuntimeException if error
57       * @throws NamingException if error
58       * @throws OTSDrawingException if error
59       */
60      public static void main(final String[] args)
61              throws SimRuntimeException, NamingException, RemoteException, OTSDrawingException
62      {
63          OTSAnimator simulator = new OTSAnimator();
64          OTSModelInterface model = new TestModel(simulator);
65          OTSReplication replication =
66                  OTSReplication.create("rep1", Time.ZERO, Duration.ZERO, new Duration(1800.0, SECOND), model);
67          simulator.initialize(replication, ReplicationMode.TERMINATING);
68          DSOLPanel<Time, Duration, SimTimeDoubleUnit> panel = new DSOLPanel<Time, Duration, SimTimeDoubleUnit>(model, simulator);
69  
70          Rectangle2D extent = new Rectangle2D.Double(-50, -50, 300, 100);
71          Dimension size = new Dimension(1024, 768);
72          OTSAnimationPanel animationPanel =
73                  new OTSAnimationPanel(extent, size, simulator, model, new DefaultSwitchableGTUColorer(), model.getNetwork());
74          panel.getTabbedPane().addTab(0, "animation", animationPanel);
75  
76          DefaultAnimationFactory.animateNetwork(model.getNetwork(), model.getSimulator(), OTSSwingApplication.DEFAULT_COLORER);
77          AnimationToggles.setTextAnimationTogglesStandard(animationPanel);
78  
79          // tell the animation panel to update its statistics
80          animationPanel.notify(new Event(SimulatorInterface.START_REPLICATION_EVENT, simulator, null));
81  
82          new TestGeometry("TestGeometry", panel);
83      }
84  
85  }