KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > jfreechart > JFreeChartEngine


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Aug 15, 2005
14  * @author James Dixon
15  *
16  */

17
18 package org.pentaho.plugin.jfreechart;
19
20 import java.awt.Color JavaDoc;
21 import java.awt.Font JavaDoc;
22 import java.awt.GradientPaint JavaDoc;
23 import java.awt.Image JavaDoc;
24 import java.awt.Paint JavaDoc;
25 import java.awt.TexturePaint JavaDoc;
26 import java.awt.geom.Rectangle2D JavaDoc;
27 import java.awt.image.BufferedImage JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.FileOutputStream JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.io.OutputStreamWriter JavaDoc;
33 import java.io.PrintWriter JavaDoc;
34 import java.io.Writer JavaDoc;
35 import java.net.MalformedURLException JavaDoc;
36 import java.net.URL JavaDoc;
37 import java.util.TimeZone JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.List JavaDoc;
40
41 import javax.imageio.ImageIO JavaDoc;
42
43 import org.apache.batik.dom.GenericDOMImplementation;
44 import org.apache.batik.svggen.SVGGraphics2D;
45 import org.dom4j.Node;
46 import org.jfree.chart.ChartRenderingInfo;
47 import org.jfree.chart.ChartUtilities;
48 import org.jfree.chart.JFreeChart;
49 import org.jfree.chart.axis.CategoryAxis;
50 import org.jfree.chart.axis.DateAxis;
51 import org.jfree.chart.axis.NumberAxis;
52 import org.jfree.chart.axis.NumberAxis3D;
53 import org.jfree.chart.axis.ValueAxis;
54 import org.jfree.chart.labels.ItemLabelAnchor;
55 import org.jfree.chart.labels.ItemLabelPosition;
56 import org.jfree.chart.labels.PieToolTipGenerator;
57 import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
58 import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
59 import org.jfree.chart.labels.StandardXYToolTipGenerator;
60 import org.jfree.chart.labels.StandardPieToolTipGenerator;
61 import org.jfree.chart.plot.CategoryPlot;
62 import org.jfree.chart.plot.DefaultDrawingSupplier;
63 import org.jfree.chart.plot.MeterInterval;
64 import org.jfree.chart.plot.MeterPlot;
65 import org.jfree.chart.plot.MultiplePiePlot;
66 import org.jfree.chart.plot.PiePlot;
67 import org.jfree.chart.plot.PiePlot3D;
68 import org.jfree.chart.plot.Plot;
69 import org.jfree.chart.plot.PlotOrientation;
70 import org.jfree.chart.plot.XYPlot;
71 import org.jfree.chart.renderer.category.AreaRenderer;
72 import org.jfree.chart.renderer.category.BarRenderer;
73 import org.jfree.chart.renderer.category.BarRenderer3D;
74 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
75 import org.jfree.chart.renderer.category.LineRenderer3D;
76 import org.jfree.chart.renderer.category.StackedAreaRenderer;
77 import org.jfree.chart.renderer.category.StackedBarRenderer;
78 import org.jfree.chart.renderer.category.StackedBarRenderer3D;
79 import org.jfree.chart.renderer.xy.XYItemRenderer;
80 import org.jfree.chart.renderer.xy.XYAreaRenderer;
81 import org.jfree.chart.renderer.xy.XYDifferenceRenderer;
82 import org.jfree.chart.renderer.xy.XYDotRenderer;
83 import org.jfree.chart.renderer.xy.XYLine3DRenderer;
84 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
85 import org.jfree.chart.renderer.xy.XYStepRenderer;
86 import org.jfree.chart.renderer.xy.XYStepAreaRenderer;
87 import org.jfree.chart.title.TextTitle;
88 import org.jfree.chart.urls.PieURLGenerator;
89 import org.jfree.chart.urls.StandardCategoryURLGenerator;
90 import org.jfree.chart.urls.StandardXYURLGenerator;
91 import org.jfree.chart.urls.StandardPieURLGenerator;
92 import org.jfree.data.Range;
93 import org.jfree.data.general.Dataset;
94 import org.jfree.ui.RectangleEdge;
95 import org.jfree.ui.TextAnchor;
96 import org.jfree.util.TableOrder;
97 import org.pentaho.core.repository.ISolutionRepository;
98 import org.pentaho.core.session.IPentahoSession;
99 import org.pentaho.core.system.PentahoSystem;
100 import org.pentaho.messages.Messages;
101 import org.pentaho.messages.util.LocaleHelper;
102 import org.pentaho.util.logging.ILogger;
103 import org.w3c.dom.Document JavaDoc;
104
105 public class JFreeChartEngine {
106
107     public static final int OUTPUT_PNG = 1;
108
109     public static final int OUTPUT_SVG = 2;
110
111     // Node names
112
private static final String JavaDoc X1_NODE_NAME = "x1"; //$NON-NLS-1$
113

114     private static final String JavaDoc Y1_NODE_NAME = "y1"; //$NON-NLS-1$
115

116     private static final String JavaDoc X2_NODE_NAME = "x2"; //$NON-NLS-1$
117

118     private static final String JavaDoc Y2_NODE_NAME = "y2"; //$NON-NLS-1$
119

120     private static final String JavaDoc COLOR1_NODE_NAME = "color1"; //$NON-NLS-1$
121

122     private static final String JavaDoc COLOR2_NODE_NAME = "color2"; //$NON-NLS-1$
123

124     private static final String JavaDoc CYCLIC_NODE_NAME = "cyclic"; //$NON-NLS-1$
125

126     private static final String JavaDoc TEXTURE_IMAGE_NODE_NAME = "texture-image"; //$NON-NLS-1$
127

128     private static final String JavaDoc FONT_FAMILY_NODE_NAME = "font-family"; //$NON-NLS-1$
129

130     private static final String JavaDoc SIZE_NODE_NAME = "size"; //$NON-NLS-1$
131

132     private static final String JavaDoc IS_ITALIC_NODE_NAME = "is-italic"; //$NON-NLS-1$
133

134     private static final String JavaDoc IS_BOLD_NODE_NAME = "is-bold"; //$NON-NLS-1$
135

136     public static final int UNDEFINED_CHART_TYPE = -1;
137
138     public static final int DIAL_CHART_TYPE = 0;
139
140     public static final int THERMOMETER_CHART_TYPE = 1;
141
142     public static final int PIE_CHART_TYPE = 2;
143
144     public static final int PIE_GRID_CHART_TYPE = 3;
145
146     public static final int BAR_CHART_TYPE = 4;
147
148     public static final int LINE_CHART_TYPE = 5;
149
150     public static final int AREA_CHART_TYPE = 6;
151
152     public static final int STEP_CHART_TYPE = 7;
153
154     public static final int STEP_AREA_CHART_TYPE = 8;
155
156     public static final int DIFFERENCE_CHART_TYPE = 9;
157
158     public static final int DOT_CHART_TYPE = 10;
159
160     /**
161      * Creates a JFreeChart object from a dial definition object. All of the
162      * settings for the dial image are defined by the dial definition.
163      *
164      * @param widget
165      * The dial definition object.
166      * @param title
167      * The dial title.
168      * @param units
169      * The dial units
170      * @return A JFreeChart object for the dial
171      */

172     private static JFreeChart createDial(DialWidgetDefinition widget, String JavaDoc title, String JavaDoc units) {
173         MeterPlot meter = new MeterPlot(widget);
174
175         updatePlot(meter, widget);
176         meter.setUnits(units);
177
178         meter.setValuePaint(widget.getValuePaint());
179         meter.setTickPaint(widget.getTickPaint());
180         int tickSize = widget.getTickSize();
181         if (tickSize == 0) {
182             meter.setTickLabelsVisible(false);
183         } else {
184             meter.setTickLabelsVisible(true);
185             meter.setTickSize(tickSize);
186         }
187         if (widget.getValueFont() != null) {
188             meter.setValueFont(widget.getValueFont());
189         } else {
190             meter.setValuePaint( getTransparent() );
191         }
192         // TODO support title fonts in the definition
193
Font JavaDoc titleFont = widget.getTitleFont();
194         
195         JFreeChart chart = new JFreeChart(title, titleFont, meter, false);
196
197         // TODO support any other MeterPlot properties
198

199         return chart;
200     }
201
202     private static JFreeChart createXYSeriesCollectionChart(XYSeriesCollectionChartDefinition chartDefinition) {
203         JFreeChart chart = null;
204         // TODO Make the following accessible from the chartDefinition
205
String JavaDoc domainAxisLabel = null;
206         String JavaDoc rangeAxisLabel = null;
207         boolean tooltips = true;
208         boolean urls = true;
209         // -----------------------------------------------------------
210

211         String JavaDoc title = chartDefinition.getTitle();
212         boolean legend = chartDefinition.isLegendIncluded();
213
214         NumberAxis domainAxis = chartDefinition.isThreeD() ? new NumberAxis3D(domainAxisLabel) : new NumberAxis(domainAxisLabel);
215         domainAxis.setAutoRangeIncludesZero( chartDefinition.isDomainIncludesZero() );
216         domainAxis.setAutoRangeStickyZero( chartDefinition.isDomainStickyZero() );
217         ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
218         
219         XYItemRenderer renderer = null;
220         switch (chartDefinition.getChartType()) {
221         case LINE_CHART_TYPE:
222             renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false);
223             break;
224         case AREA_CHART_TYPE:
225             renderer = new XYAreaRenderer();
226             break;
227         case STEP_CHART_TYPE:
228             renderer = new XYStepRenderer();
229             break;
230         case STEP_AREA_CHART_TYPE:
231             renderer = new XYStepAreaRenderer();
232             break;
233         case DIFFERENCE_CHART_TYPE:
234             renderer = new XYDifferenceRenderer();
235             break;
236         case DOT_CHART_TYPE:
237             renderer = new XYDotRenderer();
238             break;
239         default:
240             break;
241         }
242         if (tooltips) {
243             renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
244         }
245         if (urls) {
246             renderer.setURLGenerator(new StandardXYURLGenerator());
247         }
248
249         XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
250         updatePlot(plot, chartDefinition);
251
252         chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
253
254         return chart;
255
256     }
257
258     private static JFreeChart createTimeSeriesCollectionChart(TimeSeriesCollectionChartDefinition chartDefinition) {
259         JFreeChart chart = null;
260         // TODO Make the following accessible from the chartDefinition
261
String JavaDoc domainAxisLabel = null;
262         String JavaDoc rangeAxisLabel = null;
263         boolean tooltips = true;
264         boolean urls = true;
265         // -----------------------------------------------------------
266

267         String JavaDoc title = chartDefinition.getTitle();
268         boolean legend = chartDefinition.isLegendIncluded();
269
270         DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault());
271         ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel);
272         
273         XYItemRenderer renderer = null;
274         switch (chartDefinition.getChartType()) {
275         case LINE_CHART_TYPE:
276             renderer = chartDefinition.isThreeD() ? new XYLine3DRenderer() : new XYLineAndShapeRenderer(true, false);
277             break;
278         case AREA_CHART_TYPE:
279             renderer = new XYAreaRenderer();
280             break;
281         case STEP_CHART_TYPE:
282             renderer = new XYStepRenderer();
283             break;
284         case STEP_AREA_CHART_TYPE:
285             renderer = new XYStepAreaRenderer();
286             break;
287         case DIFFERENCE_CHART_TYPE:
288             renderer = new XYDifferenceRenderer();
289             break;
290         case DOT_CHART_TYPE:
291             renderer = new XYDotRenderer();
292             break;
293         default:
294             break;
295         }
296         if (tooltips) {
297             renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
298         }
299         if (urls) {
300             renderer.setURLGenerator(new StandardXYURLGenerator());
301         }
302
303         XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer);
304         updatePlot(plot, chartDefinition);
305
306         chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
307
308         return chart;
309
310     }
311
312     private static JFreeChart createCategoryDatasetChart(CategoryDatasetChartDefinition chartDefinition) {
313         JFreeChart chart = null;
314         switch (chartDefinition.getChartType()) {
315         case BAR_CHART_TYPE:
316             chart = createBarChart(chartDefinition);
317             break;
318         case LINE_CHART_TYPE:
319             chart = createLineChart(chartDefinition);
320             break;
321         case PIE_GRID_CHART_TYPE:
322             chart = createMultiplePieChart(chartDefinition);
323             break;
324         case AREA_CHART_TYPE:
325             chart = createAreaChart(chartDefinition);
326             break;
327         default:
328             break;
329         }
330         return chart;
331     }
332
333     private static JFreeChart createPieDatasetChart(PieDatasetChartDefinition chartDefinition) {
334         // TODO Make the following accessible from the chartDefinition
335
boolean tooltips = true;
336         boolean urls = true;
337         // -----------------------------------------------------------
338

339         String JavaDoc title = chartDefinition.getTitle();
340         boolean legend = chartDefinition.isLegendIncluded();
341
342         PiePlot plot = null;
343         plot = chartDefinition.isThreeD() ? new PiePlot3D(chartDefinition) : new PiePlot(chartDefinition);
344         updatePlot(plot, chartDefinition);
345         JFreeChart pieChart = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
346         TextTitle seriesTitle = new TextTitle("Series Title", new Font JavaDoc("SansSerif", Font.BOLD, 12)); //$NON-NLS-1$ //$NON-NLS-2$
347
seriesTitle.setPosition(RectangleEdge.BOTTOM);
348         pieChart.setTitle(title);
349         pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());
350
351         if (tooltips) {
352             PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
353             plot.setToolTipGenerator(tooltipGenerator);
354         }
355
356         if (urls) {
357             PieURLGenerator urlGenerator = new StandardPieURLGenerator();
358             plot.setURLGenerator(urlGenerator);
359         }
360
361         return pieChart;
362     }
363
364     private static void updatePlot(Plot plot, ChartDefinition chartDefinition) {
365         plot.setBackgroundPaint(chartDefinition.getPlotBackgroundPaint());
366         plot.setBackgroundImage(chartDefinition.getPlotBackgroundImage());
367
368         // create a custom palette if it was defined
369
if (chartDefinition.getPaintSequence() != null) {
370             DefaultDrawingSupplier drawingSupplier = new DefaultDrawingSupplier(chartDefinition.getPaintSequence(), DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
371                     DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
372             plot.setDrawingSupplier(drawingSupplier);
373         }
374         plot.setOutlineStroke(null); // TODO define outline stroke
375

376         if (plot instanceof CategoryPlot) {
377             CategoryPlot categoryPlot = (CategoryPlot) plot;
378             CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
379             categoryPlot.setOrientation(categoryDatasetChartDefintion.getOrientation());
380             CategoryAxis domainAxis = categoryPlot.getDomainAxis();
381             if (domainAxis != null) {
382                 domainAxis.setLabel(categoryDatasetChartDefintion.getDomainTitle());
383                 domainAxis.setLabelFont(categoryDatasetChartDefintion.getDomainTitleFont());
384                 domainAxis.setCategoryLabelPositions(categoryDatasetChartDefintion.getCategoryLabelPositions());
385             }
386             ValueAxis valueAxis = categoryPlot.getRangeAxis();
387             if (valueAxis != null) {
388                 valueAxis.setLabel(categoryDatasetChartDefintion.getRangeTitle());
389                 valueAxis.setLabelFont(categoryDatasetChartDefintion.getRangeTitleFont());
390             }
391         }
392         if (plot instanceof PiePlot) {
393             PiePlot pie = (PiePlot) plot;
394             PieDatasetChartDefinition pieDefinition = (PieDatasetChartDefinition) chartDefinition;
395             pie.setInteriorGap(pieDefinition.getInteriorGap());
396             pie.setStartAngle(pieDefinition.getStartAngle());
397             pie.setLabelFont(pieDefinition.getLabelFont());
398             if (pieDefinition.getLabelPaint() != null) {
399                 pie.setLabelPaint(pieDefinition.getLabelPaint());
400             }
401             pie.setLabelBackgroundPaint(pieDefinition.getLabelBackgroundPaint());
402             if( pieDefinition.isLegendIncluded() ) {
403                 StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0}"); //$NON-NLS-1$
404
pie.setLegendLabelGenerator(labelGen);
405             }
406             
407             pie.setLabelGap(pieDefinition.getLabelGap());
408             if (!pieDefinition.isDisplayLabels()) {
409                 pie.setLabelGenerator(null);
410             } else {
411                     if( pieDefinition.isLegendIncluded() ) {
412                         StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{1} ({2})"); //$NON-NLS-1$
413
pie.setLabelGenerator(labelGen);
414                     } else {
415                         StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator("{0} = {1} ({2})"); //$NON-NLS-1$
416
pie.setLabelGenerator(labelGen);
417                     }
418             }
419         }
420         if (plot instanceof MultiplePiePlot) {
421             MultiplePiePlot pies = (MultiplePiePlot) plot;
422             CategoryDatasetChartDefinition categoryDatasetChartDefintion = (CategoryDatasetChartDefinition) chartDefinition;
423             pies.setDataset(categoryDatasetChartDefintion);
424         }
425         if (plot instanceof MeterPlot) {
426             MeterPlot meter = (MeterPlot) plot;
427             DialWidgetDefinition widget = (DialWidgetDefinition) chartDefinition;
428             List JavaDoc intervals = widget.getIntervals();
429             Iterator JavaDoc intervalIterator = intervals.iterator();
430             while (intervalIterator.hasNext()) {
431                 MeterInterval interval = (MeterInterval) intervalIterator.next();
432                 meter.addInterval(interval);
433             }
434
435             meter.setNeedlePaint(widget.getNeedlePaint());
436             meter.setDialShape(widget.getDialShape());
437             meter.setDialBackgroundPaint(widget.getPlotBackgroundPaint());
438             meter.setRange(new Range(widget.getMinimum(), widget.getMaximum()));
439
440         }
441         if (plot instanceof XYPlot) {
442             XYPlot xyPlot = (XYPlot) plot;
443             if (chartDefinition instanceof XYSeriesCollectionChartDefinition) {
444                 XYSeriesCollectionChartDefinition xySeriesCollectionChartDefintion = (XYSeriesCollectionChartDefinition) chartDefinition;
445                 xyPlot.setOrientation(xySeriesCollectionChartDefintion.getOrientation());
446                 ValueAxis domainAxis = xyPlot.getDomainAxis();
447                 if (domainAxis != null) {
448                     domainAxis.setLabel(xySeriesCollectionChartDefintion.getDomainTitle());
449                     domainAxis.setLabelFont(xySeriesCollectionChartDefintion.getDomainTitleFont());
450                     domainAxis.setVerticalTickLabels(xySeriesCollectionChartDefintion.isDomainVerticalTickLabels());
451                 }
452                 ValueAxis rangeAxis = xyPlot.getRangeAxis();
453                 if (rangeAxis != null) {
454                     rangeAxis.setLabel(xySeriesCollectionChartDefintion.getRangeTitle());
455                     rangeAxis.setLabelFont(xySeriesCollectionChartDefintion.getRangeTitleFont());
456                 }
457             } else if (chartDefinition instanceof TimeSeriesCollectionChartDefinition) {
458                 TimeSeriesCollectionChartDefinition timeSeriesCollectionChartDefintion = (TimeSeriesCollectionChartDefinition) chartDefinition;
459                 xyPlot.setOrientation(timeSeriesCollectionChartDefintion.getOrientation());
460                 ValueAxis domainAxis = xyPlot.getDomainAxis();
461                 if (domainAxis != null) {
462                     domainAxis.setLabel(timeSeriesCollectionChartDefintion.getDomainTitle());
463                     domainAxis.setLabelFont(timeSeriesCollectionChartDefintion.getDomainTitleFont());
464                     domainAxis.setVerticalTickLabels(timeSeriesCollectionChartDefintion.isDomainVerticalTickLabels());
465                 }
466                 ValueAxis rangeAxis = xyPlot.getRangeAxis();
467                 if (rangeAxis != null) {
468                     rangeAxis.setLabel(timeSeriesCollectionChartDefintion.getRangeTitle());
469                     rangeAxis.setLabelFont(timeSeriesCollectionChartDefintion.getRangeTitleFont());
470                 }
471             }
472         }
473     }
474
475     private static JFreeChart createMultiplePieChart(CategoryDatasetChartDefinition chartDefinition) {
476         // TODO Make the following accessible from the chartDefinition
477
TableOrder order = TableOrder.BY_ROW;
478         // boolean tooltips = true;
479
// boolean urls = true;
480
// -----------------------------------------------------------
481

482         String JavaDoc title = chartDefinition.getTitle();
483         boolean legend = chartDefinition.isLegendIncluded();
484
485         if (order == null) {
486             throw new IllegalArgumentException JavaDoc(Messages.getString("JFreeChartEngine.ERROR_0001_NULL_ORDER_ARGUMENT")); //$NON-NLS-1$
487
}
488         MultiplePiePlot plot = new MultiplePiePlot(chartDefinition);
489         updatePlot(plot, chartDefinition);
490         plot.setDataExtractOrder(order);
491
492         JFreeChart pieChart = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
493         TextTitle seriesTitle = new TextTitle("Series Title", new Font JavaDoc("SansSerif", Font.BOLD, 12)); //$NON-NLS-1$ //$NON-NLS-2$
494
seriesTitle.setPosition(RectangleEdge.BOTTOM);
495         pieChart.setTitle(seriesTitle);
496         pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());
497         plot.setPieChart(pieChart);
498
499         // if (tooltips) {
500
// PieToolTipGenerator tooltipGenerator = new
501
// StandardPieToolTipGenerator();
502
// PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
503
// pp.setToolTipGenerator(tooltipGenerator);
504
// }
505

