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.simtime.SimTimeDoubleUnit;
26  import nl.tudelft.simulation.dsol.swing.gui.DSOLApplication;
27  import nl.tudelft.simulation.dsol.swing.gui.DSOLPanel;
28  import nl.tudelft.simulation.dsol.swing.gui.control.RealTimeControlPanel;
29  import nl.tudelft.simulation.language.DSOLException;
30  
31  /**
32   * <p>
33   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
34   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
35   * <p>
36   * $LastChangedDate: 2022-02-09 18:05:59 +0100 (Wed, 09 Feb 2022) $, @version $Revision: 7012 $, by $Author: averbraeck $,
37   * initial version Oct 16, 2014 <br>
38   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
39   */
40  public class TestGeometry extends DSOLApplication implements UNITS
41  {
42      /** */
43      private static final long serialVersionUID = 1L;
44  
45      /**
46       * @param title String; t
47       * @param panel DSOLPanel&lt;Time,Duration,SimTimeDoubleUnit&gt;; p
48       */
49      public TestGeometry(final String title, final DSOLPanel panel)
50      {
51          super(panel, title);
52      }
53  
54      /**
55       * @param args String[]; args
56       * @throws RemoteException if error
57       * @throws SimRuntimeException if error
58       * @throws NamingException if error
59       * @throws OTSDrawingException if error
60       * @throws DSOLException when the simulator does not implement AnimatorInterface
61       */
62      public static void main(final String[] args)
63              throws SimRuntimeException, NamingException, RemoteException, OTSDrawingException, DSOLException
64      {
65          OTSAnimator simulator = new OTSAnimator("TestGeometry");
66          OTSModelInterface model = new TestModel(simulator);
67          OTSReplication replication = new OTSReplication("rep1", Time.ZERO, Duration.ZERO, new Duration(1800.0, SECOND));
68          simulator.initialize(model, replication);
69          DSOLPanel panel =
70                  new DSOLPanel(new RealTimeControlPanel<Time, Duration, SimTimeDoubleUnit, OTSAnimator>(model, simulator));
71  
72          Rectangle2D extent = new Rectangle2D.Double(-50, -50, 200, 50);
73          Dimension size = new Dimension(1024, 768);
74          OTSAnimationPanel animationPanel =
75                  new OTSAnimationPanel(extent, size, simulator, model, new DefaultSwitchableGTUColorer(), model.getNetwork());
76          panel.getTabbedPane().addTab(0, "animation", animationPanel);
77  
78          DefaultAnimationFactory.animateNetwork(model.getNetwork(), model.getSimulator(), OTSSwingApplication.DEFAULT_COLORER);
79          AnimationToggles.setTextAnimationTogglesStandard(animationPanel);
80  
81          // tell the animation panel to update its statistics
82          animationPanel.notify(
83                  new TimedEvent(ReplicationInterface.START_REPLICATION_EVENT, simulator, null, simulator.getSimulatorTime()));
84  
85          new TestGeometry("TestGeometry", panel);
86          animationPanel.enableSimulationControlButtons();
87      }
88  
89  }