View Javadoc
1   package org.opentrafficsim.demo.geometry.shape;
2   
3   import java.awt.Dimension;
4   import java.awt.geom.Rectangle2D;
5   import java.io.IOException;
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.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.Replication;
24  import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
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.language.DSOLException;
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-09-03 11:54:19 +0200 (Thu, 03 Sep 2020) $, @version $Revision: 6688 $, by $Author: averbraeck $,
36   * initial version Aug 15, 2014 <br>
37   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
38   */
39  public class ShapeTestApplication extends DSOLApplication implements UNITS
40  {
41      /**
42       * @param title String; String title of the application window
43       * @param panel DSOLPanel&lt;Time,Duration,SimTimeDoubleUnit&gt;; DSOLPanel
44       */
45      public ShapeTestApplication(final String title, final DSOLPanel<Time, Duration, SimTimeDoubleUnit> panel)
46      {
47          super(title, panel);
48      }
49  
50      /** */
51      private static final long serialVersionUID = 20140819L;
52  
53      /**
54       * @param args String[]; command line arguments
55       * @throws SimRuntimeException on ???
56       * @throws NamingException on ???
57       * @throws IOException on ???
58       * @throws OTSDrawingException on drawing error
59       * @throws DSOLException when the simulator does not implement the AnimatorInterface
60       */
61      public static void main(final String[] args)
62              throws SimRuntimeException, NamingException, IOException, OTSDrawingException, DSOLException
63      {
64          OTSAnimator simulator = new OTSAnimator("ShapeTestApplication");
65          ShapeModeletry/shape/ShapeModel.html#ShapeModel">ShapeModel model = new ShapeModel(simulator);
66          OTSReplication replication =
67                  OTSReplication.create("rep1", Time.ZERO, Duration.ZERO, new Duration(7200.0, SECOND), model);
68          simulator.initialize(replication, ReplicationMode.TERMINATING);
69  
70          DSOLPanel<Time, Duration, SimTimeDoubleUnit> panel = new DSOLPanel<Time, Duration, SimTimeDoubleUnit>(model, simulator);
71  
72          Rectangle2D extent = new Rectangle2D.Double(65000.0, 440000.0, 55000.0, 30000.0);
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          // TODO should be done automatically in DSOL!
83          animationPanel.notify(
84                  new TimedEvent(Replication.START_REPLICATION_EVENT, simulator, null, simulator.getSimulatorTime()));
85  
86          new ShapeTestApplication("Network Transmission Model", panel);
87          animationPanel.enableSimulationControlButtons();
88      }
89  
90  }