506         // if (urls) {
507
// PieURLGenerator urlGenerator = new StandardPieURLGenerator();
508
// PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
509
// pp.setURLGenerator(urlGenerator);
510
// }
511

512         return pieChart;
513     }
514
515     private static JFreeChart createLineChart(CategoryDatasetChartDefinition chartDefinition) {
516         // TODO Make the following accessible from the chartDefinition
517
String JavaDoc categoryAxisLabel = null;
518         String JavaDoc valueAxisLabel = null;
519         boolean tooltips = true;
520         boolean urls = true;
521         // -----------------------------------------------------------
522

523         String JavaDoc title = chartDefinition.getTitle();
524         boolean legend = chartDefinition.isLegendIncluded();
525
526         CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
527         ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
528         LineAndShapeRenderer renderer = chartDefinition.isThreeD() ? new LineRenderer3D() : new LineAndShapeRenderer(true, false);
529         if (tooltips) {
530             renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
531         }
532         if (urls) {
533             renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
534         }
535
536         CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
537         updatePlot(plot, chartDefinition);
538
539         JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
540
541         return chart;
542
543     }
544
545     private static JFreeChart createBarChart(CategoryDatasetChartDefinition chartDefinition) {
546         // TODO Make the following accessible from the chartDefinition
547
String JavaDoc categoryAxisLabel = null;
548         String JavaDoc valueAxisLabel = null;
549         boolean tooltips = true;
550         boolean urls = true;
551         // -----------------------------------------------------------
552

553         String JavaDoc title = chartDefinition.getTitle();
554         boolean legend = chartDefinition.isLegendIncluded();
555         PlotOrientation orientation = chartDefinition.getOrientation();
556
557         CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
558         ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
559         BarRenderer renderer = null;
560         // Determine the type of renderer to use
561
if (chartDefinition.isStacked() || chartDefinition.isThreeD()) {
562             if (chartDefinition.isStacked() && chartDefinition.isThreeD()) {
563                 renderer = new StackedBarRenderer3D();
564             } else if (chartDefinition.isStacked()) {
565                 renderer = new StackedBarRenderer();
566             } else {
567                 renderer = new BarRenderer3D();
568             }
569         } else {
570             renderer = new BarRenderer();
571         }
572         if (orientation == PlotOrientation.HORIZONTAL) {
573             ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
574             renderer.setPositiveItemLabelPosition(position1);
575             ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT);
576             renderer.setNegativeItemLabelPosition(position2);
577         } else if (orientation == PlotOrientation.VERTICAL) {
578             ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
579             renderer.setPositiveItemLabelPosition(position1);
580             ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
581             renderer.setNegativeItemLabelPosition(position2);
582         }
583         if (tooltips) {
584             renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
585         }
586         if (urls) {
587             renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
588         }
589
590         CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
591         updatePlot(plot, chartDefinition);
592
593         JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
594
595         return chart;
596
597     }
598
599     private static JFreeChart createAreaChart(CategoryDatasetChartDefinition chartDefinition) {
600         // TODO Make the following accessible from the chartDefinition
601
String JavaDoc categoryAxisLabel = null;
602         String JavaDoc valueAxisLabel = null;
603         boolean tooltips = true;
604         boolean urls = true;
605         // -----------------------------------------------------------
606

607         String JavaDoc title = chartDefinition.getTitle();
608         boolean legend = chartDefinition.isLegendIncluded();
609
610         CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
611         ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
612
613         AreaRenderer renderer = chartDefinition.isStacked() ? new StackedAreaRenderer() : new AreaRenderer();
614         if (tooltips) {
615             renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
616         }
617         if (urls) {
618             renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
619         }
620
621         CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
622         updatePlot(plot, chartDefinition);
623
624         JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
625
626         return chart;
627     }
628
629     /**
630      * Create a PNG image file from a JFreeChart object
631      *
632      * @param chart
633      * The chart object to create an image from
634      * @param path
635      * The path and name of the image file to create
636      * @param width
637      * The width of the image in pixels
638      * @param height
639      * The height of the image in pixels
640      * @param writer
641      * A writer for the iamge map to be written to
642      * @throws IOException
643      */

