Search in sources :

Example 31 with LegendItem

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

the class LegendItemTest method testCloning.

/**
 * Basic checks for cloning.
 * @throws java.lang.CloneNotSupportedException
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    LegendItem item1 = new LegendItem("Item");
    LegendItem item2 = CloneUtils.clone(item1);
    assertNotSame(item1, item2);
    assertSame(item1.getClass(), item2.getClass());
    assertEquals(item1, item2);
    // the clone references the same dataset as the original
    assertSame(item1.getDataset(), item2.getDataset());
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) Test(org.junit.jupiter.api.Test)

Example 32 with LegendItem

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

the class LegendItemTest method testEquals.

/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    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);
    assertEquals(item1, item2);
    assertEquals(item2, item1);
    item1 = new LegendItem("Label2", "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);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "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);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "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);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "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);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, 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);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, 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);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.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);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.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);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, 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);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, 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);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, 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);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, 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);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), false, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), false, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.GREEN);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(2.1f), Color.GREEN);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(2.1f), Color.GREEN);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f), Color.GREEN);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f), Color.GREEN);
    assertEquals(item1, item2);
    item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f), Color.WHITE);
    assertNotEquals(item1, item2);
    item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.YELLOW, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f), Color.WHITE);
    assertEquals(item1, item2);
    // fillPaintTransformer
    item1.setFillPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL));
    assertNotEquals(item1, item2);
    item2.setFillPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL));
    assertEquals(item1, item2);
    // labelFont
    item1.setLabelFont(new Font("Dialog", Font.PLAIN, 13));
    assertNotEquals(item1, item2);
    item2.setLabelFont(new Font("Dialog", Font.PLAIN, 13));
    assertEquals(item1, item2);
    // labelPaint
    item1.setLabelPaint(Color.RED);
    assertNotEquals(item1, item2);
    item2.setLabelPaint(Color.RED);
    assertEquals(item1, item2);
    // fillPaint
    item1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.GREEN, 3.0f, 4.0f, Color.BLUE));
    assertNotEquals(item1, item2);
    item2.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.GREEN, 3.0f, 4.0f, Color.BLUE));
    assertEquals(item1, item2);
    // outlinePaint
    item1.setOutlinePaint(new GradientPaint(1.1f, 2.2f, Color.GREEN, 3.3f, 4.4f, Color.BLUE));
    assertNotEquals(item1, item2);
    item2.setOutlinePaint(new GradientPaint(1.1f, 2.2f, Color.GREEN, 3.3f, 4.4f, Color.BLUE));
    assertEquals(item1, item2);
    // linePaint
    item1.setLinePaint(new GradientPaint(0.1f, 0.2f, Color.GREEN, 0.3f, 0.4f, Color.BLUE));
    assertNotEquals(item1, item2);
    item2.setLinePaint(new GradientPaint(0.1f, 0.2f, Color.GREEN, 0.3f, 0.4f, Color.BLUE));
    assertEquals(item1, item2);
}
Also used : BasicStroke(java.awt.BasicStroke) StandardGradientPaintTransformer(org.jfree.chart.util.StandardGradientPaintTransformer) LegendItem(org.jfree.chart.legend.LegendItem) Rectangle2D(java.awt.geom.Rectangle2D) GradientPaint(java.awt.GradientPaint) Line2D(java.awt.geom.Line2D) Font(java.awt.Font) Test(org.junit.jupiter.api.Test)

Example 33 with LegendItem

use of org.jfree.chart.legend.LegendItem 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 34 with LegendItem

use of org.jfree.chart.legend.LegendItem 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 35 with LegendItem

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

Aggregations

LegendItem (org.jfree.chart.legend.LegendItem)58 Test (org.junit.jupiter.api.Test)32 Paint (java.awt.Paint)23 NumberAxis (org.jfree.chart.axis.NumberAxis)20 LegendItemCollection (org.jfree.chart.legend.LegendItemCollection)20 JFreeChart (org.jfree.chart.JFreeChart)19 XYPlot (org.jfree.chart.plot.XYPlot)18 Stroke (java.awt.Stroke)16 Shape (java.awt.Shape)15 CategoryPlot (org.jfree.chart.plot.CategoryPlot)15 XYDataset (org.jfree.data.xy.XYDataset)12 GradientPaint (java.awt.GradientPaint)9 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)9 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)9 CategoryAxis (org.jfree.chart.axis.CategoryAxis)8 CategoryDataset (org.jfree.data.category.CategoryDataset)8 XYSeries (org.jfree.data.xy.XYSeries)7 BasicStroke (java.awt.BasicStroke)6 Rectangle2D (java.awt.geom.Rectangle2D)6 Line2D (java.awt.geom.Line2D)5