package com.positive.charts.tooltips;
import java.util.List;
import com.positive.charts.event.RendererChangeEvent;
import com.positive.charts.renderer.ChartRenderer;
public class XYTooltips {
/** The base tool tip generator. */
private XYToolTipGenerator baseToolTipGenerator;
/** The tool tip generator for ALL series. */
private XYToolTipGenerator toolTipGenerator;
/** A list of tool tip generators (one per series). */
private List toolTipGeneratorList;
/** The renderer that this tooltips handler is attached to. */
private final ChartRenderer renderer;
public XYTooltips(final ChartRenderer renderer) {
this.renderer = renderer;
}
/**
* Returns the base tool tip generator.
*
* @return The generator (possibly <code>null</code>).
*/
public XYToolTipGenerator getBaseToolTipGenerator() {
return this.baseToolTipGenerator;
}
/**
* Returns the tool tip generator for a series.
*
* @param series
* the series index (zero based).
*
* @return The generator (possibly <code>null</code>).
*/
public XYToolTipGenerator getSeriesToolTipGenerator(final int series) {
// return the generator for ALL series, if there is one...
if (this.toolTipGenerator != null) {
return this.toolTipGenerator;
}
// otherwise look up the generator table
XYToolTipGenerator generator = (XYToolTipGenerator) this.toolTipGeneratorList
.get(series);
if (generator == null) {
generator = this.baseToolTipGenerator;
}
return generator;
}
/**
* Returns the tool tip generator for a data item. This implementation
* simply passes control to the getSeriesToolTipGenerator() method. If, for
* some reason, you want a different generator for individual items, you can
* override this method.
*
* @param row
* the row index (zero based).
* @param column
* the column index (zero based).
*
* @return The generator (possibly <code>null</code>).
*/
public XYToolTipGenerator getToolTipGenerator(final int row,
final int column) {
return this.getSeriesToolTipGenerator(row);
}
/**
* Sets the base tool tip generator and sends a {@link RendererChangeEvent}
* to all registered listeners.
*
* @param generator
* the generator (<code>null</code> permitted).
*/
public void setBaseToolTipGenerator(final XYToolTipGenerator generator) {
this.baseToolTipGenerator = generator;
this.renderer.notifyListeners(new RendererChangeEvent(this));
}
/**
* Sets the tool tip generator for a series and sends a
* {@link RendererChangeEvent} to all registered listeners.
*
* @param series
* the series index (zero based).
* @param generator
* the generator (<code>null</code> permitted).
*/
public void setSeriesToolTipGenerator(final int series,
final XYToolTipGenerator generator) {
this.toolTipGeneratorList.set(series, generator);
this.renderer.notifyListeners(new RendererChangeEvent(this));
}
/**
* Sets the tool tip generator for ALL series and sends a
* {@link RendererChangeEvent} to all registered listeners.
*
* @param generator
* the generator (<code>null</code> permitted).
*/
public void setToolTipGenerator(final XYToolTipGenerator generator) {
this.toolTipGenerator = generator;
this.renderer.notifyListeners(new RendererChangeEvent(this));
}
}