644     private static void saveChartAsPNG(JFreeChart chart, String JavaDoc path, int width, int height, PrintWriter JavaDoc writer, ChartRenderingInfo info) throws IOException JavaDoc {
645         File JavaDoc file = new File JavaDoc(path + ".png"); //$NON-NLS-1$
646
ChartUtilities.saveChartAsPNG(file, chart, width, height, info);
647
648         // TODO support tool tip generators
649

650         // TODO support URL fragment generators
651

652         // TODO: make the image map name unique on the page
653
if (writer != null) {
654             ChartUtilities.writeImageMap(writer, "map-name", info, true); //$NON-NLS-1$
655
}
656     }
657
658     /**
659      * Create an SVG image file from a JFreeChart object
660      *
661      * @param chart
662      * The chart object to create an image from
663      * @param path
664      * The path and name of the image file to create
665      * @param width
666      * The width of the image in pixels
667      * @param height
668      * The height of the image in pixels
669      * @throws IOException
670      */

671     private static void saveChartAsSVG(JFreeChart chart, String JavaDoc path, int width, int height, ChartRenderingInfo info) throws IOException JavaDoc {
672         // THE FOLLOWING CODE BASED ON THE EXAMPLE IN THE BATIK DOCUMENTATION...
673
// Get a DOMImplementation
674
org.w3c.dom.DOMImplementation JavaDoc domImpl = GenericDOMImplementation.getDOMImplementation();
675         // Create an instance of org.w3c.dom.Document
676
Document JavaDoc document = domImpl.createDocument(null, "svg", null); //$NON-NLS-1$
677
// Create an instance of the SVG Generator
678
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
679         // set the precision to avoid a null pointer exception in Batik 1.5
680
svgGenerator.getGeneratorContext().setPrecision(6);
681         // Ask the chart to render into the SVG Graphics2D implementation
682
chart.draw(svgGenerator, new Rectangle2D.Double JavaDoc(0, 0, width, height), info);
683         // Finally, stream out SVG to a file using UTF-8 character to byte
684
// encoding
685
boolean useCSS = true;
686         Writer JavaDoc out = new OutputStreamWriter JavaDoc(new FileOutputStream JavaDoc(new File JavaDoc(path + ".svg")), LocaleHelper.getSystemEncoding()); //$NON-NLS-1$
687
svgGenerator.stream(out, useCSS);
688     }
689
690     /**
691      * Create an image file from a JFreeChart object
692      *
693      * @param chart
694      * The chart object to create an image from
695      * @param path
696      * The path and name of the image file to create
697      * @param width
698      * The width of the image in pixels
699      * @param height
700      * The height of the image in pixels
701      * @param outputType
702      * The type of the image to create, OUPUT_PNG or OUTPUT_SVG
703      * @param writer
704      * @throws IOException
705      */

