Search in sources :

Example 1 with LegendItemCollection

use of org.jfree.chart.LegendItemCollection 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 2 with LegendItemCollection

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

the class AbstractXYItemRenderer method getLegendItems.

/**
 * Returns a (possibly empty) collection of legend items for the series
 * that this renderer is responsible for drawing.
 *
 * @return The legend item collection (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.plot == null) {
        return new LegendItemCollection();
    }
    LegendItemCollection result = new LegendItemCollection();
    int index = this.plot.getIndexOf(this);
    XYDataset dataset = this.plot.getDataset(index);
    if (dataset != null) {
        int seriesCount = dataset.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            if (isSeriesVisibleInLegend(i)) {
                LegendItem item = getLegendItem(index, 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) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 3 with LegendItemCollection

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

the class PiePlot method getLegendItems.

/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }
    List keys = this.dataset.getKeys();
    int section = 0;
    Shape shape = getLegendItemShape();
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        Number n = this.dataset.getValue(key);
        boolean include;
        if (n == null) {
            include = !this.ignoreNullValues;
        } else {
            double v = n.doubleValue();
            if (v == 0.0) {
                include = !this.ignoreZeroValues;
            } else {
                include = v > 0.0;
            }
        }
        if (include) {
            String label = this.legendLabelGenerator.generateSectionLabel(this.dataset, key);
            if (label != null) {
                String description = label;
                String toolTipText = null;
                if (this.legendLabelToolTipGenerator != null) {
                    toolTipText = this.legendLabelToolTipGenerator.generateSectionLabel(this.dataset, key);
                }
                String urlText = null;
                if (this.legendLabelURLGenerator != null) {
                    urlText = this.legendLabelURLGenerator.generateURL(this.dataset, key, this.pieIndex);
                }
                Paint paint = lookupSectionPaint(key);
                Paint outlinePaint = lookupSectionOutlinePaint(key);
                Stroke outlineStroke = lookupSectionOutlineStroke(key);
                LegendItem item = new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, true, outlinePaint, outlineStroke, // line not visible
                false, new Line2D.Float(), new BasicStroke(), Color.black);
                item.setDataset(getDataset());
                item.setSeriesIndex(this.dataset.getIndex(key));
                item.setSeriesKey(key);
                result.add(item);
            }
            section++;
        } else {
            section++;
        }
    }
    return result;
}
Also used : BasicStroke(java.awt.BasicStroke) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Shape(java.awt.Shape) LegendItemCollection(org.jfree.chart.LegendItemCollection) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) LegendItem(org.jfree.chart.LegendItem) Iterator(java.util.Iterator) List(java.util.List)

Example 4 with LegendItemCollection

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

the class CombinedDomainXYPlot method getLegendItems.

/**
 * Returns a collection of legend items for the plot.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = getFixedLegendItems();
    if (result == null) {
        result = new LegendItemCollection();
        if (this.subplots != null) {
            Iterator iterator = this.subplots.iterator();
            while (iterator.hasNext()) {
                XYPlot plot = (XYPlot) iterator.next();
                LegendItemCollection more = plot.getLegendItems();
                result.addAll(more);
            }
        }
    }
    return result;
}
Also used : LegendItemCollection(org.jfree.chart.LegendItemCollection) Iterator(java.util.Iterator)

Example 5 with LegendItemCollection

use of org.jfree.chart.LegendItemCollection 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)

Aggregations

LegendItemCollection (org.jfree.chart.LegendItemCollection)30 LegendItem (org.jfree.chart.LegendItem)19 Paint (java.awt.Paint)12 Test (org.junit.Test)12 Iterator (java.util.Iterator)9 BasicStroke (java.awt.BasicStroke)6 Stroke (java.awt.Stroke)6 GradientPaint (java.awt.GradientPaint)5 NumberAxis (org.jfree.chart.axis.NumberAxis)5 List (java.util.List)4 XYDataset (org.jfree.data.xy.XYDataset)4 Shape (java.awt.Shape)3 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)3 Color (java.awt.Color)2 Font (java.awt.Font)2 HashSet (java.util.HashSet)2 JFreeChart (org.jfree.chart.JFreeChart)2 DefaultPolarItemRenderer (org.jfree.chart.renderer.DefaultPolarItemRenderer)2 DefaultXYItemRenderer (org.jfree.chart.renderer.xy.DefaultXYItemRenderer)2 LegendTitle (org.jfree.chart.title.LegendTitle)2