~brian-thomason/+junk/jasperreports3.7

« back to all changes in this revision

Viewing changes to src/net/sf/jasperreports/engine/xml/JRChartFactory.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:51:16 UTC
  • Revision ID: brian.thomason@canonical.com-20111220175116-apwo6unuaedvgzo3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * JasperReports - Free Java Reporting Library.
 
3
 * Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
 
4
 * http://www.jaspersoft.com
 
5
 *
 
6
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 
7
 * the following license terms apply:
 
8
 *
 
9
 * This program is part of JasperReports.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 * 
 
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/>.
 
23
 */
 
24
package net.sf.jasperreports.engine.xml;
 
25
 
 
26
import java.awt.Color;
 
27
 
 
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;
 
36
 
 
37
import org.xml.sax.Attributes;
 
38
 
 
39
 
 
40
/**
 
41
 * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
 
42
 * @version $Id: JRChartFactory.java 3701 2010-04-07 11:09:35Z lucianc $
 
43
 */
 
44
public class JRChartFactory extends JRBaseFactory
 
45
{
 
46
 
 
47
        /**
 
48
         *
 
49
         */
 
50
        public Object createObject(Attributes atts)
 
51
        {
 
52
                JRXmlLoader xmlLoader = (JRXmlLoader)digester.peek(digester.getCount() - 1);
 
53
 
 
54
                JRDesignChart chart = (JRDesignChart) digester.peek();
 
55
 
 
56
                String isShowLegend = atts.getValue(JRXmlConstants.ATTRIBUTE_isShowLegend);
 
57
                if (isShowLegend != null && isShowLegend.length() > 0)
 
58
                {
 
59
                        chart.setShowLegend(Boolean.valueOf(isShowLegend));
 
60
                }
 
61
                EvaluationTimeEnum evaluationTime = EvaluationTimeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_evaluationTime));
 
62
                if (evaluationTime != null)
 
63
                {
 
64
                        chart.setEvaluationTime(evaluationTime);
 
65
                }
 
66
                if (chart.getEvaluationTimeValue() == EvaluationTimeEnum.GROUP)
 
67
                {
 
68
                        xmlLoader.addGroupEvaluatedChart(chart);
 
69
 
 
70
                        String groupName = atts.getValue(JRXmlConstants.ATTRIBUTE_evaluationGroup);
 
71
                        if (groupName != null)
 
72
                        {
 
73
                                JRDesignGroup group = new JRDesignGroup();
 
74
                                group.setName(groupName);
 
75
                                chart.setEvaluationGroup(group);
 
76
                        }
 
77
                }
 
78
 
 
79
                chart.setLinkType(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType));
 
80
                chart.setLinkTarget(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));
 
81
 
 
82
                String bookmarkLevelAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
 
83
                if (bookmarkLevelAttr != null)
 
84
                {
 
85
                        chart.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
 
86
                }
 
87
 
 
88
                String chartCustomizerClass = atts.getValue( JRXmlConstants.ATTRIBUTE_customizerClass );
 
89
                if( chartCustomizerClass != null && chartCustomizerClass.length() > 0 )
 
90
                {
 
91
                        chart.setCustomizerClass(chartCustomizerClass);
 
92
                }
 
93
                
 
94
                chart.setRenderType(atts.getValue(JRXmlConstants.ATTRIBUTE_renderType));
 
95
                chart.setTheme(atts.getValue(JRXmlConstants.ATTRIBUTE_theme));
 
96
                
 
97
                return chart;
 
98
        }
 
99
 
 
100
 
 
101
        /**
 
102
         *
 
103
         */
 
104
        public static class JRChartTitleFactory extends JRBaseFactory
 
105
        {
 
106
                public Object createObject(Attributes atts)
 
107
                {
 
108
                        JRDesignChart chart = (JRDesignChart) digester.peek();
 
109
 
 
110
                        EdgeEnum position = EdgeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_position));
 
111
                        if (position != null)
 
112
                        {
 
113
                                chart.setTitlePosition(position);
 
114
                        }
 
115
                        
 
116
                        Color color = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_color), Color.black);
 
117
                        if (color != null)
 
118
                        {
 
119
                                chart.setTitleColor(color);
 
120
                        }
 
121
 
 
122
                        return chart;
 
123
                }
 
124
        }
 
125
 
 
126
 
 
127
        /**
 
128
         *
 
129
         */
 
130
        public static class JRChartSubtitleFactory extends JRBaseFactory
 
131
        {
 
132
                public Object createObject(Attributes atts)
 
133
                {
 
134
                        JRDesignChart chart = (JRDesignChart) digester.peek();
 
135
 
 
136
                        Color color = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_color), Color.black);
 
137
                        if (color != null)
 
138
                        {
 
139
                                chart.setSubtitleColor(color);
 
140
                        }
 
141
 
 
142
                        return chart;
 
143
                }
 
