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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations