Search in sources :

Example 51 with RectangleInsets

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

the class CombinedRangeCategoryPlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).  Will perform all the placement calculations for each
 * sub-plots and then tell these to draw themselves.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot (including axis labels)
 *              should be drawn.
 * @param anchor  the anchor point ({@code null} permitted).
 * @param parentState  the parent state.
 * @param info  collects information about the drawing ({@code null}
 *              permitted).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // set up info collection...
    if (info != null) {
        info.setPlotArea(area);
    }
    // adjust the drawing area for plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    // calculate the data area...
    AxisSpace space = calculateAxisSpace(g2, area);
    Rectangle2D dataArea = space.shrink(area, null);
    // set the width and height of non-shared axis of all sub-plots
    setFixedDomainAxisSpaceForSubplots(space);
    // draw the shared axis
    ValueAxis axis = getRangeAxis();
    RectangleEdge rangeEdge = getRangeAxisEdge();
    double cursor = RectangleEdge.coordinate(dataArea, rangeEdge);
    AxisState state = axis.draw(g2, cursor, area, dataArea, rangeEdge, info);
    if (parentState == null) {
        parentState = new PlotState();
    }
    parentState.getSharedAxisStates().put(axis, state);
    // draw all the charts
    for (int i = 0; i < this.subplots.size(); i++) {
        CategoryPlot plot = this.subplots.get(i);
        PlotRenderingInfo subplotInfo = null;
        if (info != null) {
            subplotInfo = new PlotRenderingInfo(info.getOwner());
            info.addSubplotInfo(subplotInfo);
        }
        Point2D subAnchor = null;
        if (anchor != null && this.subplotArea[i].contains(anchor)) {
            subAnchor = anchor;
        }
        plot.draw(g2, this.subplotArea[i], subAnchor, parentState, subplotInfo);
    }
    if (info != null) {
        info.setDataArea(dataArea);
    }
}
Also used : AxisState(org.jfree.chart.axis.AxisState) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.chart.api.RectangleInsets) AxisSpace(org.jfree.chart.axis.AxisSpace) RectangleEdge(org.jfree.chart.api.RectangleEdge)

Example 52 with RectangleInsets

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

the class CombinedRangeCategoryPlot method add.

/**
 * Adds a subplot and sends a {@link PlotChangeEvent} to all registered
 * listeners.
 * <br><br>
 * You must ensure that the subplot has a non-null domain axis.  The range
 * axis for the subplot will be set to {@code null}.
 *
 * @param subplot  the subplot ({@code null} not permitted).
 * @param weight  the weight (must be &gt;= 1).
 */
public void add(CategoryPlot subplot, int weight) {
    Args.nullNotPermitted(subplot, "subplot");
    if (weight <= 0) {
        throw new IllegalArgumentException("Require weight >= 1.");
    }
    // store the plot and its weight
    subplot.setParent(this);
    subplot.setWeight(weight);
    subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    subplot.setRangeAxis(null);
    subplot.setOrientation(getOrientation());
    subplot.addChangeListener(this);
    this.subplots.add(subplot);
    // configure the range axis...
    ValueAxis axis = getRangeAxis();
    if (axis != null) {
        axis.configure();
    }
    fireChangeEvent();
}
Also used : ValueAxis(org.jfree.chart.axis.ValueAxis) RectangleInsets(org.jfree.chart.api.RectangleInsets)

Example 53 with RectangleInsets

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

the class PlotTest method testEquals.

/**
 * Check that the equals() method can distinguish all fields (note that
 * the dataset is NOT considered in the equals() method).
 */
