/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.geoforge.jfreechart.chart.renderer.xy;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.util.List;
import org.geoforge.jfreechart.chart.labels.GfrStandardXYSeriesLabelGenerator;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.jfree.chart.LegendItem;
import org.jfree.chart.event.AnnotationChangeEvent;
import org.jfree.chart.labels.XYToolTipGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
/**
*
* @author robert
*/
public class GfrXYLineAndShapeRenderer extends XYLineAndShapeRenderer implements
IGfrHandlerLifeCycleObject
{
public GfrXYLineAndShapeRenderer(boolean blnIsLine, boolean blnIsShape)
{
super(blnIsLine,
blnIsShape
);
// specific
// GfrStandardXYSeriesLabelGenerator
//super.setLegendItemLabelGenerator(null);
GfrStandardXYSeriesLabelGenerator gen = new GfrStandardXYSeriesLabelGenerator(
"{0}");
super.setLegendItemLabelGenerator(gen);
}
public GfrXYLineAndShapeRenderer()
{
this(true, true);
}
@Override
public boolean init()
{
// !!! never called !!!
return true;
}
@Override
public void destroy()
{
super.setBaseToolTipGenerator((XYToolTipGenerator) null);
List lst = super.getAnnotations();
if (lst!=null && !lst.isEmpty())
{
for (Object objCur: lst)
{
if (objCur instanceof IGfrHandlerLifeCycleObject)
{
((IGfrHandlerLifeCycleObject) objCur).destroy();
}
}
super.removeAnnotations();
}
}
@Override
public void annotationChanged(AnnotationChangeEvent evt)
{
super.annotationChanged(evt);
}
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
XYPlot plot = getPlot();
if (plot == null) {
return null;
}
XYDataset dataset = plot.getDataset(datasetIndex);
if (dataset == null) {
return null;
}
if (!getItemVisible(series, 0)) {
return null;
}
String label = getLegendItemLabelGenerator().generateLabel(dataset,
series);
String description = label;
String toolTipText = null;
if (getLegendItemToolTipGenerator() != null) {
toolTipText = getLegendItemToolTipGenerator().generateLabel(
dataset, series);
}
String urlText = null;
if (getLegendItemURLGenerator() != null) {
urlText = getLegendItemURLGenerator().generateLabel(dataset,
series);
}
boolean shapeIsVisible = getItemShapeVisible(series, 0);
Shape shape = lookupLegendShape(series);
boolean shapeIsFilled = getItemShapeFilled(series, 0);
Paint fillPaint = (this.useFillPaint ? lookupSeriesFillPaint(series)
: lookupSeriesPaint(series));
boolean shapeOutlineVisible = this.drawOutlines;
Paint outlinePaint = (this.useOutlinePaint ? lookupSeriesOutlinePaint(
series) : lookupSeriesPaint(series));
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
boolean lineVisible = getItemLineVisible(series, 0);
Stroke lineStroke = lookupSeriesStroke(series);
Paint linePaint = lookupSeriesPaint(series);
LegendItem result = new LegendItem(label, description, toolTipText,
urlText, shapeIsVisible, shape, shapeIsFilled, fillPaint,
shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible,
this.legendLine, lineStroke, linePaint);
result.setLabelFont(lookupLegendTextFont(series));
Paint labelPaint = lookupLegendTextPaint(series);
if (labelPaint != null) {
result.setLabelPaint(labelPaint);
}
result.setSeriesKey(dataset.getSeriesKey(series));
result.setSeriesIndex(series);
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
return result;
}
}