package org.opentrafficsim.demo.ntm.IO;
import java.awt.Dimension;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.naming.NamingException;
import javax.swing.JScrollPane;
import org.djunits.unit.DurationUnit;
import org.djunits.value.vdouble.scalar.Duration;
import org.djunits.value.vdouble.scalar.Time;
import org.djutils.event.TimedEvent;
import org.opentrafficsim.core.dsol.OTSAnimator;
import org.opentrafficsim.demo.ntm.NTMModel;
import nl.tudelft.simulation.dsol.SimRuntimeException;
import nl.tudelft.simulation.dsol.experiment.Replication;
import nl.tudelft.simulation.dsol.model.inputparameters.InputParameterException;
import nl.tudelft.simulation.dsol.simtime.SimTimeDoubleUnit;
import nl.tudelft.simulation.dsol.swing.animation.D2.AnimationPanel;
import nl.tudelft.simulation.dsol.swing.gui.DSOLApplication;
import nl.tudelft.simulation.dsol.swing.gui.DSOLPanel;
import nl.tudelft.simulation.dsol.swing.gui.HTMLPanel;
import nl.tudelft.simulation.language.DSOLException;
/**
*
* Copyright (c) 2013-2017 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License .
*
* $LastChangedDate$, @version $Revision$, by $Author$,
* initial version Aug 15, 2014
* @author Alexander Verbraeck
*/
public class DataViewerApplication extends DSOLApplication
{
/**
* @param title String;
* @param panel DSOLPanel<Time,Duration,SimTimeDoubleUnit>;
*/
public DataViewerApplication(String title, DSOLPanel panel)
{
super(title, panel);
}
/** */
private static final long serialVersionUID = 20140819L;
/**
* @param args String[];
* @throws SimRuntimeException
* @throws RemoteException
* @throws NamingException
* @throws IOException
* @throws DSOLException
* @throws InputParameterException
*/
public static void main(final String[] args) throws SimRuntimeException, NamingException, IOException, DSOLException
{
OTSAnimator simulator = new OTSAnimator("DataViewerApplication");
DataViewer model = new DataViewer(simulator);
simulator.initialize(Time.ZERO, Duration.ZERO, new Duration(7200.0, DurationUnit.SECOND), model);
DSOLPanel panel = new DSOLPanel(model, simulator);
addInfoTab(panel);
Rectangle2D extent = new Rectangle2D.Double(65000.0, 440000.0, 55000.0, 30000.0);
Dimension size = new Dimension(1024, 768);
AnimationPanel animationPanel = new AnimationPanel(extent, size, simulator);
panel.getTabbedPane().addTab(0, "animation", animationPanel);
// tell the animation panel to update its statistics
// TODO should be done automatically in DSOL!
animationPanel.notify(
new TimedEvent(Replication.START_REPLICATION_EVENT, simulator, null, simulator.getSimulatorTime()));
new DataViewerApplication("Network Transmission Model", panel);
}
/**
* @param panel DSOLPanel<Time,Duration,SimTimeDoubleUnit>;
*/
private static void addInfoTab(final DSOLPanel panel)
{
// Let's find some content for our infoscreen and add it to our tabbedPane
String helpSource = "/" + NTMModel.class.getPackage().getName().replace('.', '/') + "/html/ntm.html";
URL page = NTMModel.class.getResource(helpSource);
if (page != null)
{
HTMLPanel htmlPanel = null;
try
{
htmlPanel = new HTMLPanel(page);
}
catch (IOException exception)
{
exception.printStackTrace();
}
panel.getTabbedPane().addTab("info", new JScrollPane(htmlPanel));
}
else
{
System.err.println("Information page " + helpSource + " not found.");
}
}
}