00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.benchmarks.timit.util.charts;
00032
00033 import java.awt.Graphics2D;
00034 import java.awt.Rectangle;
00035 import java.io.File;
00036 import java.io.FileOutputStream;
00037 import java.io.IOException;
00038 import java.io.OutputStream;
00039 import java.io.OutputStreamWriter;
00040 import java.io.Writer;
00041 import java.lang.reflect.Constructor;
00042 import java.lang.reflect.Method;
00043
00044 import org.jdom.Element;
00045 import org.jfree.chart.JFreeChart;
00046 import org.objectweb.proactive.benchmarks.timit.TimIt;
00047 import org.objectweb.proactive.benchmarks.timit.config.ConfigChart;
00048 import org.objectweb.proactive.benchmarks.timit.util.BenchmarkStatistics;
00049 import org.w3c.dom.DOMImplementation;
00050
00056 public class Utilities {
00057
00069 public static void generatingCharts(Element eTimitResult,
00070 BenchmarkStatistics bstats, ConfigChart[] charts) {
00071
00072 if( charts == null ) return;
00073 TimIt.message(2, "Generating charts...");
00074 String className = null;
00075
00076 for (ConfigChart cChart : charts) {
00077 TimIt.message(4, "Generating " + cChart.get("title") + " ["
00078 + cChart.get("subtitle") + "]" + "...");
00079 try {
00080 className = Utilities.class.getPackage().getName() + "."
00081 + cChart.get("type");
00082 Class chartClass = Class.forName(className);
00083 Chart chart = (Chart) chartClass.newInstance();
00084 chart.generateChart(eTimitResult, bstats, cChart);
00085
00086 } catch (ClassNotFoundException e) {
00087 System.err.println(" Fail: Unknown chart type: " + className);
00088 } catch (InstantiationException e) {
00089 e.printStackTrace();
00090 } catch (IllegalAccessException e) {
00091 e.printStackTrace();
00092 }
00093 }
00094 }
00095
00108 public static void saveChartAsSVG(JFreeChart chart, Rectangle bounds,
00109 File svgFile) throws IOException {
00110 try {
00111 Class GDI = Class
00112 .forName("org.apache.batik.dom.GenericDOMImplementation");
00113
00114
00115 Method getDOMImplementation = GDI.getMethod("getDOMImplementation",
00116 new Class[0]);
00117 DOMImplementation domImpl = (DOMImplementation) getDOMImplementation
00118 .invoke(null, new Object[0]);
00119
00120 org.w3c.dom.Document document = domImpl.createDocument(null, "svg",
00121 null);
00122
00123
00124 Class SG2D = Class.forName("org.apache.batik.svggen.SVGGraphics2D");
00125 Method streamMethod = SG2D.getMethod("stream", new Class[] {
00126 Writer.class, boolean.class });
00127 Constructor SG2DConstr = SG2D
00128 .getConstructor(new Class[] { org.w3c.dom.Document.class });
00129 Object svgGenerator = SG2DConstr.newInstance(document);
00130
00131
00132 chart.draw((Graphics2D) svgGenerator, bounds);
00133
00134
00135 OutputStream outputStream = new FileOutputStream(svgFile);
00136 Writer out = new OutputStreamWriter(outputStream, "UTF-8");
00137 streamMethod.invoke(svgGenerator,
00138 new Object[] { out, true });
00139 outputStream.flush();
00140 outputStream.close();
00141 out.close();
00142
00143 } catch (Exception e) {
00144 e.printStackTrace();
00145 }
00146 }
00147 }