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 net.sf.jasperreports.engine.JRBox;
033:
034: import org.xml.sax.Attributes;
035:
036: /**
037: * @author Teodor Danciu (teodord@users.sourceforge.net)
038: * @version $Id: JRBoxFactory.java 1581 2007-02-12 14:19:02Z shertage $
039: */
040: public class JRBoxFactory extends JRBaseFactory {
041:
042: /**
043: *
044: */
045: public Object createObject(Attributes atts) {
046: JRBox box = (JRBox) digester.peek();
047: setBoxAttributes(atts, box);
048: return box;
049: }
050:
051: public static void setBoxAttributes(Attributes atts, JRBox box) {
052: Byte border = (Byte) JRXmlConstants.getPenMap().get(
053: atts.getValue(JRXmlConstants.ATTRIBUTE_border));
054: if (border != null) {
055: box.setBorder(border);
056: }
057:
058: Color borderColor = JRXmlConstants.getColor(atts
059: .getValue(JRXmlConstants.ATTRIBUTE_borderColor), null);
060: if (borderColor != null) {
061: box.setBorderColor(borderColor);
062: }
063:
064: String padding = atts
065: .getValue(JRXmlConstants.ATTRIBUTE_padding);
066: if (padding != null && padding.length() > 0) {
067: box.setPadding(Integer.parseInt(padding));
068: }
069:
070: border = (Byte) JRXmlConstants.getPenMap().get(
071: atts.getValue(JRXmlConstants.ATTRIBUTE_topBorder));
072: if (border != null) {
073: box.setTopBorder(border);
074: }
075:
076: borderColor = JRXmlConstants.getColor(atts
077: .getValue(JRXmlConstants.ATTRIBUTE_topBorderColor),
078: Color.black);
079: if (borderColor != null) {
080: box.setTopBorderColor(borderColor);
081: }
082:
083: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_topPadding);
084: if (padding != null && padding.length() > 0) {
085: box.setTopPadding(Integer.parseInt(padding));
086: }
087:
088: border = (Byte) JRXmlConstants.getPenMap().get(
089: atts.getValue(JRXmlConstants.ATTRIBUTE_leftBorder));
090: if (border != null) {
091: box.setLeftBorder(border);
092: }
093:
094: borderColor = JRXmlConstants.getColor(atts
095: .getValue(JRXmlConstants.ATTRIBUTE_leftBorderColor),
096: Color.black);
097: if (borderColor != null) {
098: box.setLeftBorderColor(borderColor);
099: }
100:
101: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_leftPadding);
102: if (padding != null && padding.length() > 0) {
103: box.setLeftPadding(Integer.parseInt(padding));
104: }
105:
106: border = (Byte) JRXmlConstants.getPenMap().get(
107: atts.getValue(JRXmlConstants.ATTRIBUTE_bottomBorder));
108: if (border != null) {
109: box.setBottomBorder(border);
110: }
111:
112: borderColor = JRXmlConstants.getColor(atts
113: .getValue(JRXmlConstants.ATTRIBUTE_bottomBorderColor),
114: Color.black);
115: if (borderColor != null) {
116: box.setBottomBorderColor(borderColor);
117: }
118:
119: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_bottomPadding);
120: if (padding != null && padding.length() > 0) {
121: box.setBottomPadding(Integer.parseInt(padding));
122: }
123:
124: border = (Byte) JRXmlConstants.getPenMap().get(
125: atts.getValue(JRXmlConstants.ATTRIBUTE_rightBorder));
126: if (border != null) {
127: box.setRightBorder(border);
128: }
129:
130: borderColor = JRXmlConstants.getColor(atts
131: .getValue(JRXmlConstants.ATTRIBUTE_rightBorderColor),
132: Color.black);
133: if (borderColor != null) {
134: box.setRightBorderColor(borderColor);
135: }
136:
137: padding = atts.getValue(JRXmlConstants.ATTRIBUTE_rightPadding);
138: if (padding != null && padding.length() > 0) {
139: box.setRightPadding(Integer.parseInt(padding));
140: }
141: }
142:
143: }
|