706     private static void saveChart(JFreeChart chart, String JavaDoc path, int width, int height, int outputType, PrintWriter JavaDoc writer, ChartRenderingInfo info) throws IOException JavaDoc {
707         if (outputType == OUTPUT_PNG) {
708             saveChartAsPNG(chart, path, width, height, writer, info);
709         } else if (outputType == OUTPUT_SVG) {
710             saveChartAsSVG(chart, path, width, height, info);
711         }
712         // TODO support other image types, e.g. JPG, GIF
713
}
714
715     /**
716      * Create an image file using dataset object. This method takes a dataset
717      * object, e.g. a DialWidgetDefinition, creates a JFreeChart object from it,
718      * and then creates an image file.
719      *
720      * @param dataset
721      * The
722      * @param title
723      * The title of the chart
724      * @param units
725      * The units of the chart value
726      * @param fileName
727      * The path and file of the image to create
728      * @param width
729      * The width of the image to create
730      * @param height
731      * The height of the image to create
732      * @param outputType
733      * The type of the image to create
734      * @param writer
735      * A writer to writer the image map into
736      * @param logger
737      * The logger to log any messages to
738      */

739     public static void saveChart(Dataset dataset, String JavaDoc title, String JavaDoc units, String JavaDoc fileName, int width, int height, int outputType, PrintWriter JavaDoc writer, ILogger logger) {
740         ChartRenderingInfo info = new ChartRenderingInfo();
741         saveChart(dataset, title, units, fileName, width, height, outputType, writer, info, logger);
742     }
743
744     /**
745      * Create an image file using dataset object. This method takes a dataset
746      * object, e.g. a DialWidgetDefinition, creates a JFreeChart object from it,
747      * and then creates an image file.
748      *
749      * @param dataset
750      * The
751      * @param title
752      * The title of the chart
753      * @param units
754      * The units of the chart value
755      * @param fileName
756      * The path and file of the image to create
757      * @param width
758      * The width of the image to create
759      * @param height
760      * The height of the image to create
761      * @param outputType
762      * The type of the image to create
763      * @param writer
764      * A writer to writer the image map into
765      * @param logger
766      * The logger to log any messages to
767      */

