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:
032: import org.xml.sax.Attributes;
033: import net.sf.jasperreports.engine.design.JRDesignConditionalStyle;
034:
035: /**
036: * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
037: * @version $Id: JRConditionalStyleFillerFactory.java 1581 2007-02-12 14:19:02Z shertage $
038: */
039: public class JRConditionalStyleFillerFactory extends JRBaseFactory {
040:
041: /**
042: *
043: */
044: public Object createObject(Attributes atts) {
045: JRDesignConditionalStyle style = (JRDesignConditionalStyle) digester
046: .peek();
047:
048: // get JRElement attributes
049: Byte mode = (Byte) JRXmlConstants.getModeMap().get(
050: atts.getValue(JRXmlConstants.ATTRIBUTE_mode));
051: if (mode != null) {
052: style.setMode(mode);
053: }
054:
055: String forecolor = atts
056: .getValue(JRXmlConstants.ATTRIBUTE_forecolor);
057: style.setForecolor(JRXmlConstants.getColor(forecolor, null));
058:
059: String backcolor = atts
060: .getValue(JRXmlConstants.ATTRIBUTE_backcolor);
061: style.setBackcolor(JRXmlConstants.getColor(backcolor, null));
062:
063: // get graphic element attributes
064: Byte pen = (Byte) JRXmlConstants.getPenMap().get(
065: atts.getValue(JRXmlConstants.ATTRIBUTE_pen));
066: style.setPen(pen);
067:
068: Byte fill = (Byte) JRXmlConstants.getFillMap().get(
069: atts.getValue(JRXmlConstants.ATTRIBUTE_fill));
070: style.setFill(fill);
071:
072: // get rectangle attributes
073: String radius = atts.getValue(JRXmlConstants.ATTRIBUTE_radius);
074: if (radius != null && radius.length() > 0) {
075: style.setRadius(Integer.parseInt(radius));
076: }
077:
078: // get image attributes
079: Byte scaleImage = (Byte) JRXmlConstants.getScaleImageMap().get(
080: atts.getValue(JRXmlConstants.ATTRIBUTE_scaleImage));
081: if (scaleImage != null) {
082: style.setScaleImage(scaleImage);
083: }
084:
085: Byte horizontalAlignment = (Byte) JRXmlConstants
086: .getHorizontalAlignMap().get(
087: atts.getValue(JRXmlConstants.ATTRIBUTE_hAlign));
088: if (horizontalAlignment != null) {
089: style.setHorizontalAlignment(horizontalAlignment);
090: }
091:
092: Byte verticalAlignment = (Byte) JRXmlConstants
093: .getVerticalAlignMap().get(
094: atts.getValue(JRXmlConstants.ATTRIBUTE_vAlign));
095: if (verticalAlignment != null) {
096: style.setVerticalAlignment(verticalAlignment);
097: }
098:
099: // get box attributes
100: Byte border = (Byte) JRXmlConstants.getPenMap().get(
101: atts.getValue(JRXmlConstants.ATTRIBUTE_border));
102: if (border != null) {
103: style.setBorder(border);
104: }
105:
106: Color borderColor = JRXmlConstants.getColor(atts
107: .getValue(JRXmlConstants.ATTRIBUTE_borderColor), null);
108: if (borderColor != null) {
109: style.setBorderColor(borderColor);
110: }
111:
112: String padding = atts
113: .getValue(JRXmlConstants.ATTRIBUTE_padding);
114: if (padding != null && padding.length() > 0) {
115: style.setPadding(Integer.parseInt(padding));
116: }
117:
118: border = (Byte) JRXmlConstants.getPenMap().get(
119: atts.getValue(JRXmlConstants.ATTRIBUTE_topBorder));
120: if (border != null) {
121: style.setTopBorder(border);
122: }
123:
124: borderColor = JRXmlConstants.getColor(atts
125: .getValue(JRXmlConstants.ATTRIBUTE_topBorderColor),
126: Color.black);
127: if (borderColor != null) {
128: style.setTopBorderColor(borderColor);
129: }
130:
131: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_topPadding);
132: if (padding != null && padding.length() > 0) {
133: style.setTopPadding(Integer.parseInt(padding));
134: }
135:
136: border = (Byte) JRXmlConstants.getPenMap().get(
137: atts.getValue(JRXmlConstants.ATTRIBUTE_leftBorder));
138: if (border != null) {
139: style.setLeftBorder(border);
140: }
141:
142: borderColor = JRXmlConstants.getColor(atts
143: .getValue(JRXmlConstants.ATTRIBUTE_leftBorderColor),
144: Color.black);
145: if (borderColor != null) {
146: style.setLeftBorderColor(borderColor);
147: }
148:
149: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_leftPadding);
150: if (padding != null && padding.length() > 0) {
151: style.setLeftPadding(Integer.parseInt(padding));
152: }
153:
154: border = (Byte) JRXmlConstants.getPenMap().get(
155: atts.getValue(JRXmlConstants.ATTRIBUTE_bottomBorder));
156: if (border != null) {
157: style.setBottomBorder(border);
158: }
159:
160: borderColor = JRXmlConstants.getColor(atts
161: .getValue(JRXmlConstants.ATTRIBUTE_bottomBorderColor),
162: Color.black);
163: if (borderColor != null) {
164: style.setBottomBorderColor(borderColor);
165: }
166:
167: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_bottomPadding);
168: if (padding != null && padding.length() > 0) {
169: style.setBottomPadding(Integer.parseInt(padding));
170: }
171:
172: border = (Byte) JRXmlConstants.getPenMap().get(
173: atts.getValue(JRXmlConstants.ATTRIBUTE_rightBorder));
174: if (border != null) {
175: style.setRightBorder(border);
176: }
177:
178: borderColor = JRXmlConstants.getColor(atts
179: .getValue(JRXmlConstants.ATTRIBUTE_rightBorderColor),
180: Color.black);
181: if (borderColor != null) {
182: style.setRightBorderColor(borderColor);
183: }
184:
185: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_rightPadding);
186: if (padding != null && padding.length() > 0) {
187: style.setRightPadding(Integer.parseInt(padding));
188: }
189:
190: Byte rotation = (Byte) JRXmlConstants.getRotationMap().get(
191: atts.getValue(JRXmlConstants.ATTRIBUTE_rotation));
192: if (rotation != null) {
193: style.setRotation(rotation);
194: }
195:
196: Byte lineSpacing = (Byte) JRXmlConstants
197: .getLineSpacingMap()
198: .get(
199: atts
200: .getValue(JRXmlConstants.ATTRIBUTE_lineSpacing));
201: if (lineSpacing != null) {
202: style.setLineSpacing(lineSpacing);
203: }
204:
205: String isStyledText = atts
206: .getValue(JRXmlConstants.ATTRIBUTE_isStyledText);
207: if (isStyledText != null && isStyledText.length() > 0) {
208: style.setStyledText(Boolean.valueOf(isStyledText));
209: }
210:
211: style.setPattern(atts
212: .getValue(JRXmlConstants.ATTRIBUTE_pattern));
213:
214: String isBlankWhenNull = atts
215: .getValue(JRXmlConstants.ATTRIBUTE_isBlankWhenNull);
216: if (isBlankWhenNull != null && isBlankWhenNull.length() > 0) {
217: style.setBlankWhenNull(Boolean.valueOf(isBlankWhenNull));
218: }
219:
220: if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontName) != null)
221: style.setFontName(atts
222: .getValue(JRXmlConstants.ATTRIBUTE_fontName));
223:
224: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isBold) != null)
225: style.setBold(Boolean.valueOf(atts
226: .getValue(JRXmlConstants.ATTRIBUTE_isBold)));
227:
228: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic) != null)
229: style.setItalic(Boolean.valueOf(atts
230: .getValue(JRXmlConstants.ATTRIBUTE_isItalic)));
231:
232: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline) != null)
233: style.setUnderline(Boolean.valueOf(atts
234: .getValue(JRXmlConstants.ATTRIBUTE_isUnderline)));
235:
236: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough) != null)
237: style
238: .setStrikeThrough(Boolean
239: .valueOf(atts
240: .getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough)));
241:
242: if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontSize) != null)
243: style.setFontSize(Integer.valueOf(atts
244: .getValue(JRXmlConstants.ATTRIBUTE_fontSize)));
245:
246: if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName) != null)
247: style.setPdfFontName(atts
248: .getValue(JRXmlConstants.ATTRIBUTE_pdfFontName));
249:
250: if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding) != null)
251: style.setPdfEncoding(atts
252: .getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding));
253:
254: if (atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded) != null)
255: style.setPdfEmbedded(Boolean.valueOf(atts
256: .getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded)));
257:
258: return style;
259: }
260: }
|