@Test
public void testEquals() {
    PiePlot plot1 = new PiePlot();
    PiePlot plot2 = new PiePlot();
    assertEquals(plot1, plot2);
    assertEquals(plot2, plot1);
    // noDataMessage
    plot1.setNoDataMessage("No data XYZ");
    assertNotEquals(plot1, plot2);
    plot2.setNoDataMessage("No data XYZ");
    assertEquals(plot1, plot2);
    // noDataMessageFont
    plot1.setNoDataMessageFont(new Font("SansSerif", Font.PLAIN, 13));
    assertNotEquals(plot1, plot2);
    plot2.setNoDataMessageFont(new Font("SansSerif", Font.PLAIN, 13));
    assertEquals(plot1, plot2);
    // noDataMessagePaint
    plot1.setNoDataMessagePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE));
    assertNotEquals(plot1, plot2);
    plot2.setNoDataMessagePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE));
    assertEquals(plot1, plot2);
    // insets
    plot1.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
    assertNotEquals(plot1, plot2);
    plot2.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
    assertEquals(plot1, plot2);
    // outlineVisible
    plot1.setOutlineVisible(false);
    assertNotEquals(plot1, plot2);
    plot2.setOutlineVisible(false);
    assertEquals(plot1, plot2);
    // outlineStroke
    BasicStroke s = new BasicStroke(1.23f);
    plot1.setOutlineStroke(s);
    assertNotEquals(plot1, plot2);
    plot2.setOutlineStroke(s);
    assertEquals(plot1, plot2);
    // outlinePaint
    plot1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.YELLOW, 3.0f, 4.0f, Color.GREEN));
    assertNotEquals(plot1, plot2);
    plot2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.YELLOW, 3.0f, 4.0f, Color.GREEN));
    assertEquals(plot1, plot2);
    // backgroundPaint
    plot1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.CYAN, 3.0f, 4.0f, Color.GREEN));
    assertNotEquals(plot1, plot2);
    plot2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.CYAN, 3.0f, 4.0f, Color.GREEN));
    assertEquals(plot1, plot2);
    // // backgroundImage
    // plot1.setBackgroundImage(JFreeChart.INFO.getLogo());
    // assertFalse(plot1.equals(plot2));
    // plot2.setBackgroundImage(JFreeChart.INFO.getLogo());
    // assertTrue(plot1.equals(plot2));
    // backgroundImageAlignment
    plot1.setBackgroundImageAlignment(RectangleAlignment.BOTTOM_RIGHT);
    assertNotEquals(plot1, plot2);
    plot2.setBackgroundImageAlignment(RectangleAlignment.BOTTOM_RIGHT);
    assertEquals(plot1, plot2);
    // backgroundImageAlpha
    plot1.setBackgroundImageAlpha(0.77f);
    assertNotEquals(plot1, plot2);
    plot2.setBackgroundImageAlpha(0.77f);
    assertEquals(plot1, plot2);
    // foregroundAlpha
    plot1.setForegroundAlpha(0.99f);
    assertNotEquals(plot1, plot2);
    plot2.setForegroundAlpha(0.99f);
    assertEquals(plot1, plot2);
    // backgroundAlpha
    plot1.setBackgroundAlpha(0.99f);
    assertNotEquals(plot1, plot2);
    plot2.setBackgroundAlpha(0.99f);
    assertEquals(plot1, plot2);
    // drawingSupplier
    plot1.setDrawingSupplier(new DefaultDrawingSupplier(new Paint[] { Color.BLUE }, new Paint[] { Color.RED }, new Stroke[] { new BasicStroke(1.1f) }, new Stroke[] { new BasicStroke(9.9f) }, new Shape[] { new Rectangle(1, 2, 3, 4) }));
    assertNotEquals(plot1, plot2);
    plot2.setDrawingSupplier(new DefaultDrawingSupplier(new Paint[] { Color.BLUE }, new Paint[] { Color.RED }, new Stroke[] { new BasicStroke(1.1f) }, new Stroke[] { new BasicStroke(9.9f) }, new Shape[] { new Rectangle(1, 2, 3, 4) }));
    assertEquals(plot1, plot2);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) Rectangle(java.awt.Rectangle) PiePlot(org.jfree.chart.plot.pie.PiePlot) GradientPaint(java.awt.GradientPaint) RectangleInsets(org.jfree.chart.api.RectangleInsets) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) Test(org.junit.jupiter.api.Test)

Example 54 with RectangleInsets

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

the class LineBorderTest method testEquals.

/**
 * Confirm that the equals() method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    LineBorder b1 = new LineBorder(Color.RED, new BasicStroke(1.0f), new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    LineBorder b2 = new LineBorder(Color.RED, new BasicStroke(1.0f), new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertEquals(b1, b2);
    assertEquals(b2, b2);
    b1 = new LineBorder(Color.BLUE, new BasicStroke(1.0f), new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertNotEquals(b1, b2);
    b2 = new LineBorder(Color.BLUE, new BasicStroke(1.0f), new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertEquals(b1, b2);
    b1 = new LineBorder(Color.BLUE, new BasicStroke(1.1f), new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertNotEquals(b1, b2);
    b2 = new LineBorder(Color.BLUE, new BasicStroke(1.1f), new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertEquals(b1, b2);
    b1 = new LineBorder(Color.BLUE, new BasicStroke(1.1f), new RectangleInsets(1.0, 2.0, 3.0, 4.0));
    assertNotEquals(b1, b2);
    b2 = new LineBorder(Color.BLUE, new BasicStroke(1.1f), new RectangleInsets(1.0, 2.0, 3.0, 4.0));
    assertEquals(b1, b2);
}
Also used : BasicStroke(java.awt.BasicStroke) RectangleInsets(org.jfree.chart.api.RectangleInsets) Test(org.junit.jupiter.api.Test)

Example 55 with RectangleInsets

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

the class LineBorderTest method testSerialization.

/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    LineBorder b1 = new LineBorder(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.YELLOW), new BasicStroke(1.0f), new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    LineBorder b2 = TestUtils.serialised(b1);
    assertEquals(b1, b2);
}
Also used : BasicStroke(java.awt.BasicStroke) GradientPaint(java.awt.GradientPaint) RectangleInsets(org.jfree.chart.api.RectangleInsets) Test(org.junit.jupiter.api.Test)

Aggregations

RectangleInsets (org.jfree.chart.api.RectangleInsets)58 Rectangle2D (java.awt.geom.Rectangle2D)19 Test (org.junit.jupiter.api.Test)17 Font (java.awt.Font)16 BasicStroke (java.awt.BasicStroke)14 GradientPaint (java.awt.GradientPaint)13 Paint (java.awt.Paint)9 Shape (java.awt.Shape)9 AxisState (org.jfree.chart.axis.AxisState)7 FontMetrics (java.awt.FontMetrics)6 Stroke (java.awt.Stroke)6 FontRenderContext (java.awt.font.FontRenderContext)6 LineMetrics (java.awt.font.LineMetrics)6 RectangleEdge (org.jfree.chart.api.RectangleEdge)6 AxisSpace (org.jfree.chart.axis.AxisSpace)6 ValueAxis (org.jfree.chart.axis.ValueAxis)6 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)6 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)6 AlphaComposite (java.awt.AlphaComposite)5 Composite (java.awt.Composite)5