768     public static void saveChart(Dataset dataset, String JavaDoc title, String JavaDoc units, String JavaDoc fileName, int width, int height, int outputType, PrintWriter JavaDoc writer, ChartRenderingInfo info, ILogger logger) {
769
770         JFreeChart chart = null;
771         if (dataset instanceof DialWidgetDefinition) {
772             chart = createDial((DialWidgetDefinition) dataset, title, units);
773         } else if (dataset instanceof TimeSeriesCollectionChartDefinition) {
774             chart = createTimeSeriesCollectionChart((TimeSeriesCollectionChartDefinition) dataset);
775         } else if (dataset instanceof XYSeriesCollectionChartDefinition) {
776             chart = createXYSeriesCollectionChart((XYSeriesCollectionChartDefinition) dataset);
777         } else if (dataset instanceof CategoryDatasetChartDefinition) {
778             chart = createCategoryDatasetChart((CategoryDatasetChartDefinition) dataset);
779         } else if (dataset instanceof PieDatasetChartDefinition) {
780             chart = createPieDatasetChart((PieDatasetChartDefinition) dataset);
781         }
782         if (chart == null) {
783             logger.error(Messages.getString("ChartEngine.ERROR_0002_COULD_NOT_CREATE_CHART")); //$NON-NLS-1$
784
} else {
785             // TODO implement the ability to have "ImageTitle"s for subtitles
786
ChartDefinition chartDefinition = (ChartDefinition) dataset;
787             Iterator JavaDoc iter = chartDefinition.getSubtitles().iterator();
788             while (iter.hasNext()) {
789                 chart.addSubtitle(new TextTitle(iter.next().toString()));
790             }
791             chart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());
792             chart.setBackgroundImage(chartDefinition.getChartBackgroundImage());
793             chart.setBorderVisible(chartDefinition.isBorderVisible());
794             chart.setBorderPaint(chartDefinition.getBorderPaint());
795             chart.getTitle().setPosition(chartDefinition.getTitlePosition());
796             chart.getTitle().setFont(chartDefinition.getTitleFont());
797
798             // TODO implement
799
// chart.setBorderStroke(chartDefintion.getBorderStroke());
800
}
801         try {
802             String JavaDoc filePath = PentahoSystem.getApplicationContext().getFileOutputPath(fileName);
803             saveChart(chart, filePath, width, height, outputType, writer, info);
804         } catch (IOException JavaDoc e) {
805             logger.error(Messages.getString("ChartEngine.ERROR_0001_COULD_NOT_CREATE_CHART"), e); //$NON-NLS-1$
806
}
807     }
808
809     /**
810      * Creates a java.awt.Color object from an HTML color definition, eg #80dd3f
811      *
812      * @param htmlColor
813      * The color string
814      * @return A Color object
815      */

