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.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.OTSReplication;
15  import org.opentrafficsim.draw.core.OTSDrawingException;
16  import org.opentrafficsim.draw.factory.DefaultAnimationFactory;
17  import org.opentrafficsim.swing.gui.AnimationToggles;
18  import org.opentrafficsim.swing.gui.OTSAnimationPanel;
19  import org.opentrafficsim.swing.gui.OTSSwingApplication;
20  
21  import nl.tudelft.simulation.dsol.SimRuntimeException;
22  import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
23  import nl.tudelft.simulation.dsol.simtime.SimTimeDoubleUnit;
24  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
25  import nl.tudelft.simulation.dsol.swing.gui.DSOLApplication;
26  import nl.tudelft.simulation.dsol.swing.gui.DSOLPanel;
27  import nl.tudelft.simulation.event.Event;
28  
29  /**
30   * <p>
31   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
32   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
33   * <p>
34   * $LastChangedDate: 2019-01-18 16:48:39 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 4878 $, by $Author: wjschakel $,
35   * initial version Aug 15, 2014 <br>
36   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
37   */
38  public class ShapeTestApplication extends DSOLApplication implements UNITS
39  {
40      /**
41       * @param title String; String title of the application window
42       * @param panel DSOLPanel&lt;Time,Duration,SimTimeDoubleUnit&gt;; DSOLPanel
43       */
44      public ShapeTestApplication(final String title, final DSOLPanel<Time, Duration, SimTimeDoubleUnit> panel)
45      {
46          super(title, panel);
47      }
48  
49      /** */
50      private static final long serialVersionUID = 20140819L;
51  
52      /**
53       * @param args String[]; command line arguments
54       * @throws SimRuntimeException on ???
55       * @throws NamingException on ???
56       * @throws IOException on ???
57       * @throws OTSDrawingException on drawing error
58       */
59      public static void main(final String[] args) throws SimRuntimeException, NamingException, IOException, OTSDrawingException
60      {
61          OTSAnimator simulator = new OTSAnimator();
62          ShapeModel model = new ShapeModel(simulator);
63          OTSReplication replication =
64                  OTSReplication.create("rep1", Time.ZERO, Duration.ZERO, new Duration(7200.0, SECOND), model);
65          simulator.initialize(replication, ReplicationMode.TERMINATING);
66  
67          DSOLPanel<Time, Duration, SimTimeDoubleUnit> panel = new DSOLPanel<Time, Duration, SimTimeDoubleUnit>(model, simulator);
68  
69          Rectangle2D extent = new Rectangle2D.Double(65000.0, 440000.0, 55000.0, 30000.0);
70          Dimension size = new Dimension(1024, 768);
71          OTSAnimationPanel animationPanel =
72                  new OTSAnimationPanel(extent, size, simulator, model, new DefaultSwitchableGTUColorer(), model.getNetwork());
73          panel.getTabbedPane().addTab(0, "animation", animationPanel);
74  
75          DefaultAnimationFactory.animateNetwork(model.getNetwork(), model.getSimulator(), OTSSwingApplication.DEFAULT_COLORER);
76          AnimationToggles.setTextAnimationTogglesStandard(animationPanel);
77  
78          // tell the animation panel to update its statistics
79          // TODO should be done automatically in DSOL!
80          animationPanel.notify(new Event(SimulatorInterface.START_REPLICATION_EVENT, simulator, null));
81  
82          new ShapeTestApplication("Network Transmission Model", panel);
83      }
84  
85  }