package com.positive.charting;
import org.eclipse.swt.graphics.Rectangle;
import com.positive.charts.entity.EntityCollection;
import com.positive.charts.entity.StandardEntityCollection;
import com.positive.charts.plot.PlotRenderingInfo;
import com.positive.charts.util.RectangleUtil;
/**
* A structure for storing rendering information from one call to the
* JFreeChart.draw() method.
* <P>
* An instance of the {@link JFreeChart} class can draw itself within an
* arbitrary rectangle on any <code>Graphics2D</code>. It is assumed that client
* code will sometimes render the same chart in more than one view, so the
* {@link JFreeChart} instance does not retain any information about its
* rendered dimensions. This information can be useful sometimes, so you have
* the option to collect the information at each call to
* <code>JFreeChart.draw()</code>, by passing an instance of this
* <code>ChartRenderingInfo</code> class.
*/
public class ChartRenderingInfo {
/** For serialization. */
private static final long serialVersionUID = 2751952018173406822L;
/** The area in which the chart is drawn. */
private transient final Rectangle chartArea;
/** Rendering info for the chart's plot (and subplots, if any). */
private PlotRenderingInfo plotInfo;
/**
* Storage for the chart entities. Since retaining entity information for
* charts with a large number of data points consumes a lot of memory, it is
* intended that you can set this to <code>null</code> to prevent the
* information being collected.
*/
private EntityCollection entities;
/**
* Constructs a new ChartRenderingInfo structure that can be used to collect
* information about the dimensions of a rendered chart.
*/
public ChartRenderingInfo() {
this(new StandardEntityCollection());
}
/**
* Constructs a new instance. If an entity collection is supplied, it will
* be populated with information about the entities in a chart. If it is
* <code>null</code>, no entity information (including tool tips) will be
* collected.
*
* @param entities
* an entity collection (<code>null</code> permitted).
*/
public ChartRenderingInfo(final EntityCollection entities) {
this.chartArea = new Rectangle(0, 0, 0, 0);
this.plotInfo = new PlotRenderingInfo(this);
this.entities = entities;
}
/**
* Clears the information recorded by this object.
*/
public void clear() {
this.chartArea.x = this.chartArea.y = this.chartArea.width = this.chartArea.height = 0;
this.plotInfo = new PlotRenderingInfo(this);
if (this.entities != null) {
this.entities.clear();
}
}
/**
* Returns the area in which the chart was drawn.
*
* @return The area in which the chart was drawn.
*/
public Rectangle getChartArea() {
return this.chartArea;
}
/**
* Returns the collection of entities maintained by this instance.
*
* @return The entity collection (possibly <code>null</code>.
*/
public EntityCollection getEntityCollection() {
return this.entities;
}
/**
* Returns the rendering info for the chart's plot.
*
* @return The rendering info for the plot.
*/
public PlotRenderingInfo getPlotInfo() {
return this.plotInfo;
}
/**
* Sets the area in which the chart was drawn.
*
* @param area
* the chart area.
*/
public void setChartArea(final Rectangle area) {
RectangleUtil.setRect(this.chartArea, area);
}
/**
* Sets the entity collection.
*
* @param entities
* the entity collection (<code>null</code> permitted).
*/
public void setEntityCollection(final EntityCollection entities) {
this.entities = entities;
}
}