816     public static Color JavaDoc getColor(String JavaDoc htmlColor) {
817
818         return new Color JavaDoc(Integer.parseInt(htmlColor.substring(1, 3), 16), Integer.parseInt(htmlColor.substring(3, 5), 16), Integer.parseInt(htmlColor.substring(5), 16));
819     }
820
821     public static Color JavaDoc getTransparent( ) {
822             return new Color JavaDoc( 0, 0, 0, 0);
823     }
824     
825     /**
826      * Creates a java.awt.Paint object from an XML node from the dial definition
827      * document
828      *
829      * @param width
830      * of the chart
831      * @param height
832      * of the chart
833      * @param node
834      * XML Node from the dial definition
835      * @return Paint object defined by the node
836      */

837     public static Paint JavaDoc getPaint(Node node, int width, int height, IPentahoSession session) {
838         if (node == null) {
839             return null;
840         }
841         // TODO support gradient and texture paints
842
if (null != node.selectSingleNode("gradient")) { //$NON-NLS-1$
843
return getGradientPaint((node.selectSingleNode("gradient")), width, height); //$NON-NLS-1$
844
} else if (null != node.selectSingleNode("texture")) { //$NON-NLS-1$
845
return getTexturePaint((node.selectSingleNode("texture")), width, height, session); //$NON-NLS-1$
846
} else {
847             String JavaDoc htmlColor = node.getText();
848             return getPaint(htmlColor);
849         }
850
851     }
852
853     /**
854      * Creates a java.awt.GradientPaint object from an XML node from the dial
855      * definition document
856      *
857      * @param XML
858      * Node from the dial definition
859      * @param width
860      * of the chart
861      * @param height
862      * of the chart
863      * @return Paint object defined by the node / public static Paint
864      * getGradientPaint( Node node,int width, int height ) {
865      *
866      * if( node == null ) { return null; } Color
867      * firstColor=getColor((node.selectSingleNode("first-color")).getText().toString());
868      * //$NON-NLS-1$ Color
869      * secondColor=getColor((node.selectSingleNode("second-color")).getText().toString());
870      * //$NON-NLS-1$ boolean cyclic=true;
871      * if((node.selectSingleNode("cyclic")).getText().trim().equals("false")) {
872      * //$NON-NLS-1$ //$NON-NLS-2$ cyclic=false; } return new
873      * GradientPaint(0,0,firstColor,width-(width/2),height,secondColor,cyclic); }
874      */

