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.Replication;
25 import nl.tudelft.simulation.dsol.experiment.ReplicationMode;
26 import nl.tudelft.simulation.dsol.simtime.SimTimeDoubleUnit;
27 import nl.tudelft.simulation.dsol.swing.gui.DSOLApplication;
28 import nl.tudelft.simulation.dsol.swing.gui.DSOLPanel;
29 import nl.tudelft.simulation.language.DSOLException;
30
31
32
33
34
35
36
37
38
39
40 public class TestGeometry extends DSOLApplication implements UNITS
41 {
42
43 private static final long serialVersionUID = 1L;
44
45
46
47
48
49 public TestGeometry(final String title, final DSOLPanel<Time, Duration, SimTimeDoubleUnit> panel)
50 {
51 super(title, panel);
52 }
53
54
55
56
57
58
59
60
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 =
68 OTSReplication.create("rep1", Time.ZERO, Duration.ZERO, new Duration(1800.0, SECOND), model);
69 simulator.initialize(replication, ReplicationMode.TERMINATING);
70 DSOLPanel<Time, Duration, SimTimeDoubleUnit> panel = new DSOLPanel<Time, Duration, SimTimeDoubleUnit>(model, simulator);
71
72 Rectangle2D extent = new Rectangle2D.Double(-50, -50, 300, 100);
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
82 animationPanel.notify(
83 new TimedEvent(Replication.START_REPLICATION_EVENT, simulator, null, simulator.getSimulatorTime()));
84
85 new TestGeometry("TestGeometry", panel);
86 animationPanel.enableSimulationControlButtons();
87 }
88
89 }