Search in sources :

Example 21 with LegendItemCollection

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

the class PolarPlot method getLegendItems.

/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's m_Renderer, since the m_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();
    int count = this.datasets.size();
    for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
        XYDataset dataset = getDataset(datasetIndex);
        PolarItemRenderer renderer = getRenderer(datasetIndex);
        if (dataset != null && renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                LegendItem item = renderer.getLegendItem(i);
                result.add(item);
            }
        }
    }
    return result;
}
Also used : LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) XYDataset(org.jfree.data.xy.XYDataset) PolarItemRenderer(org.jfree.chart.renderer.PolarItemRenderer) Point(java.awt.Point) Paint(java.awt.Paint)

Example 22 with LegendItemCollection

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

the class AbstractCategoryItemRenderer 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>).
 *
 * @see #getLegendItem(int, int)
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (this.plot == null) {
        return result;
    }
    int index = this.plot.getIndexOf(this);
    CategoryDataset dataset = this.plot.getDataset(index);
    if (dataset == null) {
        return result;
    }
    int seriesCount = dataset.getRowCount();
    if (plot.getRowRenderingOrder().equals(SortOrder.ASCENDING)) {
        for (int i = 0; i < seriesCount; i++) {
            if (isSeriesVisibleInLegend(i)) {
                LegendItem item = getLegendItem(index, i);
                if (item != null) {
                    result.add(item);
                }
            }
        }
    } else {
        for (int i = seriesCount - 1; i >= 0; 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) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 23 with LegendItemCollection

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

the class XYPlotTest method testGetLegendItems.

/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    // check the case where there is a secondary dataset that doesn't
    // have a renderer (i.e. falls back to renderer 0)
    XYDataset d0 = createDataset1();
    XYDataset d1 = createDataset2();
    XYItemRenderer r0 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot();
    plot.setDataset(0, d0);
    plot.setDataset(1, d1);
    plot.setRenderer(0, r0);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
}
Also used : LegendItemCollection(org.jfree.chart.LegendItemCollection) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) DefaultXYItemRenderer(org.jfree.chart.renderer.xy.DefaultXYItemRenderer) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Test(org.junit.Test)

Example 24 with LegendItemCollection

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

the class XYPlotTest method testEquals.

/**
 * Some checks for the equals() method.
 */
