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.design;
029:
030: import java.awt.Color;
031: import java.io.IOException;
032: import java.util.ArrayList;
033: import java.util.List;
034:
035: import net.sf.jasperreports.engine.JRAbstractObjectFactory;
036: import net.sf.jasperreports.engine.JRBox;
037: import net.sf.jasperreports.engine.JRChild;
038: import net.sf.jasperreports.engine.JRConstants;
039: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
040: import net.sf.jasperreports.engine.JRElement;
041: import net.sf.jasperreports.engine.JRElementGroup;
042: import net.sf.jasperreports.engine.JRExpressionCollector;
043: import net.sf.jasperreports.engine.JRFrame;
044: import net.sf.jasperreports.engine.base.JRBaseElementGroup;
045: import net.sf.jasperreports.engine.util.JRStyleResolver;
046: import net.sf.jasperreports.engine.xml.JRXmlWriter;
047:
048: /**
049: * Implementation of {@link net.sf.jasperreports.engine.JRFrame JRFrame} to be used at design time.
050: *
051: * @author Lucian Chirita (lucianc@users.sourceforge.net)
052: * @version $Id: JRDesignFrame.java 1229 2006-04-19 10:27:35Z teodord $
053: */
054: public class JRDesignFrame extends JRDesignElement implements JRFrame {
055: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
056:
057: private List children;
058:
059: /**
060: * Creates a new frame object.
061: *
062: * @param defaultStyleProvider default style provider instance
063: */
064: public JRDesignFrame(JRDefaultStyleProvider defaultStyleProvider) {
065: super (defaultStyleProvider);
066:
067: children = new ArrayList();
068: }
069:
070: /**
071: * Creates a new frame object.
072: */
073: public JRDesignFrame() {
074: this (null);
075: }
076:
077: public void collectExpressions(JRExpressionCollector collector) {
078: collector.collect(this );
079: }
080:
081: public JRChild getCopy(JRAbstractObjectFactory factory) {
082: return factory.getFrame(this );
083: }
084:
085: public void writeXml(JRXmlWriter writer) throws IOException {
086: writer.writeFrame(this );
087: }
088:
089: public JRElement[] getElements() {
090: return JRBaseElementGroup.getElements(children);
091: }
092:
093: /**
094: * Adds a sub element to the frame.
095: *
096: * @param element the element to add
097: */
098: public void addElement(JRElement element) {
099: children.add(element);
100: }
101:
102: /**
103: * Removes a sub element from the frame.
104: *
105: * @param element the element to remove
106: * @return <tt>true</tt> if this frame contained the specified element
107: */
108: public boolean removeElement(JRElement element) {
109: return children.remove(element);
110: }
111:
112: /**
113: * Adds an element group to the frame.
114: *
115: * @param group the element group to add
116: */
117: public void addElementGroup(JRElementGroup group) {
118: children.add(group);
119: }
120:
121: /**
122: * Removes a group element from the frame.
123: *
124: * @param group the group to remove
125: * @return <tt>true</tt> if this frame contained the specified group
126: */
127: public boolean removeElementGroup(JRElementGroup group) {
128: return children.remove(group);
129: }
130:
131: public List getChildren() {
132: return children;
133: }
134:
135: public JRElement getElementByKey(String elementKey) {
136: return JRBaseElementGroup.getElementByKey(getElements(),
137: elementKey);
138: }
139:
140: public byte getMode() {
141: return JRStyleResolver.getMode(this , MODE_TRANSPARENT);
142: }
143:
144: // box
145: protected Byte border;
146: protected Byte topBorder = null;
147: protected Byte leftBorder = null;
148: protected Byte bottomBorder = null;
149: protected Byte rightBorder = null;
150: protected Color borderColor = null;
151: protected Color topBorderColor = null;
152: protected Color leftBorderColor = null;
153: protected Color bottomBorderColor = null;
154: protected Color rightBorderColor = null;
155: protected Integer padding;
156: protected Integer topPadding = null;
157: protected Integer leftPadding = null;
158: protected Integer bottomPadding = null;
159: protected Integer rightPadding = null;
160:
161: public byte getBorder() {
162: return JRStyleResolver.getBorder(this );
163: }
164:
165: public Byte getOwnBorder() {
166: return border;
167: }
168:
169: public void setBorder(byte border) {
170: this .border = new Byte(border);
171: }
172:
173: public void setBorder(Byte border) {
174: this .border = border;
175: }
176:
177: public Color getBorderColor() {
178: return JRStyleResolver.getBorderColor(this , getForecolor());
179: }
180:
181: public Color getOwnBorderColor() {
182: return borderColor;
183: }
184:
185: public void setBorderColor(Color borderColor) {
186: this .borderColor = borderColor;
187: }
188:
189: public int getPadding() {
190: return JRStyleResolver.getPadding(this );
191: }
192:
193: public Integer getOwnPadding() {
194: return padding;
195: }
196:
197: public void setPadding(int padding) {
198: this .padding = new Integer(padding);
199: }
200:
201: public void setPadding(Integer padding) {
202: this .padding = padding;
203: }
204:
205: public byte getTopBorder() {
206: return JRStyleResolver.getTopBorder(this );
207: }
208:
209: public Byte getOwnTopBorder() {
210: return topBorder;
211: }
212:
213: public void setTopBorder(byte topBorder) {
214: this .topBorder = new Byte(topBorder);
215: }
216:
217: public void setTopBorder(Byte topBorder) {
218: this .topBorder = topBorder;
219: }
220:
221: public Color getTopBorderColor() {
222: return JRStyleResolver.getTopBorderColor(this , getForecolor());
223: }
224:
225: public Color getOwnTopBorderColor() {
226: return topBorderColor;
227: }
228:
229: public void setTopBorderColor(Color topBorderColor) {
230: this .topBorderColor = topBorderColor;
231: }
232:
233: public int getTopPadding() {
234: return JRStyleResolver.getTopPadding(this );
235: }
236:
237: public Integer getOwnTopPadding() {
238: return topPadding;
239: }
240:
241: public void setTopPadding(int topPadding) {
242: this .topPadding = new Integer(topPadding);
243: }
244:
245: public void setTopPadding(Integer topPadding) {
246: this .topPadding = topPadding;
247: }
248:
249: public byte getLeftBorder() {
250: return JRStyleResolver.getLeftBorder(this );
251: }
252:
253: public Byte getOwnLeftBorder() {
254: return leftBorder;
255: }
256:
257: public void setLeftBorder(byte leftBorder) {
258: this .leftBorder = new Byte(leftBorder);
259: }
260:
261: public void setLeftBorder(Byte leftBorder) {
262: this .leftBorder = leftBorder;
263: }
264:
265: public Color getLeftBorderColor() {
266: return JRStyleResolver.getLeftBorderColor(this , getForecolor());
267: }
268:
269: public Color getOwnLeftBorderColor() {
270: return leftBorderColor;
271: }
272:
273: public void setLeftBorderColor(Color leftBorderColor) {
274: this .leftBorderColor = leftBorderColor;
275: }
276:
277: public int getLeftPadding() {
278: return JRStyleResolver.getLeftPadding(this );
279: }
280:
281: public Integer getOwnLeftPadding() {
282: return leftPadding;
283: }
284:
285: public void setLeftPadding(int leftPadding) {
286: this .leftPadding = new Integer(leftPadding);
287: }
288:
289: public void setLeftPadding(Integer leftPadding) {
290: this .leftPadding = leftPadding;
291: }
292:
293: public byte getBottomBorder() {
294: return JRStyleResolver.getBottomBorder(this );
295: }
296:
297: public Byte getOwnBottomBorder() {
298: return bottomBorder;
299: }
300:
301: public void setBottomBorder(byte bottomBorder) {
302: this .bottomBorder = new Byte(bottomBorder);
303: }
304:
305: public void setBottomBorder(Byte bottomBorder) {
306: this .bottomBorder = bottomBorder;
307: }
308:
309: public Color getBottomBorderColor() {
310: return JRStyleResolver.getBottomBorderColor(this ,
311: getForecolor());
312: }
313:
314: public Color getOwnBottomBorderColor() {
315: return bottomBorderColor;
316: }
317:
318: public void setBottomBorderColor(Color bottomBorderColor) {
319: this .bottomBorderColor = bottomBorderColor;
320: }
321:
322: public int getBottomPadding() {
323: return JRStyleResolver.getBottomPadding(this );
324: }
325:
326: public Integer getOwnBottomPadding() {
327: return bottomPadding;
328: }
329:
330: public void setBottomPadding(int bottomPadding) {
331: this .bottomPadding = new Integer(bottomPadding);
332: }
333:
334: public void setBottomPadding(Integer bottomPadding) {
335: this .bottomPadding = bottomPadding;
336: }
337:
338: public byte getRightBorder() {
339: return JRStyleResolver.getRightBorder(this );
340: }
341:
342: public Byte getOwnRightBorder() {
343: return rightBorder;
344: }
345:
346: public void setRightBorder(byte rightBorder) {
347: this .rightBorder = new Byte(rightBorder);
348: }
349:
350: public void setRightBorder(Byte rightBorder) {
351: this .rightBorder = rightBorder;
352: }
353:
354: public Color getRightBorderColor() {
355: return JRStyleResolver
356: .getRightBorderColor(this , getForecolor());
357: }
358:
359: public Color getOwnRightBorderColor() {
360: return rightBorderColor;
361: }
362:
363: public void setRightBorderColor(Color rightBorderColor) {
364: this .rightBorderColor = rightBorderColor;
365: }
366:
367: public int getRightPadding() {
368: return JRStyleResolver.getRightPadding(this );
369: }
370:
371: public Integer getOwnRightPadding() {
372: return rightPadding;
373: }
374:
375: public void setRightPadding(int rightPadding) {
376: this .rightPadding = new Integer(rightPadding);
377: }
378:
379: public void setRightPadding(Integer rightPadding) {
380: this .rightPadding = rightPadding;
381: }
382:
383: /**
384: * Sets all the box attributes.
385: *
386: * @param box a box object to get the box attributes from
387: */
388: public void setBox(JRBox box) {
389: if (box != null) {
390: border = box.getOwnBorder();
391: topBorder = box.getOwnTopBorder();
392: leftBorder = box.getOwnLeftBorder();
393: bottomBorder = box.getOwnBottomBorder();
394: rightBorder = box.getOwnRightBorder();
395: borderColor = box.getOwnBorderColor();
396: topBorderColor = box.getOwnTopBorderColor();
397: leftBorderColor = box.getOwnLeftBorderColor();
398: bottomBorderColor = box.getOwnBottomBorderColor();
399: rightBorderColor = box.getOwnRightBorderColor();
400: padding = box.getOwnPadding();
401: topPadding = box.getOwnTopPadding();
402: leftPadding = box.getOwnLeftPadding();
403: bottomPadding = box.getOwnBottomPadding();
404: rightPadding = box.getOwnRightPadding();
405: }
406: }
407: }
|