875     /**
876      * Creates a java.awt.TexturePaint object from an XML node from the dial
877      * definition document
878      *
879      * @param XML
880      * Node from the dial definition
881      * @param width
882      * of the chart
883      * @param height
884      * of the chart
885      * @return Paint object defined by the node / public static Paint
886      * getTexturePaint( Node node, int width, int height ) {
887      *
888      * if( node == null ) { return null; } int rectWidth=width; int
889      * rectHeight=height; int x=0; int y=0; // Get Image try{ Node imageNode =
890      * node.selectSingleNode( "background-image" ); //$NON-NLS-1$ if( imageNode !=
891      * null ) { String imageName = imageNode.getText().toString(); String
892      * fileName = PentahoSystem.getApplicationContext().getSolutionPath(
893      * imageName ); int offset = fileName.lastIndexOf( "." ); //$NON-NLS-1$
894      * String type = offset == -1 ? "jpg" : fileName.substring(offset + 1);
895      * //$NON-NLS-1$
896      *
897      * BufferedImage image = new BufferedImage( width, height,
898      * BufferedImage.TYPE_INT_ARGB);
899      *
900      * ImageIO.write(image, type, new File( fileName ));
901      *
902      * Node rectangle= node.selectSingleNode("rectangle"); //$NON-NLS-1$ if(
903      * rectangle != null ) { Node tmpNode = rectangle.selectSingleNode("width");
904      * //$NON-NLS-1$ if( tmpNode != null ) {
905      * rectWidth=Integer.parseInt(tmpNode.getText().toString().trim());
906      * //$NON-NLS-1$ } tmpNode = rectangle.selectSingleNode("height");
907      * //$NON-NLS-1$ if( tmpNode != null ) {
908      * rectHeight=Integer.parseInt(tmpNode.getText().toString().trim());
909      * //$NON-NLS-1$ } tmpNode = rectangle.selectSingleNode("x"); //$NON-NLS-1$
910      * if( tmpNode != null ) {
911      * x=Integer.parseInt(tmpNode.getText().toString().trim()); //$NON-NLS-1$ }
912      * tmpNode = rectangle.selectSingleNode("y"); //$NON-NLS-1$ if( tmpNode !=
913      * null ) { y=Integer.parseInt(tmpNode.getText().toString().trim());
914      * //$NON-NLS-1$ } }
915      *
916      * Rectangle2D rect = new Rectangle2D.Double(x,y,rectWidth,rectHeight);
917      *
918      * return new TexturePaint(image,rect); }
919      *
920      * }catch(Exception e){e.printStackTrace();} return null; }
921      */

922     public static Font JavaDoc getFont(Node fontNode) {
923         Font JavaDoc font = null;
924         if (fontNode != null) {
925             String JavaDoc fontFamily = TextTitle.DEFAULT_FONT.getFamily();
926             int fontStyle = Font.PLAIN;
927             int fontSize = TextTitle.DEFAULT_FONT.getSize();
928
929             Node fontFamilyNode = fontNode.selectSingleNode(FONT_FAMILY_NODE_NAME);
930             if (fontFamilyNode != null && fontFamilyNode.getText().length() > 0) {
931                 fontFamily = fontFamilyNode.getText();
932             }
933             Node isBoldNode = fontNode.selectSingleNode(IS_BOLD_NODE_NAME);
934             if (isBoldNode != null) {
935                 boolean bold = Boolean.valueOf(isBoldNode.getText()).booleanValue();
936                 if (bold) {
937                     fontStyle += Font.BOLD;
938                 }
939             }
940             Node isItalicNode = fontNode.selectSingleNode(IS_ITALIC_NODE_NAME);
941             if (isItalicNode != null) {
942                 boolean italic = Boolean.valueOf(isItalicNode.getText()).booleanValue();
943                 if (italic) {
944                     fontStyle += Font.ITALIC;
945                 }
946             }
947             Node sizeNode = fontNode.selectSingleNode(SIZE_NODE_NAME);
948             if (sizeNode != null && sizeNode.getText().length() > 0) {
949                 fontSize = Integer.parseInt(sizeNode.getText());
950             }
951             font = new Font JavaDoc(fontFamily, fontStyle, fontSize);
952         }
953         return font;
954     }
955
956     /**
957      * Creates a java.awt.Paint object from an XML node from the dial definition
958      * document
959      *
960      * @param node
961      * XML Node from the chart definition
962      * @return Paint object defined by the node
963      */

