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.djutils.event.TimedEvent;
13  import org.opentrafficsim.core.animation.gtu.colorer.DefaultSwitchableGTUColorer;
14  import org.opentrafficsim.core.dsol.OTSAnimator;
15  import org.opentrafficsim.core.dsol.OTSModelInterface;
16  import org.opentrafficsim.core.dsol.OTSReplication;
17  import org.opentrafficsim.draw.core.OTSDrawingException;
18  import org.opentrafficsim.draw.factory.DefaultAnimationFactory;
19  import org.opentrafficsim.swing.gui.AnimationToggles;
20  import org.opentrafficsim.swing.gui.OTSAnimationPanel;
21  import org.opentrafficsim.swing.gui.OTSSwingApplication;
22  
23  import nl.tudelft.simulation.dsol.SimRuntimeException;
24  import nl.tudelft.simulation.dsol.experiment.ReplicationInterface;
25  import nl.tudelft.simulation.dsol.swing.gui.DSOLApplication;
26  import nl.tudelft.simulation.dsol.swing.gui.DSOLPanel;
27  import nl.tudelft.simulation.dsol.swing.gui.control.RealTimeControlPanel;
28  import nl.tudelft.simulation.language.DSOLException;
29  
30  /**
31   * <p>
32   * Copyright (c) 2013-2022 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$, @version $Revision$, by $Author$,
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 panel)
49      {
50          super(panel, title);
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       * @throws DSOLException when the simulator does not implement AnimatorInterface
60       */
61      public static void main(final String[] args)
62              throws SimRuntimeException, NamingException, RemoteException, OTSDrawingException, DSOLException
63      {
64          OTSAnimator simulator = new OTSAnimator("TestGeometry");
65          OTSModelInterface model = new TestModel(simulator);
66          OTSReplication replication = new OTSReplication("rep1", Time.ZERO, Duration.ZERO, new Duration(1800.0, SECOND));
67          simulator.initialize(model, replication);
68          DSOLPanel panel =
69                  new DSOLPanel(new RealTimeControlPanel<Duration, OTSAnimator>(model, simulator));
70  
71          Rectangle2D extent = new Rectangle2D.Double(-50, -50, 200, 50);
72          Dimension size = new Dimension(1024, 768);
73          OTSAnimationPanel animationPanel =
74                  new OTSAnimationPanel(extent, size, simulator, model, new DefaultSwitchableGTUColorer(), model.getNetwork());
75          panel.getTabbedPane().addTab(0, "animation", animationPanel);
76  
77          DefaultAnimationFactory.animateNetwork(model.getNetwork(), model.getSimulator(), OTSSwingApplication.DEFAULT_COLORER);
78          AnimationToggles.setTextAnimationTogglesStandard(animationPanel);
79  
80          // tell the animation panel to update its statistics
81          animationPanel.notify(
82                  new TimedEvent(ReplicationInterface.START_REPLICATION_EVENT, simulator, null, simulator.getSimulatorTime()));
83  
84          new TestGeometry("TestGeometry", panel);
85          animationPanel.enableSimulationControlButtons();
86      }
87  
88  }