use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class XYPlotTest method testCloning3.
/**
* Tests cloning for a plot where the fixed legend items have been
* specified.
*/
@Test
public void testCloning3() throws CloneNotSupportedException {
XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer());
LegendItemCollection c1 = new LegendItemCollection();
p1.setFixedLegendItems(c1);
XYPlot p2 = (XYPlot) p1.clone();
assertTrue(p1 != p2);
assertTrue(p1.getClass() == p2.getClass());
assertTrue(p1.equals(p2));
// verify independence of fixed legend item collection
c1.add(new LegendItem("X"));
assertFalse(p1.equals(p2));
}
use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class AbstractCategoryItemRenderer method getLegendItem.
/**
* Returns a legend item for a series. This default implementation will
* return <code>null</code> if {@link #isSeriesVisible(int)} or
* {@link #isSeriesVisibleInLegend(int)} returns <code>false</code>.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return The legend item (possibly <code>null</code>).
*
* @see #getLegendItems()
*/
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
CategoryPlot p = getPlot();
if (p == null) {
return null;
}
// check that a legend item needs to be displayed...
if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
return null;
}
CategoryDataset dataset = p.getDataset(datasetIndex);
String label = this.legendItemLabelGenerator.generateLabel(dataset, series);
String description = label;
String toolTipText = null;
if (this.legendItemToolTipGenerator != null) {
toolTipText = this.legendItemToolTipGenerator.generateLabel(dataset, series);
}
String urlText = null;
if (this.legendItemURLGenerator != null) {
urlText = this.legendItemURLGenerator.generateLabel(dataset, series);
}
Shape shape = lookupLegendShape(series);
Paint paint = lookupSeriesPaint(series);
Paint outlinePaint = lookupSeriesOutlinePaint(series);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
LegendItem item = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
item.setLabelFont(lookupLegendTextFont(series));
Paint labelPaint = lookupLegendTextPaint(series);
if (labelPaint != null) {
item.setLabelPaint(labelPaint);
}
item.setSeriesKey(dataset.getRowKey(series));
item.setSeriesIndex(series);
item.setDataset(dataset);
item.setDatasetIndex(datasetIndex);
return item;
}
use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class BarRenderer method getLegendItem.
/**
* Returns a legend item for a series.
*
* @param datasetIndex the dataset index (zero-based).
* @param series the series index (zero-based).
*
* @return The legend item (possibly <code>null</code>).
*/
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
CategoryPlot cp = getPlot();
if (cp == null) {
return null;
}
// check that a legend item needs to be displayed...
if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
return null;
}
CategoryDataset dataset = cp.getDataset(datasetIndex);
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);
}
Shape shape = lookupLegendShape(series);
Paint paint = lookupSeriesPaint(series);
Paint outlinePaint = lookupSeriesOutlinePaint(series);
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
LegendItem result = new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f), Color.black);
result.setLabelFont(lookupLegendTextFont(series));
Paint labelPaint = lookupLegendTextPaint(series);
if (labelPaint != null) {
result.setLabelPaint(labelPaint);
}
result.setDataset(dataset);
result.setDatasetIndex(datasetIndex);
result.setSeriesKey(dataset.getRowKey(series));
result.setSeriesIndex(series);
if (this.gradientPaintTransformer != null) {
result.setFillPaintTransformer(this.gradientPaintTransformer);
}
return result;
}
use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class SpiderWebPlot method getLegendItems.
/**
* Returns a collection of legend items for the spider web chart.
*
* @return The legend items (never <code>null</code>).
*/
@Override
public LegendItemCollection getLegendItems() {
LegendItemCollection result = new LegendItemCollection();
if (getDataset() == null) {
return result;
}
List keys = null;
if (this.dataExtractOrder == TableOrder.BY_ROW) {
keys = this.dataset.getRowKeys();
} else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
keys = this.dataset.getColumnKeys();
}
if (keys == null) {
return result;
}
int series = 0;
Iterator iterator = keys.iterator();
Shape shape = getLegendItemShape();
while (iterator.hasNext()) {
Comparable key = (Comparable) iterator.next();
String label = key.toString();
String description = label;
Paint paint = getSeriesPaint(series);
Paint outlinePaint = getSeriesOutlinePaint(series);
Stroke stroke = getSeriesOutlineStroke(series);
LegendItem item = new LegendItem(label, description, null, null, shape, paint, stroke, outlinePaint);
item.setDataset(getDataset());
item.setSeriesKey(key);
item.setSeriesIndex(series);
result.add(item);
series++;
}
return result;
}
use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.
the class XYPlot method getLegendItems.
/**
* Returns the legend items for the plot. Each legend item is generated by
* the plot's renderer, since the renderer is responsible for the visual
* representation of the data.
*
* @return The legend items.
*/
@Override
public LegendItemCollection getLegendItems() {
if (this.fixedLegendItems != null) {
return this.fixedLegendItems;
}
LegendItemCollection result = new LegendItemCollection();
for (XYDataset dataset : this.datasets.values()) {
if (dataset == null) {
continue;
}
int datasetIndex = indexOf(dataset);
XYItemRenderer renderer = getRenderer(datasetIndex);
if (renderer == null) {
renderer = getRenderer(0);
}
if (renderer != null) {
int seriesCount = dataset.getSeriesCount();
for (int i = 0; i < seriesCount; i++) {
if (renderer.isSeriesVisible(i) && renderer.isSeriesVisibleInLegend(i)) {
LegendItem item = renderer.getLegendItem(datasetIndex, i);
if (item != null) {
result.add(item);
}
}
}
}
}
return result;
}
Aggregations