001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.xml;
029:
030: import java.awt.Color;
031: import java.util.Collection;
032:
033: import net.sf.jasperreports.charts.util.JRAxisFormat;
034: import net.sf.jasperreports.engine.JRException;
035: import net.sf.jasperreports.engine.JRExpression;
036: import net.sf.jasperreports.engine.design.JRDesignChart;
037: import net.sf.jasperreports.engine.design.JRDesignGroup;
038:
039: import org.xml.sax.Attributes;
040:
041: /**
042: * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
043: * @version $Id: JRChartFactory.java 1797 2007-07-30 09:38:35Z teodord $
044: */
045: public class JRChartFactory extends JRBaseFactory {
046:
047: /**
048: *
049: */
050: public Object createObject(Attributes atts) {
051: JRXmlLoader xmlLoader = (JRXmlLoader) digester.peek(digester
052: .getCount() - 1);
053: Collection groupEvaluatedCharts = xmlLoader
054: .getGroupEvaluatedCharts();
055:
056: JRDesignChart chart = (JRDesignChart) digester.peek();
057:
058: String isShowLegend = atts
059: .getValue(JRXmlConstants.ATTRIBUTE_isShowLegend);
060: if (isShowLegend != null && isShowLegend.length() > 0)
061: chart.setShowLegend(Boolean.valueOf(isShowLegend)
062: .booleanValue());
063:
064: Byte evaluationTime = (Byte) JRXmlConstants
065: .getEvaluationTimeMap()
066: .get(
067: atts
068: .getValue(JRXmlConstants.ATTRIBUTE_evaluationTime));
069: if (evaluationTime != null) {
070: chart.setEvaluationTime(evaluationTime.byteValue());
071: }
072: if (chart.getEvaluationTime() == JRExpression.EVALUATION_TIME_GROUP) {
073: groupEvaluatedCharts.add(chart);
074:
075: String groupName = atts
076: .getValue(JRXmlConstants.ATTRIBUTE_evaluationGroup);
077: if (groupName != null) {
078: JRDesignGroup group = new JRDesignGroup();
079: group.setName(groupName);
080: chart.setEvaluationGroup(group);
081: }
082: }
083:
084: String hyperlinkType = atts
085: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType);
086: if (hyperlinkType != null) {
087: chart.setLinkType(hyperlinkType);
088: }
089:
090: Byte hyperlinkTarget = (Byte) JRXmlConstants
091: .getHyperlinkTargetMap()
092: .get(
093: atts
094: .getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));
095: if (hyperlinkTarget != null) {
096: chart.setHyperlinkTarget(hyperlinkTarget.byteValue());
097: }
098:
099: String bookmarkLevelAttr = atts
100: .getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
101: if (bookmarkLevelAttr != null) {
102: chart.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
103: }
104:
105: String chartCustomizerClass = atts
106: .getValue(JRXmlConstants.ATTRIBUTE_customizerClass);
107: if (chartCustomizerClass != null
108: && chartCustomizerClass.length() > 0) {
109: chart.setCustomizerClass(chartCustomizerClass);
110: }
111:
112: return chart;
113: }
114:
115: /**
116: *
117: */
118: public static class JRChartTitleFactory extends JRBaseFactory {
119: public Object createObject(Attributes atts) {
120: JRDesignChart chart = (JRDesignChart) digester.peek();
121:
122: String position = atts
123: .getValue(JRXmlConstants.ATTRIBUTE_position);
124: if (position != null && position.length() > 0)
125: chart.setTitlePosition(((Byte) JRXmlConstants
126: .getChartTitlePositionMap().get(position))
127: .byteValue());
128:
129: Color color = JRXmlConstants.getColor(atts
130: .getValue(JRXmlConstants.ATTRIBUTE_color),
131: Color.black);
132: if (color != null) {
133: chart.setTitleColor(color);
134: }
135:
136: return chart;
137: }
138: }
139:
140: /**
141: *
142: */
143: public static class JRChartSubtitleFactory extends JRBaseFactory {
144: public Object createObject(Attributes atts) {
145: JRDesignChart chart = (JRDesignChart) digester.peek();
146:
147: Color color = JRXmlConstants.getColor(atts
148: .getValue(JRXmlConstants.ATTRIBUTE_color),
149: Color.black);
150: if (color != null) {
151: chart.setSubtitleColor(color);
152: }
153:
154: return chart;
155: }
156: }
157:
158: /**
159: * A factory responsible for creating new chart legend formatting objects.
160: *
161: * @author Barry Klawans (bklawans@users.sourceforge.net)
162: */
163: public static class JRChartLegendFactory extends JRBaseFactory {
164: /**
165: *
166: */
167: public Object createObject(Attributes atts) throws JRException {
168: // Grab the chart from the object stack.
169: JRDesignChart chart = (JRDesignChart) digester.peek();
170:
171: // Set the text color
172: String attrValue = atts
173: .getValue(JRXmlConstants.ATTRIBUTE_textColor);
174: if (attrValue != null && attrValue.length() > 0) {
175: Color color = JRXmlConstants.getColor(attrValue, null);
176: chart.setLegendColor(color);
177: }
178:
179: // Set the background color
180: attrValue = atts
181: .getValue(JRXmlConstants.ATTRIBUTE_backgroundColor);
182: if (attrValue != null && attrValue.length() > 0) {
183: Color color = JRXmlConstants.getColor(attrValue, null);
184: chart.setLegendBackgroundColor(color);
185: }
186:
187: // Any font set will be put in the chart directly by the digester
188:
189: return chart;
190: }
191: }
192:
193: /**
194: * A factory responsible for creating new chart axis formatting objects.
195: *
196: * @author Barry Klawans (bklawans@users.sourceforge.net)
197: */
198: public static class JRChartAxisFormatFactory extends JRBaseFactory {
199: /**
200: *
201: */
202: public Object createObject(Attributes atts) throws JRException {
203: // Create an empty axis formatting object
204: JRAxisFormat axisLabel = new JRAxisFormat();
205:
206: // Set the label color
207: String attrValue = atts
208: .getValue(JRXmlConstants.ATTRIBUTE_labelColor);
209: if (attrValue != null && attrValue.length() > 0) {
210: Color color = JRXmlConstants.getColor(attrValue, null);
211: axisLabel.setLabelColor(color);
212: }
213:
214: // Set the tick label color
215: attrValue = atts
216: .getValue(JRXmlConstants.ATTRIBUTE_tickLabelColor);
217: if (attrValue != null && attrValue.length() > 0) {
218: Color color = JRXmlConstants.getColor(attrValue, null);
219: axisLabel.setTickLabelColor(color);
220: }
221:
222: // Set the tick mask
223: attrValue = atts
224: .getValue(JRXmlConstants.ATTRIBUTE_tickLabelMask);
225: if (attrValue != null && attrValue.length() > 0) {
226: axisLabel.setTickLabelMask(attrValue);
227: }
228:
229: // And finally set the axis line color
230: attrValue = atts
231: .getValue(JRXmlConstants.ATTRIBUTE_axisLineColor);
232: if (attrValue != null && attrValue.length() > 0) {
233: Color color = JRXmlConstants.getColor(attrValue, null);
234: axisLabel.setLineColor(color);
235: }
236:
237: // Any fonts set will be put in the axis format object by the digester.
238:
239: return axisLabel;
240: }
241: }
242: }
|