964     public static Paint JavaDoc getPaint(Node node) {
965         if (node == null) {
966             return null;
967         }
968         // TODO support gradient and texture paints
969
String JavaDoc htmlColor = node.getText();
970         return getPaint(htmlColor);
971     }
972
973     /**
974      * Creates a java.awt.Paint object from an HTML color definition, eg #80ff3f
975      *
976      * @param htmlColor
977      * The color string
978      * @return Paint The Paint object for the requested color
979      */

980     public static Paint JavaDoc getPaint(String JavaDoc htmlColor) {
981
982         Color JavaDoc color = getColor(htmlColor);
983         
984         return color;
985     }
986
987     /**
988      * @param gradientNode
989      * root node that hold gradient information
990      * @return a gradientPaint implementation of Paint
991      */

992     public static Paint JavaDoc getGradientPaint(Node gradientNode, int width, int height) {
993
994         if (gradientNode == null) {
995             return null;
996         }
997         float x1 = 0;
998         float y1 = 0;
999         float x2 = width;
1000        float y2 = height;
1001
1002        if (gradientNode.selectSingleNode(X1_NODE_NAME) != null) {
1003            x1 = Float.parseFloat(gradientNode.selectSingleNode(X1_NODE_NAME).getText());
1004        }
1005        if (gradientNode.selectSingleNode(Y1_NODE_NAME) != null) {
1006            y1 = Float.parseFloat(gradientNode.selectSingleNode(Y1_NODE_NAME).getText());
1007        }
1008        if (gradientNode.selectSingleNode(X2_NODE_NAME) != null) {
1009            x2 = Float.parseFloat(gradientNode.selectSingleNode(X2_NODE_NAME).getText());
1010        }
1011        if (gradientNode.selectSingleNode(Y2_NODE_NAME) != null) {
1012            y2 = Float.parseFloat(gradientNode.selectSingleNode(Y2_NODE_NAME).getText());
1013        }
1014        Color JavaDoc color1 = getColor(gradientNode.selectSingleNode(COLOR1_NODE_NAME).getText());
1015        Color JavaDoc color2 = getColor(gradientNode.selectSingleNode(COLOR2_NODE_NAME).getText());
1016        boolean cyclic = false;
1017        if (gradientNode.selectSingleNode(CYCLIC_NODE_NAME) != null) {
1018            cyclic = Boolean.valueOf(gradientNode.selectSingleNode(CYCLIC_NODE_NAME).getText()).booleanValue();
1019        }
1020
1021        Paint JavaDoc paint = new GradientPaint JavaDoc(x1, y1, color1, x2, y2, color2, cyclic);
1022        return paint;
1023    }
1024
1025   
1026    /**
1027     * @param textureNode
1028     * root node that holds texture information
1029     * @return
1030     */

1031    public static Paint JavaDoc getTexturePaint(Node textureNode, int width, int height, IPentahoSession session) {
1032
1033        if (textureNode == null) {
1034            return null;
1035        }
1036        double x1 = 0.0;
1037        double y1 = 0.0;
1038        double x2 = width;
1039        double y2 = height;
1040        BufferedImage JavaDoc texture = (BufferedImage JavaDoc) getImage(textureNode.selectSingleNode(TEXTURE_IMAGE_NODE_NAME), session);
1041        if (textureNode.selectSingleNode(X1_NODE_NAME) != null) {
1042            x1 = Double.parseDouble(textureNode.selectSingleNode(X1_NODE_NAME).getText());
1043        }
1044        if (textureNode.selectSingleNode(Y1_NODE_NAME) != null) {
1045            y1 = Double.parseDouble(textureNode.selectSingleNode(Y1_NODE_NAME).getText());
1046        }
1047        if (textureNode.selectSingleNode(X2_NODE_NAME) != null) {
1048            x2 = Double.parseDouble(textureNode.selectSingleNode(X2_NODE_NAME).getText());
1049        }
1050        if (textureNode.selectSingleNode(Y2_NODE_NAME) != null) {
1051            y2 = Double.parseDouble(textureNode.selectSingleNode(Y2_NODE_NAME).getText());
1052        }
1053        Rectangle2D JavaDoc anchor = new Rectangle2D.Double JavaDoc(x1, y1, x2, y2);
1054
1055        Paint JavaDoc paint = new TexturePaint JavaDoc(texture, anchor);
1056        return paint;
1057    }
1058
1059    /**
1060     * @param chartBackgroundImageNode -
1061     * Node that contains a path to the images in its text element
1062     * @return the image
1063     */

1064    public static Image JavaDoc getImage(Node chartBackgroundImageNode, IPentahoSession session) {
1065        Image JavaDoc image = null;
1066        if (chartBackgroundImageNode != null && chartBackgroundImageNode.getText().length() > 0) {
1067          return getImage(chartBackgroundImageNode.getText(), session);
1068        }
1069        return image;
1070    }
1071    
1072    /**
1073     * @param imageName
1074     * String that contains a path to the image
1075     * @return the image
1076     */

1077    public static Image JavaDoc getImage(String JavaDoc imageName, IPentahoSession session) {
1078            Image JavaDoc image = null;
1079            ISolutionRepository repository = PentahoSystem.getSolutionRepository(session);
1080            InputStream JavaDoc is = repository.getResourceInputStream(imageName);
1081            try {
1082                image = ImageIO.read(is);
1083            } catch (IOException JavaDoc e) {
1084                // TODO Auto-generated catch block
1085
e.printStackTrace();
1086            }
1087            return image;
1088    }
1089    
1090}
1091
Popular Tags