@Test
public void testEquals() {
    XYPlot plot1 = new XYPlot();
    XYPlot plot2 = new XYPlot();
    assertTrue(plot1.equals(plot2));
    // orientation...
    plot1.setOrientation(PlotOrientation.HORIZONTAL);
    assertFalse(plot1.equals(plot2));
    plot2.setOrientation(PlotOrientation.HORIZONTAL);
    assertTrue(plot1.equals(plot2));
    // axisOffset...
    plot1.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
    assertFalse(plot1.equals(plot2));
    plot2.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
    assertTrue(plot1.equals(plot2));
    // domainAxis...
    plot1.setDomainAxis(new NumberAxis("Domain Axis"));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainAxis(new NumberAxis("Domain Axis"));
    assertTrue(plot1.equals(plot2));
    // domainAxisLocation...
    plot1.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    assertTrue(plot1.equals(plot2));
    // secondary DomainAxes...
    plot1.setDomainAxis(11, new NumberAxis("Secondary Domain Axis"));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainAxis(11, new NumberAxis("Secondary Domain Axis"));
    assertTrue(plot1.equals(plot2));
    // secondary DomainAxisLocations...
    plot1.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
    assertTrue(plot1.equals(plot2));
    // rangeAxis...
    plot1.setRangeAxis(new NumberAxis("Range Axis"));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeAxis(new NumberAxis("Range Axis"));
    assertTrue(plot1.equals(plot2));
    // rangeAxisLocation...
    plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    assertTrue(plot1.equals(plot2));
    // secondary RangeAxes...
    plot1.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
    assertTrue(plot1.equals(plot2));
    // secondary RangeAxisLocations...
    plot1.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
    assertTrue(plot1.equals(plot2));
    // secondary DatasetDomainAxisMap...
    plot1.mapDatasetToDomainAxis(11, 11);
    assertFalse(plot1.equals(plot2));
    plot2.mapDatasetToDomainAxis(11, 11);
    assertTrue(plot1.equals(plot2));
    // secondaryDatasetRangeAxisMap...
    plot1.mapDatasetToRangeAxis(11, 11);
    assertFalse(plot1.equals(plot2));
    plot2.mapDatasetToRangeAxis(11, 11);
    assertTrue(plot1.equals(plot2));
    // renderer
    plot1.setRenderer(new DefaultXYItemRenderer());
    assertFalse(plot1.equals(plot2));
    plot2.setRenderer(new DefaultXYItemRenderer());
    assertTrue(plot1.equals(plot2));
    // secondary renderers
    plot1.setRenderer(11, new DefaultXYItemRenderer());
    assertFalse(plot1.equals(plot2));
    plot2.setRenderer(11, new DefaultXYItemRenderer());
    assertTrue(plot1.equals(plot2));
    // domainGridlinesVisible
    plot1.setDomainGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));
    // domainGridlineStroke
    Stroke stroke = new BasicStroke(2.0f);
    plot1.setDomainGridlineStroke(stroke);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainGridlineStroke(stroke);
    assertTrue(plot1.equals(plot2));
    // domainGridlinePaint
    plot1.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.red));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.blue, 3.0f, 4.0f, Color.red));
    assertTrue(plot1.equals(plot2));
    // rangeGridlinesVisible
    plot1.setRangeGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));
    // rangeGridlineStroke
    plot1.setRangeGridlineStroke(stroke);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeGridlineStroke(stroke);
    assertTrue(plot1.equals(plot2));
    // rangeGridlinePaint
    plot1.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.red));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.red));
    assertTrue(plot1.equals(plot2));
    // rangeZeroBaselineVisible
    plot1.setRangeZeroBaselineVisible(true);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeZeroBaselineVisible(true);
    assertTrue(plot1.equals(plot2));
    // rangeZeroBaselineStroke
    plot1.setRangeZeroBaselineStroke(stroke);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeZeroBaselineStroke(stroke);
    assertTrue(plot1.equals(plot2));
    // rangeZeroBaselinePaint
    plot1.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.red));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.red));
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairVisible
    plot1.setRangeCrosshairVisible(true);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairVisible(true);
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairValue
    plot1.setRangeCrosshairValue(100.0);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairValue(100.0);
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairStroke
    plot1.setRangeCrosshairStroke(stroke);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairStroke(stroke);
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairPaint
    plot1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.pink, 3.0f, 4.0f, Color.red));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.pink, 3.0f, 4.0f, Color.red));
    assertTrue(plot1.equals(plot2));
    // rangeCrosshairLockedOnData
    plot1.setRangeCrosshairLockedOnData(false);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeCrosshairLockedOnData(false);
    assertTrue(plot1.equals(plot2));
    // range markers
    plot1.addRangeMarker(new ValueMarker(4.0));
    assertFalse(plot1.equals(plot2));
    plot2.addRangeMarker(new ValueMarker(4.0));
    assertTrue(plot1.equals(plot2));
    // secondary range markers
    plot1.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
    assertFalse(plot1.equals(plot2));
    plot2.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
    assertTrue(plot1.equals(plot2));
    plot1.addRangeMarker(1, new ValueMarker(99.0), Layer.BACKGROUND);
    assertFalse(plot1.equals(plot2));
    plot2.addRangeMarker(1, new ValueMarker(99.0), Layer.BACKGROUND);
    assertTrue(plot1.equals(plot2));
    // fixed legend items
    plot1.setFixedLegendItems(new LegendItemCollection());
    assertFalse(plot1.equals(plot2));
    plot2.setFixedLegendItems(new LegendItemCollection());
    assertTrue(plot1.equals(plot2));
    // weight
    plot1.setWeight(3);
    assertFalse(plot1.equals(plot2));
    plot2.setWeight(3);
    assertTrue(plot1.equals(plot2));
    // quadrant origin
    plot1.setQuadrantOrigin(new Point2D.Double(12.3, 45.6));
    assertFalse(plot1.equals(plot2));
    plot2.setQuadrantOrigin(new Point2D.Double(12.3, 45.6));
    assertTrue(plot1.equals(plot2));
    // quadrant paint
    plot1.setQuadrantPaint(0, new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setQuadrantPaint(0, new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(plot1.equals(plot2));
    plot1.setQuadrantPaint(1, new GradientPaint(2.0f, 3.0f, Color.red, 4.0f, 5.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setQuadrantPaint(1, new GradientPaint(2.0f, 3.0f, Color.red, 4.0f, 5.0f, Color.blue));
    assertTrue(plot1.equals(plot2));
    plot1.setQuadrantPaint(2, new GradientPaint(3.0f, 4.0f, Color.red, 5.0f, 6.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setQuadrantPaint(2, new GradientPaint(3.0f, 4.0f, Color.red, 5.0f, 6.0f, Color.blue));
    assertTrue(plot1.equals(plot2));
    plot1.setQuadrantPaint(3, new GradientPaint(4.0f, 5.0f, Color.red, 6.0f, 7.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setQuadrantPaint(3, new GradientPaint(4.0f, 5.0f, Color.red, 6.0f, 7.0f, Color.blue));
    assertTrue(plot1.equals(plot2));
    plot1.setDomainTickBandPaint(Color.red);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainTickBandPaint(Color.red);
    assertTrue(plot1.equals(plot2));
    plot1.setRangeTickBandPaint(Color.blue);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeTickBandPaint(Color.blue);
    assertTrue(plot1.equals(plot2));
    plot1.setDomainMinorGridlinesVisible(true);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainMinorGridlinesVisible(true);
    assertTrue(plot1.equals(plot2));
    plot1.setDomainMinorGridlinePaint(Color.red);
    assertFalse(plot1.equals(plot2));
    plot2.setDomainMinorGridlinePaint(Color.red);
    assertTrue(plot1.equals(plot2));
    plot1.setDomainGridlineStroke(new BasicStroke(1.1f));
    assertFalse(plot1.equals(plot2));
    plot2.setDomainGridlineStroke(new BasicStroke(1.1f));
    assertTrue(plot1.equals(plot2));
    plot1.setRangeMinorGridlinesVisible(true);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeMinorGridlinesVisible(true);
    assertTrue(plot1.equals(plot2));
    plot1.setRangeMinorGridlinePaint(Color.blue);
    assertFalse(plot1.equals(plot2));
    plot2.setRangeMinorGridlinePaint(Color.blue);
    assertTrue(plot1.equals(plot2));
    plot1.setRangeMinorGridlineStroke(new BasicStroke(1.23f));
    assertFalse(plot1.equals(plot2));
    plot2.setRangeMinorGridlineStroke(new BasicStroke(1.23f));
    assertTrue(plot1.equals(plot2));
    List axisIndices = Arrays.asList(new Integer[] { new Integer(0), new Integer(1) });
    plot1.mapDatasetToDomainAxes(0, axisIndices);
    assertFalse(plot1.equals(plot2));
    plot2.mapDatasetToDomainAxes(0, axisIndices);
    assertTrue(plot1.equals(plot2));
    plot1.mapDatasetToRangeAxes(0, axisIndices);
    assertFalse(plot1.equals(plot2));
    plot2.mapDatasetToRangeAxes(0, axisIndices);
    assertTrue(plot1.equals(plot2));
    // shadowGenerator
    plot1.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4));
    assertFalse(plot1.equals(plot2));
    plot2.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4));
    assertTrue(plot1.equals(plot2));
    plot1.setShadowGenerator(null);
    assertFalse(plot1.equals(plot2));
    plot2.setShadowGenerator(null);
    assertTrue(plot1.equals(plot2));
    LegendItemCollection lic1 = new LegendItemCollection();
    lic1.add(new LegendItem("XYZ", Color.red));
    plot1.setFixedLegendItems(lic1);
    assertFalse(plot1.equals(plot2));
    LegendItemCollection lic2 = new LegendItemCollection();
    lic2.add(new LegendItem("XYZ", Color.red));
    plot2.setFixedLegendItems(lic2);
    assertTrue(plot1.equals(plot2));
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) NumberAxis(org.jfree.chart.axis.NumberAxis) LegendItemCollection(org.jfree.chart.LegendItemCollection) GradientPaint(java.awt.GradientPaint) DefaultShadowGenerator(org.jfree.chart.util.DefaultShadowGenerator) DefaultXYItemRenderer(org.jfree.chart.renderer.xy.DefaultXYItemRenderer) Point2D(java.awt.geom.Point2D) LegendItem(org.jfree.chart.LegendItem) RectangleInsets(org.jfree.ui.RectangleInsets) List(java.util.List) Test(org.junit.Test)

Example 25 with LegendItemCollection

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

the class PolarPlotTest method testGetLegendItems2.

/**
 * Some checks for the getLegendItems() method with multiple datasets.
 */
@Test
public void testGetLegendItems2() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    d1.addSeries(new XYSeries("A"));
    d1.addSeries(new XYSeries("B"));
    XYSeriesCollection d2 = new XYSeriesCollection();
    d2.addSeries(new XYSeries("C"));
    d2.addSeries(new XYSeries("D"));
    DefaultPolarItemRenderer r = new DefaultPolarItemRenderer();
    PolarPlot plot = new PolarPlot();
    plot.setDataset(d1);
    plot.setDataset(1, d2);
    plot.setRenderer(r);
    plot.setRenderer(1, new DefaultPolarItemRenderer());
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(4, items.getItemCount());
    LegendItem item1 = items.get(0);
    assertEquals("A", item1.getLabel());
    LegendItem item2 = items.get(1);
    assertEquals("B", item2.getLabel());
    LegendItem item3 = items.get(2);
    assertEquals("C", item3.getLabel());
    LegendItem item4 = items.get(3);
    assertEquals("D", item4.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)

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