Search in sources :

Example 1 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class MeterPlot method getLegendItems.

/**
 * Returns an item for each interval.
 *
 * @return A collection of legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    Iterator iterator = this.intervals.iterator();
    while (iterator.hasNext()) {
        MeterInterval mi = (MeterInterval) iterator.next();
        Paint color = mi.getBackgroundPaint();
        if (color == null) {
            color = mi.getOutlinePaint();
        }
        LegendItem item = new LegendItem(mi.getLabel(), mi.getLabel(), null, null, new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0), color);
        item.setDataset(getDataset());
        result.add(item);
    }
    return result;
}
Also used : LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) Iterator(java.util.Iterator) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint)

Example 2 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class LineAndShapeRenderer 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.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }
    if (isSeriesVisible(series) && isSeriesVisibleInLegend(series)) {
        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 fillPaint = (this.useFillPaint ? getItemFillPaint(series, 0) : paint);
        boolean shapeOutlineVisible = this.drawOutlines;
        Paint outlinePaint = (this.useOutlinePaint ? getItemOutlinePaint(series, 0) : paint);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        boolean lineVisible = getItemLineVisible(series, 0);
        boolean shapeVisible = getItemShapeVisible(series, 0);
        LegendItem result = new LegendItem(label, description, toolTipText, urlText, shapeVisible, shape, getItemShapeFilled(series, 0), fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, new Line2D.Double(-7.0, 0.0, 7.0, 0.0), getItemStroke(series, 0), getItemPaint(series, 0));
        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);
        return result;
    }
    return null;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) LegendItem(org.jfree.chart.LegendItem) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 3 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class PolarPlotTest method testGetLegendItems.

/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    XYSeriesCollection d = new XYSeriesCollection();
    d.addSeries(new XYSeries("A"));
    d.addSeries(new XYSeries("B"));
    DefaultPolarItemRenderer r = new DefaultPolarItemRenderer();
    PolarPlot plot = new PolarPlot();
    plot.setDataset(d);
    plot.setRenderer(r);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
    LegendItem item1 = items.get(0);
    assertEquals("A", item1.getLabel());
    LegendItem item2 = items.get(1);
    assertEquals("B", item2.getLabel());
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) DefaultPolarItemRenderer(org.jfree.chart.renderer.DefaultPolarItemRenderer) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) Test(org.junit.Test)

Example 4 with LegendItem

use of org.jfree.chart.LegendItem in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testCloning3.

/**
 * Some more cloning checks.
 */
@Test
public void testCloning3() {
    LegendItemCollection c1 = new LegendItemCollection();
    CategoryPlot p1 = new CategoryPlot();
    p1.setFixedLegendItems(c1);
    CategoryPlot p2 = null;
    try {
        p2 = (CategoryPlot) p1.clone();
    } catch (CloneNotSupportedException e) {
        fail("Cloning failed.");
        return;
    }
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));
    c1.add(new LegendItem("X", "XX", "tt", "url", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red, true, Color.yellow, new BasicStroke(1.0f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f), Color.green));
    assertFalse(p1.equals(p2));
    p2.getFixedLegendItems().add(new LegendItem("X", "XX", "tt", "url", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red, true, Color.yellow, new BasicStroke(1.0f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f), Color.green));
    assertTrue(p1.equals(p2));
}
Also used : BasicStroke(java.awt.BasicStroke) LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) Test(org.junit.Test)

Example 5 with LegendItem

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;
}
Also used : LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) XYDataset(org.jfree.data.xy.XYDataset) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Paint(java.awt.Paint)

Aggregations

LegendItem (org.jfree.chart.LegendItem)51 Paint (java.awt.Paint)26 Test (org.junit.Test)25 NumberAxis (org.jfree.chart.axis.NumberAxis)20 JFreeChart (org.jfree.chart.JFreeChart)19 Stroke (java.awt.Stroke)18 XYPlot (org.jfree.chart.plot.XYPlot)18 Shape (java.awt.Shape)17 LegendItemCollection (org.jfree.chart.LegendItemCollection)17 CategoryPlot (org.jfree.chart.plot.CategoryPlot)15 XYDataset (org.jfree.data.xy.XYDataset)13 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)9 XYSeries (org.jfree.data.xy.XYSeries)9 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)9 CategoryAxis (org.jfree.chart.axis.CategoryAxis)8 CategoryDataset (org.jfree.data.category.CategoryDataset)8 GradientPaint (java.awt.GradientPaint)7 BasicStroke (java.awt.BasicStroke)6 Iterator (java.util.Iterator)5 List (java.util.List)5