package nl.tudelft.simulation.dsol.swing.charts.histogram; import java.awt.Color; import java.awt.Container; import java.awt.GradientPaint; import java.io.Serializable; import java.rmi.RemoteException; import javax.naming.NamingException; import org.djutils.event.EventProducerInterface; import org.djutils.event.EventTypeInterface; import org.djutils.event.ref.ReferenceType; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import nl.tudelft.simulation.dsol.simulators.SimulatorInterface; import nl.tudelft.simulation.dsol.statistics.SimCounter; import nl.tudelft.simulation.dsol.swing.Swingable; import nl.tudelft.simulation.naming.context.ContextInterface; import nl.tudelft.simulation.naming.context.util.ContextUtil; /** * The histogram specifies a histogram chart for the DSOL framework. *
* copyright (c) 2002-2021 Delft University of Technology , the Netherlands.
* See for project information www.simulation.tudelft.nl .
*
* Copyright (c) 2002-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information https://simulation.tudelft.nl. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * * https://simulation.tudelft.nl/dsol/3.0/license.html. *
* @author Alexander VerbraeckCounter.COUNT_EVENT.
* @param counter Counter; the counter to add.
*/
public synchronized void add(final SimCounter, ?, ?> counter)
{
HistogramSeries set = this.getDataset().addSeries(counter.getDescription());
counter.addListener(set, SimCounter.TIMED_OBSERVATION_ADDED_EVENT, ReferenceType.STRONG);
}
/**
* adds an eventProducer to the histogram dataset. The histogram subscribes its dataset subsequentially to the specified
* event.
* @param description String; the description of the eventProducer
* @param source EventProducerInterface; the eventproducer which functions as source for this histogram.
* @param eventType EventType; the eventType.
* @throws RemoteException on network error for the (possibly remote) event listener
*/
public synchronized void add(final String description, final EventProducerInterface source,
final EventTypeInterface eventType) throws RemoteException
{
HistogramSeries set = this.getDataset().addSeries(description);
source.addListener(set, eventType, ReferenceType.STRONG);
}
/**
* returns the chart.
* @return JFreeChart
*/
public JFreeChart getChart()
{
return this.chart;
}
/** {@inheritDoc} */
@Override
public Container getSwingPanel()
{
ChartPanel result = new ChartPanel(this.chart);
result.setMouseZoomable(true, false);
return result;
}
/**
* returns the dataset of a histogram.
* @return the HistogramDataset containing all series.
*/
public HistogramDataset getDataset()
{
return this.dataset;
}
/** {@inheritDoc} */
@Override
public String toString()
{
return getChart().getTitle().getText();
}
}