KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > xml > JRConditionalStyleFillerFactory


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.xml;
29
30 import java.awt.Color JavaDoc;
31
32 import org.xml.sax.Attributes JavaDoc;
33 import net.sf.jasperreports.engine.design.JRDesignConditionalStyle;
34
35 /**
36  * @author Ionut Nedelcu (ionutned@users.sourceforge.net)
37  * @version $Id: JRConditionalStyleFillerFactory.java 1413 2006-09-28 13:47:40 +0300 (Thu, 28 Sep 2006) teodord $
38  */

39 public class JRConditionalStyleFillerFactory extends JRBaseFactory
40 {
41     private static final String JavaDoc ATTRIBUTE_mode = "mode";
42     private static final String JavaDoc ATTRIBUTE_forecolor = "forecolor";
43     private static final String JavaDoc ATTRIBUTE_backcolor = "backcolor";
44
45     private static final String JavaDoc ATTRIBUTE_pen = "pen";
46     private static final String JavaDoc ATTRIBUTE_fill = "fill";
47
48     private static final String JavaDoc ATTRIBUTE_radius = "radius";
49
50     private static final String JavaDoc ATTRIBUTE_scaleImage = "scaleImage";
51     // these are inherited by both images and texts.
52
private static final String JavaDoc ATTRIBUTE_hAlign = "hAlign";
53     private static final String JavaDoc ATTRIBUTE_vAlign = "vAlign";
54
55     private static final String JavaDoc ATTRIBUTE_border = "border";
56     private static final String JavaDoc ATTRIBUTE_borderColor = "borderColor";
57     private static final String JavaDoc ATTRIBUTE_padding = "padding";
58     private static final String JavaDoc ATTRIBUTE_topBorder = "topBorder";
59     private static final String JavaDoc ATTRIBUTE_topBorderColor = "topBorderColor";
60     private static final String JavaDoc ATTRIBUTE_topPadding = "topPadding";
61     private static final String JavaDoc ATTRIBUTE_leftBorder = "leftBorder";
62     private static final String JavaDoc ATTRIBUTE_leftBorderColor = "leftBorderColor";
63     private static final String JavaDoc ATTRIBUTE_leftPadding = "leftPadding";
64     private static final String JavaDoc ATTRIBUTE_bottomBorder = "bottomBorder";
65     private static final String JavaDoc ATTRIBUTE_bottomBorderColor = "bottomBorderColor";
66     private static final String JavaDoc ATTRIBUTE_bottomPadding = "bottomPadding";
67     private static final String JavaDoc ATTRIBUTE_rightBorder = "rightBorder";
68     private static final String JavaDoc ATTRIBUTE_rightBorderColor = "rightBorderColor";
69     private static final String JavaDoc ATTRIBUTE_rightPadding = "rightPadding";
70
71     private static final String JavaDoc ATTRIBUTE_rotation = "rotation";
72     private static final String JavaDoc ATTRIBUTE_lineSpacing = "lineSpacing";
73     private static final String JavaDoc ATTRIBUTE_isStyledText = "isStyledText";
74     private static final String JavaDoc ATTRIBUTE_pattern = "pattern";
75     private static final String JavaDoc ATTRIBUTE_isBlankWhenNull = "isBlankWhenNull";
76
77     private static final String JavaDoc ATTRIBUTE_fontName = "fontName";
78     private static final String JavaDoc ATTRIBUTE_isBold = "isBold";
79     private static final String JavaDoc ATTRIBUTE_isItalic = "isItalic";
80     private static final String JavaDoc ATTRIBUTE_isUnderline = "isUnderline";
81     private static final String JavaDoc ATTRIBUTE_isStrikeThrough = "isStrikeThrough";
82     private static final String JavaDoc ATTRIBUTE_fontSize = "fontSize";
83     private static final String JavaDoc ATTRIBUTE_pdfFontName = "pdfFontName";
84     private static final String JavaDoc ATTRIBUTE_pdfEncoding = "pdfEncoding";
85     private static final String JavaDoc ATTRIBUTE_isPdfEmbedded = "isPdfEmbedded";
86
87
88     /**
89      *
90      */

91     public Object JavaDoc createObject(Attributes JavaDoc atts)
92     {
93         JRDesignConditionalStyle style = (JRDesignConditionalStyle) digester.peek();
94
95
96         // get JRElement attributes
97
Byte JavaDoc mode = (Byte JavaDoc)JRXmlConstants.getModeMap().get(atts.getValue(ATTRIBUTE_mode));
98         if (mode != null)
99         {
100             style.setMode(mode);
101         }
102
103         String JavaDoc forecolor = atts.getValue(ATTRIBUTE_forecolor);
104         style.setForecolor(JRXmlConstants.getColor(forecolor, null));
105
106         String JavaDoc backcolor = atts.getValue(ATTRIBUTE_backcolor);
107         style.setBackcolor(JRXmlConstants.getColor(backcolor, null));
108
109
110
111         // get graphic element attributes
112
Byte JavaDoc pen = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_pen));
113         style.setPen(pen);
114
115         Byte JavaDoc fill = (Byte JavaDoc)JRXmlConstants.getFillMap().get(atts.getValue(ATTRIBUTE_fill));
116         style.setFill(fill);
117
118
119
120         // get rectangle attributes
121
String JavaDoc radius = atts.getValue(ATTRIBUTE_radius);
122         if (radius != null && radius.length() > 0)
123         {
124             style.setRadius(Integer.parseInt(radius));
125         }
126
127
128
129         // get image attributes
130
Byte JavaDoc scaleImage = (Byte JavaDoc)JRXmlConstants.getScaleImageMap().get(atts.getValue(ATTRIBUTE_scaleImage));
131         if (scaleImage != null)
132         {
133             style.setScaleImage(scaleImage);
134         }
135
136         Byte JavaDoc horizontalAlignment = (Byte JavaDoc)JRXmlConstants.getHorizontalAlignMap().get(atts.getValue(ATTRIBUTE_hAlign));
137         if (horizontalAlignment != null)
138         {
139             style.setHorizontalAlignment(horizontalAlignment);
140         }
141
142         Byte JavaDoc verticalAlignment = (Byte JavaDoc)JRXmlConstants.getVerticalAlignMap().get(atts.getValue(ATTRIBUTE_vAlign));
143         if (verticalAlignment != null)
144         {
145             style.setVerticalAlignment(verticalAlignment);
146         }
147
148
149         // get box attributes
150
Byte JavaDoc border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_border));
151         if (border != null)
152         {
153             style.setBorder(border);
154         }
155
156         Color JavaDoc borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_borderColor), null);
157         if (borderColor != null)
158         {
159             style.setBorderColor(borderColor);
160         }
161
162         String JavaDoc padding = atts.getValue(ATTRIBUTE_padding);
163         if (padding != null && padding.length() > 0)
164         {
165             style.setPadding(Integer.parseInt(padding));
166         }
167
168         border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_topBorder));
169         if (border != null)
170         {
171             style.setTopBorder(border);
172         }
173
174         borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_topBorderColor), Color.black);
175         if (borderColor != null)
176         {
177             style.setTopBorderColor(borderColor);
178         }
179
180         padding = atts.getValue(ATTRIBUTE_topPadding);
181         if (padding != null && padding.length() > 0)
182         {
183             style.setTopPadding(Integer.parseInt(padding));
184         }
185
186         border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_leftBorder));
187         if (border != null)
188         {
189             style.setLeftBorder(border);
190         }
191
192         borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_leftBorderColor), Color.black);
193         if (borderColor != null)
194         {
195             style.setLeftBorderColor(borderColor);
196         }
197
198         padding = atts.getValue(ATTRIBUTE_leftPadding);
199         if (padding != null && padding.length() > 0)
200         {
201             style.setLeftPadding(Integer.parseInt(padding));
202         }
203
204         border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_bottomBorder));
205         if (border != null)
206         {
207             style.setBottomBorder(border);
208         }
209
210         borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_bottomBorderColor), Color.black);
211         if (borderColor != null)
212         {
213             style.setBottomBorderColor(borderColor);
214         }
215
216         padding = atts.getValue(ATTRIBUTE_bottomPadding);
217         if (padding != null && padding.length() > 0)
218         {
219             style.setBottomPadding(Integer.parseInt(padding));
220         }
221
222         border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_rightBorder));
223         if (border != null)
224         {
225             style.setRightBorder(border);
226         }
227
228         borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_rightBorderColor), Color.black);
229         if (borderColor != null)
230         {
231             style.setRightBorderColor(borderColor);
232         }
233
234         padding = atts.getValue(ATTRIBUTE_rightPadding);
235         if (padding != null && padding.length() > 0)
236         {
237             style.setRightPadding(Integer.parseInt(padding));
238         }
239
240
241
242         Byte JavaDoc rotation = (Byte JavaDoc)JRXmlConstants.getRotationMap().get(atts.getValue(ATTRIBUTE_rotation));
243         if (rotation != null)
244         {
245             style.setRotation(rotation);
246         }
247
248         Byte JavaDoc lineSpacing = (Byte JavaDoc)JRXmlConstants.getLineSpacingMap().get(atts.getValue(ATTRIBUTE_lineSpacing));
249         if (lineSpacing != null)
250         {
251             style.setLineSpacing(lineSpacing);
252         }
253
254         String JavaDoc isStyledText = atts.getValue(ATTRIBUTE_isStyledText);
255         if (isStyledText != null && isStyledText.length() > 0)
256         {
257             style.setStyledText(Boolean.valueOf(isStyledText));
258         }
259
260         style.setPattern(atts.getValue(ATTRIBUTE_pattern));
261
262         String JavaDoc isBlankWhenNull = atts.getValue(ATTRIBUTE_isBlankWhenNull);
263         if (isBlankWhenNull != null && isBlankWhenNull.length() > 0)
264         {
265             style.setBlankWhenNull(Boolean.valueOf(isBlankWhenNull));
266         }
267
268         if (atts.getValue(ATTRIBUTE_fontName) != null)
269             style.setFontName(atts.getValue(ATTRIBUTE_fontName));
270
271         if (atts.getValue(ATTRIBUTE_isBold) != null)
272             style.setBold(Boolean.valueOf(atts.getValue(ATTRIBUTE_isBold)));
273
274         if (atts.getValue(ATTRIBUTE_isItalic) != null)
275             style.setItalic(Boolean.valueOf(atts.getValue(ATTRIBUTE_isItalic)));
276
277         if (atts.getValue(ATTRIBUTE_isUnderline) != null)
278             style.setUnderline(Boolean.valueOf(atts.getValue(ATTRIBUTE_isUnderline)));
279
280         if (atts.getValue(ATTRIBUTE_isStrikeThrough) != null)
281             style.setStrikeThrough(Boolean.valueOf(atts.getValue(ATTRIBUTE_isStrikeThrough)));
282
283         if (atts.getValue(ATTRIBUTE_fontSize) != null)
284             style.setFontSize(Integer.valueOf(atts.getValue(ATTRIBUTE_fontSize)));
285
286         if (atts.getValue(ATTRIBUTE_pdfFontName) != null)
287             style.setPdfFontName(atts.getValue(ATTRIBUTE_pdfFontName));
288
289         if (atts.getValue(ATTRIBUTE_pdfEncoding) != null)
290             style.setPdfEncoding(atts.getValue(ATTRIBUTE_pdfEncoding));
291
292         if (atts.getValue(ATTRIBUTE_isPdfEmbedded) != null)
293             style.setPdfEmbedded(Boolean.valueOf(atts.getValue(ATTRIBUTE_isPdfEmbedded)));
294
295         return style;
296     }
297 }
298
Popular Tags