2
* JasperReports - Free Java Reporting Library.
3
* Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
4
* http://www.jaspersoft.com
6
* Unless you have purchased a commercial license agreement from Jaspersoft,
7
* the following license terms apply:
9
* This program is part of JasperReports.
11
* JasperReports is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU Lesser General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
16
* JasperReports is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public License
22
* along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
24
package net.sf.jasperreports.engine.xml;
26
import java.awt.Color;
28
import net.sf.jasperreports.charts.JRCategoryAxisFormat;
29
import net.sf.jasperreports.charts.type.EdgeEnum;
30
import net.sf.jasperreports.charts.util.JRAxisFormat;
31
import net.sf.jasperreports.engine.JRException;
32
import net.sf.jasperreports.engine.design.JRDesignChart;
33
import net.sf.jasperreports.engine.design.JRDesignGroup;
34
import net.sf.jasperreports.engine.type.EvaluationTimeEnum;
35
import net.sf.jasperreports.engine.util.JRColorUtil;
37
import org.xml.sax.Attributes;
41
* @author Ionut Nedelcu (ionutned@users.sourceforge.net)
42
* @version $Id: JRChartFactory.java 3701 2010-04-07 11:09:35Z lucianc $
44
public class JRChartFactory extends JRBaseFactory
50
public Object createObject(Attributes atts)
52
JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1);
54
JRDesignChart chart = (JRDesignChart) digester.peek();
56
String isShowLegend = atts.getValue(JRXmlConstants.ATTRIBUTE_isShowLegend);
57
if (isShowLegend != null && isShowLegend.length() > 0)
59
chart.setShowLegend(Boolean.valueOf(isShowLegend));
61
EvaluationTimeEnum evaluationTime = EvaluationTimeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_evaluationTime));
62
if (evaluationTime != null)
64
chart.setEvaluationTime(evaluationTime);
66
if (chart.getEvaluationTimeValue() == EvaluationTimeEnum.GROUP)
68
xmlLoader.addGroupEvaluatedChart(chart);
70
String groupName = atts.getValue(JRXmlConstants.ATTRIBUTE_evaluationGroup);
71
if (groupName != null)
73
JRDesignGroup group = new JRDesignGroup();
74
group.setName(groupName);
75
chart.setEvaluationGroup(group);
79
chart.setLinkType(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType));
80
chart.setLinkTarget(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));
82
String bookmarkLevelAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
83
if (bookmarkLevelAttr != null)
85
chart.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
88
String chartCustomizerClass = atts.getValue( JRXmlConstants.ATTRIBUTE_customizerClass );
89
if( chartCustomizerClass != null && chartCustomizerClass.length() > 0 )
91
chart.setCustomizerClass(chartCustomizerClass);
94
chart.setRenderType(atts.getValue(JRXmlConstants.ATTRIBUTE_renderType));
95
chart.setTheme(atts.getValue(JRXmlConstants.ATTRIBUTE_theme));
104
public static class JRChartTitleFactory extends JRBaseFactory
106
public Object createObject(Attributes atts)
108
JRDesignChart chart = (JRDesignChart) digester.peek();
110
EdgeEnum position = EdgeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_position));
111
if (position != null)
113
chart.setTitlePosition(position);
116
Color color = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_color), Color.black);
119
chart.setTitleColor(color);
130
public static class JRChartSubtitleFactory extends JRBaseFactory
132
public Object createObject(Attributes atts)
134
JRDesignChart chart = (JRDesignChart) digester.peek();
136
Color color = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_color), Color.black);
139
chart.setSubtitleColor(color);
148
* A factory responsible for creating new chart legend formatting objects.
150
* @author Barry Klawans (bklawans@users.sourceforge.net)
152
public static class JRChartLegendFactory extends JRBaseFactory
157
public Object createObject(Attributes atts) throws JRException
159
// Grab the chart from the object stack.
160
JRDesignChart chart = (JRDesignChart)digester.peek();
162
// Set the text color
163
String attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_textColor);
164
if (attrValue != null && attrValue.length() > 0)
166
Color color = JRColorUtil.getColor(attrValue, null);
167
chart.setLegendColor(color);
170
// Set the background color
171
attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_backgroundColor);
172
if (attrValue != null && attrValue.length() > 0)
174
Color color = JRColorUtil.getColor(attrValue, null);
175
chart.setLegendBackgroundColor(color);
178
EdgeEnum position = EdgeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_position));
179
if (position != null)
181
chart.setLegendPosition(position);
183
// Any font set will be put in the chart directly by the digester
191
* A factory responsible for creating new chart axis formatting objects.
193
* @author Barry Klawans (bklawans@users.sourceforge.net)
195
public static class JRChartAxisFormatFactory extends JRBaseFactory
200
public Object createObject(Attributes atts) throws JRException
202
// Create an empty axis formatting object
203
JRAxisFormat axisLabel = new JRAxisFormat();
205
// Set the label color
206
String attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_labelColor);
207
if (attrValue != null && attrValue.length() > 0)
209
Color color = JRColorUtil.getColor(attrValue, null);
210
axisLabel.setLabelColor(color);
213
// Set the tick label color
214
attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_tickLabelColor);
215
if (attrValue != null && attrValue.length() > 0)
217
Color color = JRColorUtil.getColor(attrValue, null);
218
axisLabel.setTickLabelColor(color);
222
attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_tickLabelMask);
223
if (attrValue != null && attrValue.length() > 0)
225
axisLabel.setTickLabelMask(attrValue);
228
// Set the vertical tick labels flag
229
attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_verticalTickLabels);
230
if (attrValue != null && attrValue.length() > 0)
232
axisLabel.setVerticalTickLabel(Boolean.valueOf(attrValue));
235
// And finally set the axis line color
236
attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_axisLineColor);
237
if (attrValue != null && attrValue.length() > 0)
239
Color color = JRColorUtil.getColor(attrValue, null);
240
axisLabel.setLineColor(color);
243
// Any fonts set will be put in the axis format object by the digester.
253
public static class JRCategoryAxisFormatFactory extends JRBaseFactory
258
public Object createObject(Attributes atts) throws JRException
260
JRCategoryAxisFormat categoryAxisFormat = (JRCategoryAxisFormat)digester.peek();
262
String labelRotation = atts.getValue(JRXmlConstants.ATTRIBUTE_labelRotation);
263
if (labelRotation != null && labelRotation.length() > 0)
265
categoryAxisFormat.setCategoryAxisTickLabelRotation(Double.valueOf(labelRotation));
267
return categoryAxisFormat;