Search in sources :

Example 1 with ChartProgressEvent

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

the class JFreeChartInfo method draw.

/**
 * Draws the chart on a Java 2D graphics device (such as the screen or a
 * printer).
 * <P>
 * This method is the focus of the entire JFreeChart library.
 *
 * @param g2  the graphics device.
 * @param chartArea  the area within which the chart should be drawn.
 * @param anchor  the anchor point (in Java2D space) for the chart
 *                (<code>null</code> permitted).
 * @param info  records info about the drawing (null means collect no info).
 */
public void draw(Graphics2D g2, Rectangle2D chartArea, Point2D anchor, ChartRenderingInfo info) {
    notifyListeners(new ChartProgressEvent(this, this, ChartProgressEvent.DRAWING_STARTED, 0));
    EntityCollection entities = null;
    // record the chart area, if info is requested...
    if (info != null) {
        info.clear();
        info.setChartArea(chartArea);
        entities = info.getEntityCollection();
    }
    if (entities != null) {
        entities.add(new JFreeChartEntity((Rectangle2D) chartArea.clone(), this));
    }
    // ensure no drawing occurs outside chart area...
    Shape savedClip = g2.getClip();
    g2.clip(chartArea);
    g2.addRenderingHints(this.renderingHints);
    // draw the chart background...
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(chartArea);
    }
    if (this.backgroundImage != null) {
        Composite originalComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.backgroundImageAlpha));
        Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0, this.backgroundImage.getWidth(null), this.backgroundImage.getHeight(null));
        Align.align(dest, chartArea, this.backgroundImageAlignment);
        g2.drawImage(this.backgroundImage, (int) dest.getX(), (int) dest.getY(), (int) dest.getWidth(), (int) dest.getHeight(), null);
        g2.setComposite(originalComposite);
    }
    if (isBorderVisible()) {
        Paint paint = getBorderPaint();
        Stroke stroke = getBorderStroke();
        if (paint != null && stroke != null) {
            Rectangle2D borderArea = new Rectangle2D.Double(chartArea.getX(), chartArea.getY(), chartArea.getWidth() - 1.0, chartArea.getHeight() - 1.0);
            g2.setPaint(paint);
            g2.setStroke(stroke);
            g2.draw(borderArea);
        }
    }
    // draw the title and subtitles...
    Rectangle2D nonTitleArea = new Rectangle2D.Double();
    nonTitleArea.setRect(chartArea);
    this.padding.trim(nonTitleArea);
    if (this.title != null && this.title.isVisible()) {
        EntityCollection e = drawTitle(this.title, g2, nonTitleArea, (entities != null));
        if (e != null && entities != null) {
            entities.addAll(e);
        }
    }
    Iterator iterator = this.subtitles.iterator();
    while (iterator.hasNext()) {
        Title currentTitle = (Title) iterator.next();
        if (currentTitle.isVisible()) {
            EntityCollection e = drawTitle(currentTitle, g2, nonTitleArea, (entities != null));
            if (e != null && entities != null) {
                entities.addAll(e);
            }
        }
    }
    Rectangle2D plotArea = nonTitleArea;
    // draw the plot (axes and data visualisation)
    PlotRenderingInfo plotInfo = null;
    if (info != null) {
        plotInfo = info.getPlotInfo();
    }
    this.plot.draw(g2, plotArea, anchor, null, plotInfo);
    g2.setClip(savedClip);
    notifyListeners(new ChartProgressEvent(this, this, ChartProgressEvent.DRAWING_FINISHED, 100));
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Shape(java.awt.Shape) ChartProgressEvent(org.jfree.chart.event.ChartProgressEvent) JFreeChartEntity(org.jfree.chart.entity.JFreeChartEntity) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) EntityCollection(org.jfree.chart.entity.EntityCollection) PlotRenderingInfo(org.jfree.chart.plot.PlotRenderingInfo) Rectangle2D(java.awt.geom.Rectangle2D) Iterator(java.util.Iterator) Title(org.jfree.chart.title.Title) TextTitle(org.jfree.chart.title.TextTitle) LegendTitle(org.jfree.chart.title.LegendTitle) Paint(java.awt.Paint)

Aggregations

AlphaComposite (java.awt.AlphaComposite)1 BasicStroke (java.awt.BasicStroke)1 Composite (java.awt.Composite)1 Paint (java.awt.Paint)1 Shape (java.awt.Shape)1 Stroke (java.awt.Stroke)1 Rectangle2D (java.awt.geom.Rectangle2D)1 Iterator (java.util.Iterator)1 EntityCollection (org.jfree.chart.entity.EntityCollection)1 JFreeChartEntity (org.jfree.chart.entity.JFreeChartEntity)1 ChartProgressEvent (org.jfree.chart.event.ChartProgressEvent)1 PlotRenderingInfo (org.jfree.chart.plot.PlotRenderingInfo)1 LegendTitle (org.jfree.chart.title.LegendTitle)1 TextTitle (org.jfree.chart.title.TextTitle)1 Title (org.jfree.chart.title.Title)1