1 28 package net.sf.jasperreports.engine.xml; 29 30 import java.awt.Color ; 31 import java.util.Collection ; 32 33 import net.sf.jasperreports.charts.util.JRAxisFormat; 34 import net.sf.jasperreports.engine.JRException; 35 import net.sf.jasperreports.engine.JRExpression; 36 import net.sf.jasperreports.engine.design.JRDesignChart; 37 import net.sf.jasperreports.engine.design.JRDesignGroup; 38 39 import org.xml.sax.Attributes ; 40 41 42 46 public class JRChartFactory extends JRBaseFactory 47 { 48 49 private static final String ATTRIBUTE_isShowLegend = "isShowLegend"; 50 private static final String ATTRIBUTE_evaluationTime = "evaluationTime"; 51 private static final String ATTRIBUTE_evaluationGroup = "evaluationGroup"; 52 private static final String ATTRIBUTE_hyperlinkType = "hyperlinkType"; 53 private static final String ATTRIBUTE_hyperlinkTarget = "hyperlinkTarget"; 54 private static final String ATTRIBUTE_bookmarkLevel = "bookmarkLevel"; 55 private static final String ATTRIBUTE_customizerClass = "customizerClass"; 56 57 58 61 public Object createObject(Attributes atts) 62 { 63 JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1); 64 Collection groupEvaluatedCharts = xmlLoader.getGroupEvaluatedCharts(); 65 66 JRDesignChart chart = (JRDesignChart) digester.peek(); 67 68 String isShowLegend = atts.getValue(ATTRIBUTE_isShowLegend); 69 if (isShowLegend != null && isShowLegend.length() > 0) 70 chart.setShowLegend(Boolean.valueOf(isShowLegend).booleanValue()); 71 72 Byte evaluationTime = (Byte )JRXmlConstants.getEvaluationTimeMap().get(atts.getValue(ATTRIBUTE_evaluationTime)); 73 if (evaluationTime != null) 74 { 75 chart.setEvaluationTime(evaluationTime.byteValue()); 76 } 77 if (chart.getEvaluationTime() == JRExpression.EVALUATION_TIME_GROUP) 78 { 79 groupEvaluatedCharts.add(chart); 80 81 String groupName = atts.getValue(ATTRIBUTE_evaluationGroup); 82 if (groupName != null) 83 { 84 JRDesignGroup group = new JRDesignGroup(); 85 group.setName(groupName); 86 chart.setEvaluationGroup(group); 87 } 88 } 89 90 String hyperlinkType = atts.getValue(ATTRIBUTE_hyperlinkType); 91 if (hyperlinkType != null) 92 { 93 chart.setLinkType(hyperlinkType); 94 } 95 96 Byte hyperlinkTarget = (Byte )JRXmlConstants.getHyperlinkTargetMap().get(atts.getValue(ATTRIBUTE_hyperlinkTarget)); 97 if (hyperlinkTarget != null) 98 { 99 chart.setHyperlinkTarget(hyperlinkTarget.byteValue()); 100 } 101 102 String bookmarkLevelAttr = atts.getValue(ATTRIBUTE_bookmarkLevel); 103 if (bookmarkLevelAttr != null) 104 { 105 chart.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr)); 106 } 107 108 String chartCustomizerClass = atts.getValue( ATTRIBUTE_customizerClass ); 109 if( chartCustomizerClass != null && chartCustomizerClass.length() > 0 ){ 110 chart.setCustomizerClass(chartCustomizerClass); 111 } 112 113 return chart; 114 } 115 116 117 120 public static class JRChartTitleFactory extends JRBaseFactory 121 { 122 private static final String ATTRIBUTE_position = "position"; 123 private static final String ATTRIBUTE_color = "color"; 124 125 126 public Object createObject(Attributes atts) 127 { 128 JRDesignChart chart = (JRDesignChart) digester.peek(); 129 130 String position = atts.getValue(ATTRIBUTE_position); 131 if (position != null && position.length() > 0) 132 chart.setTitlePosition(((Byte )JRXmlConstants.getChartTitlePositionMap().get(position)).byteValue()); 133 134 135 Color color = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_color), Color.black); 136 if (color != null) 137 { 138 chart.setTitleColor(color); 139 } 140 141 return chart; 142 } 143 } 144 145 146 149 public static class JRChartSubtitleFactory extends JRBaseFactory 150 { 151 private static final String ATTRIBUTE_color = "color"; 152 153 154 public Object createObject(Attributes atts) 155 { 156 JRDesignChart chart = (JRDesignChart) digester.peek(); 157 158 Color color = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_color), Color.black); 159 if (color != null) 160 { 161 chart.setSubtitleColor(color); 162 } 163 164 return chart; 165 } 166 } 167 168 169 174 public static class JRChartLegendFactory extends JRBaseFactory 175 { 176 179 public static final String ATTRIBUTE_textColor = "textColor"; 180 181 184 public static final String ATTRIBUTE_backgroundColor = "backgroundColor"; 185 186 189 public Object createObject(Attributes atts) throws JRException 190 { 191 JRDesignChart chart = (JRDesignChart)digester.peek(); 193 194 String attrValue = atts.getValue(ATTRIBUTE_textColor); 196 if (attrValue != null && attrValue.length() > 0) 197 { 198 Color color = JRXmlConstants.getColor(attrValue, null); 199 chart.setLegendColor(color); 200 } 201 202 attrValue = atts.getValue(ATTRIBUTE_backgroundColor); 204 if (attrValue != null && attrValue.length() > 0) 205 { 206 Color color = JRXmlConstants.getColor(attrValue, null); 207 chart.setLegendBackgroundColor(color); 208 } 209 210 212 return chart; 213 } 214 } 215 216 217 222 public static class JRChartAxisFormatFactory extends JRBaseFactory 223 { 224 227 public static final String ATTRIBUTE_labelColor = "labelColor"; 228 229 232 public static final String ATTRIBUTE_tickLabelColor = "tickLabelColor"; 233 234 237 public static final String ATTRIBUTE_tickLabelMask = "tickLabelMask"; 238 239 242 public static final String ATTRIBUTE_axisLineColor = "axisLineColor"; 243 244 247 public Object createObject(Attributes atts) throws JRException 248 { 249 JRAxisFormat axisLabel = new JRAxisFormat(); 251 252 String attrValue = atts.getValue(ATTRIBUTE_labelColor); 254 if (attrValue != null && attrValue.length() > 0) 255 { 256 Color color = JRXmlConstants.getColor(attrValue, null); 257 axisLabel.setLabelColor(color); 258 } 259 260 attrValue = atts.getValue(ATTRIBUTE_tickLabelColor); 262 if (attrValue != null && attrValue.length() > 0) 263 { 264 Color color = JRXmlConstants.getColor(attrValue, null); 265 axisLabel.setTickLabelColor(color); 266 } 267 268 attrValue = atts.getValue(ATTRIBUTE_tickLabelMask); 270 if (attrValue != null && attrValue.length() > 0) 271 { 272 axisLabel.setTickLabelMask(attrValue); 273 } 274 275 attrValue = atts.getValue(ATTRIBUTE_axisLineColor); 277 if (attrValue != null && attrValue.length() > 0) 278 { 279 Color color = JRXmlConstants.getColor(attrValue, null); 280 axisLabel.setLineColor(color); 281 } 282 283 285 return axisLabel; 286 } 287 } 288 } 289 | Popular Tags |