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
32
33
34
35
36
37
38
39 public class TestGeometry extends DSOLApplication implements UNITS
40 {
41
42 private static final long serialVersionUID = 1L;
43
44
45
46
47
48 public TestGeometry(final String title, final DSOLPanel panel)
49 {
50 super(panel, title);
51 }
52
53
54
55
56
57
58
59
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
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 }