Coverage Report - net.sf.statcvs.charts.ChartImage
 
Classes in this File Line Coverage Branch Coverage Complexity
ChartImage
0%
0/38
0%
0/4
1.5
 
 1  
 package net.sf.statcvs.charts;
 2  
 
 3  
 import java.awt.Color;
 4  
 import java.awt.Dimension;
 5  
 import java.io.File;
 6  
 import java.io.IOException;
 7  
 import java.util.logging.Logger;
 8  
 
 9  
 import org.jfree.chart.ChartUtilities;
 10  
 import org.jfree.chart.JFreeChart;
 11  
 
 12  
 /**
 13  
  * An image file for a chart.
 14  
  * 
 15  
  * TODO: Better integrate all charts with ReportConfig 
 16  
  * @author jentzsch
 17  
  * @author Richard Cyganiak (richard@cyganiak.de)
 18  
  * @version $Id: ChartImage.java,v 1.9 2009/03/14 11:08:35 benoitx Exp $
 19  
  */
 20  
 public class ChartImage {
 21  0
     private final static Logger logger = Logger.getLogger("sf.net.statcvs");
 22  
 
 23  0
 //    public final static Color BACKGROUND_COLOR = new Color(204, 204, 187);
 24  
 //    public final static Color PLOT_COLOR = new Color(100, 204, 187);
 25  0
     public final static Color BACKGROUND_COLOR = new Color(255, 255, 255);
 26  0
     public final static Color PLOT_COLOR = new Color(0xD0, 0xE0, 0xE0);
 27  
     
 28  
     private final String rootDirectory;
 29  
     private JFreeChart chart;
 30  0
     private final String fileName;
 31  
     private final Dimension size;
 32  
     private final String title;
 33  0
     private boolean written = false;
 34  
 
 35  
     /**
 36  
      * Creates a new ChartFile.
 37  
      * @param rootDirectory The report root directory with trailing slash
 38  
      * @param fileName The relative file name for the chart, with .png extension
 39  
      * @param title The chart's title
 40  0
      * @param chart The JFreeChart object to save as a file
 41  0
      * @param size width and height of the chart in pixels
 42  0
      */
 43  0
     public ChartImage(final String rootDirectory, final String fileName, final String title, final JFreeChart chart, final Dimension size) {
 44  0
         this.rootDirectory = rootDirectory;
 45  0
         this.fileName = fileName;
 46  0
         this.title = title;
 47  0
         this.chart = chart;
 48  0
         this.size = size;
 49  
         //        chart.setBackgroundPaint(BACKGROUND_COLOR);
 50  0
     }
 51  
 
 52  
     /**
 53  0
      * Writes the chart to disk as a PNG file.
 54  0
      */
 55  
     public void write() {
 56  0
         if (this.written) {
 57  0
             return;
 58  0
         }
 59  0
         logger.info("writing chart '" + this.title + "' to " + this.fileName);
 60  0
         try {
 61  0
             ChartUtilities.saveChartAsPNG(new File(rootDirectory + fileName), chart, size.width, size.height);
 62  0
         } catch (final IOException e) {
 63  0
             logger.warning("could not write chart '" + fileName + "': " + e);
 64  0
         }
 65  0
         this.written = true;
 66  0
         this.chart = null; // Free memory? Not sure if this has any effect ... 
 67  0
     }
 68  
 
 69  
     /**
 70  0
      * Returns the chart's URL, relative to the report root.
 71  
      */
 72  
     public String getURL() {
 73  0
         return this.fileName;
 74  
     }
 75  
 
 76  
     /**
 77  0
      * Returns the chart's title.
 78  
      */
 79  
     public String getFullTitle() {
 80  0
         return this.title;
 81  
     }
 82  
 
 83  
     /**
 84  0
      * Returns the chart's width in pixels.
 85  
      */
 86  
     public int getWidth() {
 87  0
         return this.size.width;
 88  
     }
 89  
 
 90  
     /**
 91  0
      * Returns the chart's height in pixels.
 92  
      */
 93  
     public int getHeight() {
 94  0
         return this.size.height;
 95  
     }
 96  
 }