1 28 package net.sf.jasperreports.engine.xml; 29 30 import java.awt.Color ; 31 32 import net.sf.jasperreports.engine.JRChartPlot; 33 import net.sf.jasperreports.engine.base.JRBaseChartPlot; 34 35 import org.jfree.chart.plot.PlotOrientation; 36 import org.xml.sax.Attributes ; 37 38 39 43 public class JRChartPlotFactory extends JRBaseFactory 44 { 45 46 private static final String ATTRIBUTE_backcolor = "backcolor"; 47 private static final String ATTRIBUTE_orientation = "orientation"; 48 private static final String ATTRIBUTE_backgroundAlpha = "backgroundAlpha"; 49 private static final String ATTRIBUTE_foregroundAlpha = "foregroundAlpha"; 50 private static final String ATTRIBUTE_labelRotation = "labelRotation"; 51 52 53 56 public Object createObject(Attributes atts) 57 { 58 JRChartPlot plot = (JRChartPlot) digester.peek(); 59 60 Color color = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_backcolor), Color.black); 61 if (color != null) 62 { 63 plot.setBackcolor(color); 64 } 65 66 String orientation = atts.getValue(ATTRIBUTE_orientation); 67 if (orientation != null && orientation.length() > 0) 68 plot.setOrientation((PlotOrientation)JRXmlConstants.getPlotOrientationMap().get(orientation)); 69 70 String foregroundAlpha = atts.getValue(ATTRIBUTE_foregroundAlpha); 71 if (foregroundAlpha != null && foregroundAlpha.length() > 0) 72 plot.setForegroundAlpha(Float.valueOf(foregroundAlpha).floatValue()); 73 74 String backgroundAlpha = atts.getValue(ATTRIBUTE_backgroundAlpha); 75 if (backgroundAlpha != null && backgroundAlpha.length() > 0) 76 plot.setBackgroundAlpha(Float.valueOf(backgroundAlpha).floatValue()); 77 78 String labelRotation = atts.getValue(ATTRIBUTE_labelRotation); 79 if (labelRotation != null && labelRotation.length() > 0) 80 plot.setLabelRotation(Double.valueOf(labelRotation).doubleValue()); 81 82 return plot; 83 } 84 85 public static class JRSeriesColorFactory extends JRBaseFactory 86 { 87 public static final String ATTRIBUTE_seriesOrder = "seriesOrder"; 88 public static final String ATTRIBUTE_color = "color"; 89 90 public Object createObject(Attributes atts) 91 { 92 int seriesIndex = -1; 93 Color color = null; 94 95 String seriesNumber = atts.getValue(ATTRIBUTE_seriesOrder); 96 if (seriesNumber != null && seriesNumber.length() > 0) 97 seriesIndex = Integer.valueOf(seriesNumber).intValue(); 98 99 String colorName = atts.getValue(ATTRIBUTE_color); 100 if (colorName != null && colorName.length() > 0) 101 color = JRXmlConstants.getColor(colorName, null); 102 103 return new JRBaseChartPlot.JRBaseSeriesColor(seriesIndex, color); 104 } 105 } 106 } 107 | Popular Tags |