144
        }
 
145
 
 
146
 
 
147
        /**
 
148
         * A factory responsible for creating new chart legend formatting objects.
 
149
         *
 
150
         * @author Barry Klawans (bklawans@users.sourceforge.net)
 
151
         */
 
152
        public static class JRChartLegendFactory extends JRBaseFactory
 
153
        {
 
154
                /**
 
155
                 *
 
156
                 */
 
157
                public Object createObject(Attributes atts) throws JRException
 
158
                {
 
159
                        // Grab the chart from the object stack.
 
160
                        JRDesignChart chart = (JRDesignChart)digester.peek();
 
161
 
 
162
                        // Set the text color
 
163
                        String attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_textColor);
 
164
                        if (attrValue != null && attrValue.length() > 0)
 
165
                        {
 
166
                                Color color = JRColorUtil.getColor(attrValue, null);
 
167
                                chart.setLegendColor(color);
 
168
                        }
 
169
 
 
170
                        // Set the background color
 
171
                        attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_backgroundColor);
 
172
                        if (attrValue != null && attrValue.length() > 0)
 
173
                        {
 
174
                                Color color = JRColorUtil.getColor(attrValue, null);
 
175
                                chart.setLegendBackgroundColor(color);
 
176
                        }
 
177
 
 
178
                        EdgeEnum position = EdgeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_position));
 
179
                        if (position != null)
 
180
                        {
 
181
                                chart.setLegendPosition(position);
 
182
                        }
 
183
                        // Any font set will be put in the chart directly by the digester
 
184
 
 
185
                        return chart;
 
186
                }
 
187
        }
 
188
 
 
189
 
 
190
        /**
 
191
         * A factory responsible for creating new chart axis formatting objects.
 
192
         *
 
193
         * @author Barry Klawans (bklawans@users.sourceforge.net)
 
194
         */
 
195
        public static class JRChartAxisFormatFactory extends JRBaseFactory
 
196
        {
 
197
                /**
 
198
                 *
 
199
                 */
 
200
                public Object createObject(Attributes atts) throws JRException
 
201
                {
 
202
                        // Create an empty axis formatting object
 
203
                        JRAxisFormat axisLabel = new JRAxisFormat();
 
204
 
 
205
                        // Set the label color
 
206
                        String attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_labelColor);
 
207
                        if (attrValue != null && attrValue.length() > 0)
 
208
                        {
 
209
                                Color color = JRColorUtil.getColor(attrValue, null);
 
210
                                axisLabel.setLabelColor(color);
 
211
                        }
 
212
 
 
213
                        // Set the tick label color
 
214
                        attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_tickLabelColor);
 
215
                        if (attrValue != null && attrValue.length() > 0)
 
216
                        {
 
217
                                Color color = JRColorUtil.getColor(attrValue, null);
 
218
                                axisLabel.setTickLabelColor(color);
 
219
                        }
 
220
 
 
221
                        // Set the tick mask
 
222
                        attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_tickLabelMask);
 
223
                        if (attrValue != null && attrValue.length() > 0)
 
224
                        {
 
225
                                axisLabel.setTickLabelMask(attrValue);
 
226
                        }
 
227
 
 
228
                        // Set the vertical tick labels flag
 
229
                        attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_verticalTickLabels);
 
230
                        if (attrValue != null && attrValue.length() > 0)
 
231
                        {
 
232
                                axisLabel.setVerticalTickLabel(Boolean.valueOf(attrValue));
 
233
                        }
 
234
 
 
235
                        // And finally set the axis line color
 
236
                        attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_axisLineColor);
 
237
                        if (attrValue != null && attrValue.length() > 0)
 
238
                        {
 
239
                                Color color = JRColorUtil.getColor(attrValue, null);
 
240
                                axisLabel.setLineColor(color);
 
241
                        }
 
242
 
 
243
                        // Any fonts set will be put in the axis format object by the digester.
 
244
 
 
245
                        return axisLabel;
 
246
                }
 
247
        }
 
248
 
 
249
 
 
250
        /**
 
251
         * 
 
252
         */
 
253
        public static class JRCategoryAxisFormatFactory extends JRBaseFactory
 
254
        {
 
255
                /**
 
256
                 *
 
257
                 */
 
258
                public Object createObject(Attributes atts) throws JRException
 
259
                {
 
260
                        JRCategoryAxisFormat categoryAxisFormat = (JRCategoryAxisFormat)digester.peek();
 
261
                        
 
262
                        String labelRotation = atts.getValue(JRXmlConstants.ATTRIBUTE_labelRotation);
 
263
                        if (labelRotation != null && labelRotation.length() > 0)
 
264
                        {
 
265
                                categoryAxisFormat.setCategoryAxisTickLabelRotation(Double.valueOf(labelRotation));
 
266
                        }
 
267
                        return categoryAxisFormat;
 
268
                }
 
269
        }
 
270
}