KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sf.jasperreports.engine.JRBox;
33
34 import org.xml.sax.Attributes JavaDoc;
35
36
37 /**
38  * @author Teodor Danciu (teodord@users.sourceforge.net)
39  * @version $Id: JRBoxFactory.java 1291 2006-06-13 18:11:10 +0300 (Tue, 13 Jun 2006) teodord $
40  */

41 public class JRBoxFactory extends JRBaseFactory
42 {
43
44
45     /**
46      *
47      */

48     private static final String JavaDoc ATTRIBUTE_border = "border";
49     private static final String JavaDoc ATTRIBUTE_borderColor = "borderColor";
50     private static final String JavaDoc ATTRIBUTE_padding = "padding";
51     private static final String JavaDoc ATTRIBUTE_topBorder = "topBorder";
52     private static final String JavaDoc ATTRIBUTE_topBorderColor = "topBorderColor";
53     private static final String JavaDoc ATTRIBUTE_topPadding = "topPadding";
54     private static final String JavaDoc ATTRIBUTE_leftBorder = "leftBorder";
55     private static final String JavaDoc ATTRIBUTE_leftBorderColor = "leftBorderColor";
56     private static final String JavaDoc ATTRIBUTE_leftPadding = "leftPadding";
57     private static final String JavaDoc ATTRIBUTE_bottomBorder = "bottomBorder";
58     private static final String JavaDoc ATTRIBUTE_bottomBorderColor = "bottomBorderColor";
59     private static final String JavaDoc ATTRIBUTE_bottomPadding = "bottomPadding";
60     private static final String JavaDoc ATTRIBUTE_rightBorder = "rightBorder";
61     private static final String JavaDoc ATTRIBUTE_rightBorderColor = "rightBorderColor";
62     private static final String JavaDoc ATTRIBUTE_rightPadding = "rightPadding";
63
64
65     /**
66      *
67      */

68     public Object JavaDoc createObject(Attributes JavaDoc atts)
69     {
70         JRBox box = (JRBox) digester.peek();
71         setBoxAttributes(atts, box);
72         return box;
73     }
74
75
76     public static void setBoxAttributes(Attributes JavaDoc atts, JRBox box)
77     {
78         Byte JavaDoc border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_border));
79         if (border != null)
80         {
81             box.setBorder(border);
82         }
83
84         Color JavaDoc borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_borderColor), null);
85         if (borderColor != null)
86         {
87             box.setBorderColor(borderColor);
88         }
89
90         String JavaDoc padding = atts.getValue(ATTRIBUTE_padding);
91         if (padding != null && padding.length() > 0)
92         {
93             box.setPadding(Integer.parseInt(padding));
94         }
95
96         border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_topBorder));
97         if (border != null)
98         {
99             box.setTopBorder(border);
100         }
101
102         borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_topBorderColor), Color.black);
103         if (borderColor != null)
104         {
105             box.setTopBorderColor(borderColor);
106         }
107
108         padding = atts.getValue(ATTRIBUTE_topPadding);
109         if (padding != null && padding.length() > 0)
110         {
111             box.setTopPadding(Integer.parseInt(padding));
112         }
113
114         border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_leftBorder));
115         if (border != null)
116         {
117             box.setLeftBorder(border);
118         }
119
120         borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_leftBorderColor), Color.black);
121         if (borderColor != null)
122         {
123             box.setLeftBorderColor(borderColor);
124         }
125
126         padding = atts.getValue(ATTRIBUTE_leftPadding);
127         if (padding != null && padding.length() > 0)
128         {
129             box.setLeftPadding(Integer.parseInt(padding));
130         }
131
132         border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_bottomBorder));
133         if (border != null)
134         {
135             box.setBottomBorder(border);
136         }
137
138         borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_bottomBorderColor), Color.black);
139         if (borderColor != null)
140         {
141             box.setBottomBorderColor(borderColor);
142         }
143
144         padding = atts.getValue(ATTRIBUTE_bottomPadding);
145         if (padding != null && padding.length() > 0)
146         {
147             box.setBottomPadding(Integer.parseInt(padding));
148         }
149
150         border = (Byte JavaDoc)JRXmlConstants.getPenMap().get(atts.getValue(ATTRIBUTE_rightBorder));
151         if (border != null)
152         {
153             box.setRightBorder(border);
154         }
155
156         borderColor = JRXmlConstants.getColor(atts.getValue(ATTRIBUTE_rightBorderColor), Color.black);
157         if (borderColor != null)
158         {
159             box.setRightBorderColor(borderColor);
160         }
161
162         padding = atts.getValue(ATTRIBUTE_rightPadding);
163         if (padding != null && padding.length() > 0)
164         {
165             box.setRightPadding(Integer.parseInt(padding));
166         }
167     }
168     
169
170 }
171
Popular Tags