Class AbstractPlot<S extends org.opentrafficsim.animation.graphs.AbstractPlot.PaintState>
java.lang.Object
org.opentrafficsim.animation.graphs.AbstractPlot<S>
- Type Parameters:
S- paint state implementation
- All Implemented Interfaces:
Identifiable,org.jfree.data.general.Dataset
- Direct Known Subclasses:
AbstractBoundedPlot,DistributionPlotExtendedData
public abstract class AbstractPlot<S extends org.opentrafficsim.animation.graphs.AbstractPlot.PaintState>
extends Object
implements Identifiable, org.jfree.data.general.Dataset
Super class of all plots. This schedules regular updates, creates menus and deals with listeners. There are a number of
methods for sub-classes to implement.
Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.djunits.value.vdouble.scalar.DurationInitial upper bound for the time scale.static final EventTypeThe (regular, not timed) event type for pub/sub indicating the addition of a graph.static final EventTypeThe (regular, not timed) event type for pub/sub indicating the removal of a graph. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractPlot(PlotScheduler scheduler, String caption, org.djunits.value.vdouble.scalar.Duration updateInterval, org.djunits.value.vdouble.scalar.Duration delay) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeListener(org.jfree.data.general.DatasetChangeListener listener) protected abstract voidcalculatePaintState(org.djunits.value.vdouble.scalar.Duration time) Calculates the paint state object and offers it throughofferPaintState(S), or delegates this work to a delegate.protected abstract SReturns an empty paint state.byte[]encodeAsPng(int width, int height, double fontSize) Returns the chart as a byte array representing a PNG image.org.djunits.value.vdouble.scalar.DurationReturns up to what time data is available for painting.Retrieve the caption.org.jfree.chart.JFreeChartgetChart()Returns the chart.abstract GraphTypeReturn the graph type for transceiver.final org.jfree.data.general.DatasetGroupgetGroup()getId()protected SReturns the current paint state that should be used to return paint data (i.e. x-values, etc.)abstract StringgetStatusLabel(double domainValue, double rangeValue) Returns the status label when the mouse is over the given location.protected voidRequests a calculation of the paint state.voidNotify all change listeners.voidofferPaintState(S paintState) Offer new paint state.voidofferUpdateInterval(org.djunits.value.vdouble.scalar.Duration interval) Suggests a new update interval.voidremoveChangeListener(org.jfree.data.general.DatasetChangeListener listener) voidsetAutoBoundDomain(org.jfree.chart.plot.XYPlot plot) Overridable; activates auto bounds on domain axis from user input.voidsetAutoBoundRange(org.jfree.chart.plot.XYPlot plot) Overridable; activates auto bounds on range axis from user input.protected voidsetChart(org.jfree.chart.JFreeChart chart) Sets the chart and adds menus and listeners.final voidsetGroup(org.jfree.data.general.DatasetGroup group) protected voidSets the paint state in a thread safe manner and notifies the listeners.voidupdate()Requests the worker thread to perform calculations up to the current time and (in the Swing EDT thread) update the plots.
-
Field Details
-
GRAPH_ADD_EVENT
The (regular, not timed) event type for pub/sub indicating the addition of a graph. Not used internally.
Payload: String graph caption (not an array, just a String) -
GRAPH_REMOVE_EVENT
The (regular, not timed) event type for pub/sub indicating the removal of a graph. Not used internally.
Payload: String Graph caption (not an array, just a String) -
DEFAULT_INITIAL_UPPER_TIME_BOUND
public static final org.djunits.value.vdouble.scalar.Duration DEFAULT_INITIAL_UPPER_TIME_BOUNDInitial upper bound for the time scale.
-
-
Constructor Details
-
AbstractPlot
public AbstractPlot(PlotScheduler scheduler, String caption, org.djunits.value.vdouble.scalar.Duration updateInterval, org.djunits.value.vdouble.scalar.Duration delay) Constructor.- Parameters:
scheduler- schedulercaption- captionupdateInterval- regular update interval (simulation time)delay- amount of time that chart runs behind simulation to prevent gaps in the charted data
-
-
Method Details
-
emptyPaintState
Returns an empty paint state. This is used at plot initialization.- Returns:
- empty paint state.
-
setChart
protected void setChart(org.jfree.chart.JFreeChart chart) Sets the chart and adds menus and listeners.- Parameters:
chart- chart
-
encodeAsPng
Returns the chart as a byte array representing a PNG image.- Parameters:
width- widthheight- heightfontSize- font size (16 is the original on screen size)- Returns:
- the chart as a byte array representing a PNG image
- Throws:
IOException- on IO exception
-
getGroup
public final org.jfree.data.general.DatasetGroup getGroup()- Specified by:
getGroupin interfaceorg.jfree.data.general.Dataset
-
setGroup
public final void setGroup(org.jfree.data.general.DatasetGroup group) - Specified by:
setGroupin interfaceorg.jfree.data.general.Dataset
-
setAutoBoundDomain
public void setAutoBoundDomain(org.jfree.chart.plot.XYPlot plot) Overridable; activates auto bounds on domain axis from user input. This class does not force the use ofXYPlots, but the auto bounds command comes from theChartPanelthat shows this plot. In case the used plot is aXYPlot, this method is then invoked. Sub classes with auto domain bounds that work with anXYPlotshould implement this. The method is not abstract as the use ofXYPlotis not obligated.- Parameters:
plot- plot
-
setAutoBoundRange
public void setAutoBoundRange(org.jfree.chart.plot.XYPlot plot) Overridable; activates auto bounds on range axis from user input. This class does not force the use ofXYPlots, but the auto bounds command comes from theChartPanelthat shows this plot. In case the used plot is aXYPlot, this method is then invoked. Sub classes with auto range bounds that work with anXYPlotshould implement this. The method is not abstract as the use ofXYPlotis not obligated.- Parameters:
plot- plot
-
getGraphType
Return the graph type for transceiver.- Returns:
- the graph type.
-
getStatusLabel
Returns the status label when the mouse is over the given location.- Parameters:
domainValue- domain value (x-axis)rangeValue- range value (y-axis)- Returns:
- status label when the mouse is over the given location
-
getChart
public org.jfree.chart.JFreeChart getChart()Returns the chart.- Returns:
- chart
-
getId
- Specified by:
getIdin interfaceIdentifiable
-
getCaption
Retrieve the caption.- Returns:
- the caption of the plot
-
addChangeListener
public void addChangeListener(org.jfree.data.general.DatasetChangeListener listener) - Specified by:
addChangeListenerin interfaceorg.jfree.data.general.Dataset
-
removeChangeListener
public void removeChangeListener(org.jfree.data.general.DatasetChangeListener listener) - Specified by:
removeChangeListenerin interfaceorg.jfree.data.general.Dataset
-
notifyPlotChange
public void notifyPlotChange()Notify all change listeners. -
invalidate
protected void invalidate()Requests a calculation of the paint state. May be invoked by sub-classes whenever a setting was changed that needs a recalculation. -
calculatePaintState
protected abstract void calculatePaintState(org.djunits.value.vdouble.scalar.Duration time) Calculates the paint state object and offers it throughofferPaintState(S), or delegates this work to a delegate. This method is invoked by the worker thread and can thus perform heavy calculations outside of the Swing EDT. Intermediate paint states during long calculations may also be offered. It is up to the implementation to either calculate a complete paint state, or cumulatively built on the results from previous calls. It is also up to the implementation to know when the whole time span needs to be recalculated due to property changes.- Parameters:
time- time until which data in the paint state should be calculated
-
offerPaintState
Offer new paint state. This method can be invoked by any thread, and will make sure the actual setting of the paint state will occur on the Swing EDT. This assures that no paint state is changed as Swing is painting (i.e. as the plot is asked for data to paint). Listeners are notified on the Swing EDT as soon as the paint state has been set.- Parameters:
paintState- paint state
-
setPaintState
protected void setPaintState()Sets the paint state in a thread safe manner and notifies the listeners. This method is always invoked on the Swing EDT. This method may be overridden to use a newly set paint state (after callingsuper.setPaintState()) to set internal properties. For example, setting the block size of an internal block renderer based on the granularity of the data. -
getPaintState
Returns the current paint state that should be used to return paint data (i.e. x-values, etc.)- Returns:
- current paint state
-
getAvailableTime
public org.djunits.value.vdouble.scalar.Duration getAvailableTime()Returns up to what time data is available for painting.- Returns:
- up to what time data is available for painting
-
offerUpdateInterval
public void offerUpdateInterval(org.djunits.value.vdouble.scalar.Duration interval) Suggests a new update interval. This does not affect any time granularity, but only when update events occur. This method will ask thePlotSchedulerto schedule an update now. The next update will set the update interval and schedule the next regular update aligning with the new interval. If an update is also desired right nowinvalidate()needs to be invoked. This method is typically called on the Swing EDT and will request the scheduler asynchronously. This method does not block.- Parameters:
interval- update interval
-
update
public void update()Requests the worker thread to perform calculations up to the current time and (in the Swing EDT thread) update the plots. The worker thread will take on this request once any current calculations are done. If multiple updates are requested before the worker thread is done, only the update with latest time is executed. This method should only be invoked by the thread that governs time (typically by thePlotScheduler). Otherwise events may be erroneously scheduled in the past.After a new update interval was suggested through
offerUpdateInterval(org.djunits.value.vdouble.scalar.Duration)this method does not do the above, but instead only schedules the next update aligning with the new interval.
-