Search in sources :

Example 11 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

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();
    for (MeterInterval mi : intervals) {
        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.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint)

Example 12 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class LegendItemCollectionTest method testSerialization.

/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    LegendItemCollection c1 = new LegendItemCollection();
    c1.add(new LegendItem("Item", "Description", "ToolTip", "URL", new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), Color.RED));
    LegendItemCollection c2 = TestUtils.serialised(c1);
    assertEquals(c1, c2);
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) Test(org.junit.jupiter.api.Test)

Example 13 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class LegendItemCollectionTest method testEquals.

/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    LegendItemCollection c1 = new LegendItemCollection();
    LegendItemCollection c2 = new LegendItemCollection();
    assertEquals(c1, c2);
    assertEquals(c2, c1);
    LegendItem item1 = new LegendItem("Label", "Description", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    LegendItem item2 = new LegendItem("Label", "Description", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    c1.add(item1);
    assertNotEquals(c1, c2);
    c2.add(item2);
    assertEquals(c1, c2);
}
Also used : BasicStroke(java.awt.BasicStroke) LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) Rectangle2D(java.awt.geom.Rectangle2D) Line2D(java.awt.geom.Line2D) Test(org.junit.jupiter.api.Test)

Example 14 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class LegendItemCollectionTest method testCloning.

/**
 * Confirm that cloning works.
 * @throws java.lang.CloneNotSupportedException
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    LegendItemCollection c1 = new LegendItemCollection();
    LegendItem item1 = new LegendItem("Item 1");
    c1.add(item1);
    LegendItemCollection c2 = CloneUtils.clone(c1);
    assertNotSame(c1, c2);
    assertSame(c1.getClass(), c2.getClass());
    assertEquals(c1, c2);
    Rectangle2D item1Shape = (Rectangle2D) item1.getShape();
    item1Shape.setRect(1.0, 2.0, 3.0, 4.0);
    assertNotEquals(c1, c2);
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) Rectangle2D(java.awt.geom.Rectangle2D) Test(org.junit.jupiter.api.Test)

Example 15 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class XYPlotTest method testCloning3.

/**
 * Tests cloning for a plot where the fixed legend items have been
 * specified.
 * @throws java.lang.CloneNotSupportedException
 */
@Test
public void testCloning3() throws CloneNotSupportedException {
    XYPlot<String> p1 = new XYPlot<>(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    LegendItemCollection c1 = new LegendItemCollection();
    p1.setFixedLegendItems(c1);
    XYPlot<String> p2 = CloneUtils.clone(p1);
    assertNotSame(p1, p2);
    assertSame(p1.getClass(), p2.getClass());
    assertEquals(p1, p2);
    // verify independence of fixed legend item collection
    c1.add(new LegendItem("X"));
    assertNotEquals(p1, p2);
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) LegendItem(org.jfree.chart.legend.LegendItem) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) Test(org.junit.jupiter.api.Test)

Aggregations

LegendItemCollection (org.jfree.chart.legend.LegendItemCollection)29 LegendItem (org.jfree.chart.legend.LegendItem)20 Test (org.junit.jupiter.api.Test)15 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)5 GradientPaint (java.awt.GradientPaint)5 Stroke (java.awt.Stroke)4 NumberAxis (org.jfree.chart.axis.NumberAxis)4 Rectangle2D (java.awt.geom.Rectangle2D)3 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)3 List (java.util.List)2 JFreeChart (org.jfree.chart.JFreeChart)2 RectangleInsets (org.jfree.chart.api.RectangleInsets)2 DefaultPolarItemRenderer (org.jfree.chart.renderer.DefaultPolarItemRenderer)2 DefaultXYItemRenderer (org.jfree.chart.renderer.xy.DefaultXYItemRenderer)2 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 DefaultShadowGenerator (org.jfree.chart.util.DefaultShadowGenerator)2 XYDataset (org.jfree.data.xy.XYDataset)2 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)2