| 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 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
public class ChartImage { |
| 21 | 0 | private final static Logger logger = Logger.getLogger("sf.net.statcvs"); |
| 22 | |
|
| 23 | 0 | |
| 24 | |
|
| 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 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | |
| 41 | 0 | |
| 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 | |
|
| 50 | 0 | } |
| 51 | |
|
| 52 | |
|
| 53 | 0 | |
| 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; |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
|
| 70 | 0 | |
| 71 | |
|
| 72 | |
public String getURL() { |
| 73 | 0 | return this.fileName; |
| 74 | |
} |
| 75 | |
|
| 76 | |
|
| 77 | 0 | |
| 78 | |
|
| 79 | |
public String getFullTitle() { |
| 80 | 0 | return this.title; |
| 81 | |
} |
| 82 | |
|
| 83 | |
|
| 84 | 0 | |
| 85 | |
|
| 86 | |
public int getWidth() { |
| 87 | 0 | return this.size.width; |
| 88 | |
} |
| 89 | |
|
| 90 | |
|
| 91 | 0 | |
| 92 | |
|
| 93 | |
public int getHeight() { |
| 94 | 0 | return this.size.height; |
| 95 | |
} |
| 96 | |
} |