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.base;
029:
030: import java.awt.Color;
031: import java.io.Serializable;
032:
033: import net.sf.jasperreports.engine.JRBox;
034: import net.sf.jasperreports.engine.JRConstants;
035: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
036: import net.sf.jasperreports.engine.JRGraphicElement;
037: import net.sf.jasperreports.engine.JRStyle;
038: import net.sf.jasperreports.engine.util.JRStyleResolver;
039:
040: /**
041: * This is useful for drawing borders around text elements and images. Boxes can have borders and paddings, which can
042: * have different width and colour on each side of the element.
043: * @author Teodor Danciu (teodord@users.sourceforge.net)
044: * @version $Id: JRBaseBox.java 1759 2007-06-20 16:47:34Z lucianc $
045: */
046: public class JRBaseBox implements JRBox, Serializable {
047:
048: /**
049: *
050: */
051: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
052:
053: /**
054: *
055: */
056: protected Byte border = null;
057: protected Byte topBorder = null;
058: protected Byte leftBorder = null;
059: protected Byte bottomBorder = null;
060: protected Byte rightBorder = null;
061: protected Color borderColor = null;
062: protected Color topBorderColor = null;
063: protected Color leftBorderColor = null;
064: protected Color bottomBorderColor = null;
065: protected Color rightBorderColor = null;
066: protected Integer padding = null;
067: protected Integer topPadding = null;
068: protected Integer leftPadding = null;
069: protected Integer bottomPadding = null;
070: protected Integer rightPadding = null;
071:
072: /**
073: *
074: */
075: public JRBaseBox() {
076: super ();
077: }
078:
079: public JRBaseBox(byte pen, Color color) {
080: setBorder(pen);
081: setBorderColor(color);
082: }
083:
084: /**
085: * Creates a clone of a box object.
086: *
087: * @param box the object to be cloned
088: */
089: public JRBaseBox(JRBox box) {
090: border = box.getOwnBorder();
091: borderColor = box.getOwnBorderColor();
092: padding = box.getOwnPadding();
093:
094: topBorder = box.getOwnTopBorder();
095: topBorderColor = box.getOwnTopBorderColor();
096: topPadding = box.getOwnTopPadding();
097:
098: leftBorder = box.getOwnLeftBorder();
099: leftBorderColor = box.getOwnLeftBorderColor();
100: leftPadding = box.getOwnLeftPadding();
101:
102: bottomBorder = box.getOwnBottomBorder();
103: bottomBorderColor = box.getOwnBottomBorderColor();
104: bottomPadding = box.getOwnBottomPadding();
105:
106: rightBorder = box.getOwnRightBorder();
107: rightBorderColor = box.getOwnRightBorderColor();
108: rightPadding = box.getOwnRightPadding();
109: }
110:
111: /**
112: * Creates a copy of a box object by keeping only some of the border sides.
113: *
114: * @param box the object to be cloned
115: * @param left whether to keep the left border
116: * @param right whether to keep the right border
117: * @param top whether to keep the top border
118: * @param bottom whether to keep the bottom border
119: * @param complementaryBox complementary box
120: */
121: public JRBaseBox(JRBox box, boolean left, boolean right,
122: boolean top, boolean bottom, JRBox complementaryBox) {
123: if (left && box.getLeftBorder() != JRGraphicElement.PEN_NONE) {
124: leftBorder = new Byte(box.getLeftBorder());
125: leftBorderColor = box.getLeftBorderColor();
126: leftPadding = new Integer(box.getLeftPadding());
127: } else if (complementaryBox != null) {
128: leftBorder = new Byte(complementaryBox.getLeftBorder());
129: leftBorderColor = complementaryBox.getLeftBorderColor();
130: leftPadding = new Integer(complementaryBox.getLeftPadding());
131: }
132:
133: if (right && box.getRightBorder() != JRGraphicElement.PEN_NONE) {
134: rightBorder = new Byte(box.getRightBorder());
135: rightBorderColor = box.getRightBorderColor();
136: rightPadding = new Integer(box.getRightPadding());
137: } else if (complementaryBox != null) {
138: rightBorder = new Byte(complementaryBox.getRightBorder());
139: rightBorderColor = complementaryBox.getRightBorderColor();
140: rightPadding = new Integer(complementaryBox
141: .getRightPadding());
142: }
143:
144: if (top && box.getTopBorder() != JRGraphicElement.PEN_NONE) {
145: topBorder = new Byte(box.getTopBorder());
146: topBorderColor = box.getTopBorderColor();
147: topPadding = new Integer(box.getTopPadding());
148: } else if (complementaryBox != null) {
149: topBorder = new Byte(complementaryBox.getTopBorder());
150: topBorderColor = complementaryBox.getTopBorderColor();
151: topPadding = new Integer(complementaryBox.getTopPadding());
152: }
153:
154: if (bottom
155: && box.getBottomBorder() != JRGraphicElement.PEN_NONE) {
156: bottomBorder = new Byte(box.getBottomBorder());
157: bottomBorderColor = box.getBottomBorderColor();
158: bottomPadding = new Integer(box.getBottomPadding());
159: } else if (complementaryBox != null) {
160: bottomBorder = new Byte(complementaryBox.getBottomBorder());
161: bottomBorderColor = complementaryBox.getBottomBorderColor();
162: bottomPadding = new Integer(complementaryBox
163: .getBottomPadding());
164: }
165: }
166:
167: public JRBaseBox(JRBox box, boolean resetLeft, boolean resetRight,
168: boolean resetTop, boolean resetBottom) {
169: border = box.getOwnBorder();
170: borderColor = box.getOwnBorderColor();
171: padding = box.getOwnPadding();
172:
173: if (resetLeft) {
174: leftBorder = new Byte(JRGraphicElement.PEN_NONE);
175: leftBorderColor = null;
176: leftPadding = new Integer(0);
177: } else {
178: leftBorder = box.getOwnLeftBorder();
179: leftBorderColor = box.getOwnLeftBorderColor();
180: leftPadding = box.getOwnLeftPadding();
181: }
182:
183: if (resetTop) {
184: topBorder = new Byte(JRGraphicElement.PEN_NONE);
185: topBorderColor = null;
186: topPadding = new Integer(0);
187: } else {
188: topBorder = box.getOwnTopBorder();
189: topBorderColor = box.getOwnTopBorderColor();
190: topPadding = box.getOwnTopPadding();
191: }
192:
193: if (resetRight) {
194: rightBorder = new Byte(JRGraphicElement.PEN_NONE);
195: rightBorderColor = null;
196: rightPadding = new Integer(0);
197: } else {
198: rightBorder = box.getOwnRightBorder();
199: rightBorderColor = box.getOwnRightBorderColor();
200: rightPadding = box.getOwnRightPadding();
201: }
202:
203: if (resetBottom) {
204: bottomBorder = new Byte(JRGraphicElement.PEN_NONE);
205: bottomBorderColor = null;
206: bottomPadding = new Integer(0);
207: } else {
208: bottomBorder = box.getOwnBottomBorder();
209: bottomBorderColor = box.getOwnBottomBorderColor();
210: bottomPadding = box.getOwnBottomPadding();
211: }
212: }
213:
214: /**
215: *
216: */
217: public JRDefaultStyleProvider getDefaultStyleProvider() {
218: return null;
219: }
220:
221: /**
222: *
223: */
224: public JRStyle getStyle() {
225: return null;
226: }
227:
228: /**
229: *
230: */
231: public byte getBorder() {
232: return JRStyleResolver.getBorder(this );
233: }
234:
235: /**
236: *
237: */
238: public Byte getOwnBorder() {
239: return border;
240: }
241:
242: /**
243: *
244: */
245: public void setBorder(byte border) {
246: this .border = new Byte(border);
247: }
248:
249: /**
250: *
251: */
252: public void setBorder(Byte border) {
253: this .border = border;
254: }
255:
256: /**
257: *
258: */
259: public Color getBorderColor() {
260: return JRStyleResolver.getBorderColor(this , Color.black);
261: }
262:
263: public Color getOwnBorderColor() {
264: return borderColor;
265: }
266:
267: /**
268: *
269: */
270: public void setBorderColor(Color borderColor) {
271: this .borderColor = borderColor;
272: }
273:
274: /**
275: *
276: */
277: public int getPadding() {
278: return JRStyleResolver.getPadding(this );
279: }
280:
281: public Integer getOwnPadding() {
282: return padding;
283: }
284:
285: /**
286: *
287: */
288: public void setPadding(int padding) {
289: this .padding = new Integer(padding);
290: }
291:
292: /**
293: *
294: */
295: public void setPadding(Integer padding) {
296: this .padding = padding;
297: }
298:
299: /**
300: *
301: */
302: public byte getTopBorder() {
303: return JRStyleResolver.getTopBorder(this );
304: }
305:
306: /**
307: *
308: */
309: public Byte getOwnTopBorder() {
310: return topBorder;
311: }
312:
313: /**
314: *
315: */
316: public void setTopBorder(byte topBorder) {
317: this .topBorder = new Byte(topBorder);
318: }
319:
320: /**
321: *
322: */
323: public void setTopBorder(Byte topBorder) {
324: this .topBorder = topBorder;
325: }
326:
327: /**
328: *
329: */
330: public Color getTopBorderColor() {
331: return JRStyleResolver.getTopBorderColor(this , Color.black);
332: }
333:
334: /**
335: *
336: */
337: public Color getOwnTopBorderColor() {
338: return topBorderColor;
339: }
340:
341: /**
342: *
343: */
344: public void setTopBorderColor(Color topBorderColor) {
345: this .topBorderColor = topBorderColor;
346: }
347:
348: /**
349: *
350: */
351: public int getTopPadding() {
352: return JRStyleResolver.getTopPadding(this );
353: }
354:
355: /**
356: *
357: */
358: public Integer getOwnTopPadding() {
359: return topPadding;
360: }
361:
362: /**
363: *
364: */
365: public void setTopPadding(int topPadding) {
366: this .topPadding = new Integer(topPadding);
367: }
368:
369: /**
370: *
371: */
372: public void setTopPadding(Integer topPadding) {
373: this .topPadding = topPadding;
374: }
375:
376: /**
377: *
378: */
379: public byte getLeftBorder() {
380: return JRStyleResolver.getLeftBorder(this );
381: }
382:
383: /**
384: *
385: */
386: public Byte getOwnLeftBorder() {
387: return leftBorder;
388: }
389:
390: /**
391: *
392: */
393: public void setLeftBorder(byte leftBorder) {
394: this .leftBorder = new Byte(leftBorder);
395: }
396:
397: /**
398: *
399: */
400: public void setLeftBorder(Byte leftBorder) {
401: this .leftBorder = leftBorder;
402: }
403:
404: /**
405: *
406: */
407: public Color getLeftBorderColor() {
408: return JRStyleResolver.getLeftBorderColor(this , Color.black);
409: }
410:
411: /**
412: *
413: */
414: public Color getOwnLeftBorderColor() {
415: return leftBorderColor;
416: }
417:
418: /**
419: *
420: */
421: public void setLeftBorderColor(Color leftBorderColor) {
422: this .leftBorderColor = leftBorderColor;
423: }
424:
425: /**
426: *
427: */
428: public int getLeftPadding() {
429: return JRStyleResolver.getLeftPadding(this );
430: }
431:
432: /**
433: *
434: */
435: public Integer getOwnLeftPadding() {
436: return leftPadding;
437: }
438:
439: /**
440: *
441: */
442: public void setLeftPadding(int leftPadding) {
443: this .leftPadding = new Integer(leftPadding);
444: }
445:
446: /**
447: *
448: */
449: public void setLeftPadding(Integer leftPadding) {
450: this .leftPadding = leftPadding;
451: }
452:
453: /**
454: *
455: */
456: public byte getBottomBorder() {
457: return JRStyleResolver.getBottomBorder(this );
458: }
459:
460: /**
461: *
462: */
463: public Byte getOwnBottomBorder() {
464: return bottomBorder;
465: }
466:
467: /**
468: *
469: */
470: public void setBottomBorder(byte bottomBorder) {
471: this .bottomBorder = new Byte(bottomBorder);
472: }
473:
474: /**
475: *
476: */
477: public void setBottomBorder(Byte bottomBorder) {
478: this .bottomBorder = bottomBorder;
479: }
480:
481: /**
482: *
483: */
484: public Color getBottomBorderColor() {
485: return JRStyleResolver.getBottomBorderColor(this , Color.black);
486: }
487:
488: /**
489: *
490: */
491: public Color getOwnBottomBorderColor() {
492: return bottomBorderColor;
493: }
494:
495: /**
496: *
497: */
498: public void setBottomBorderColor(Color bottomBorderColor) {
499: this .bottomBorderColor = bottomBorderColor;
500: }
501:
502: /**
503: *
504: */
505: public int getBottomPadding() {
506: return JRStyleResolver.getBottomPadding(this );
507: }
508:
509: /**
510: *
511: */
512: public Integer getOwnBottomPadding() {
513: return bottomPadding;
514: }
515:
516: /**
517: *
518: */
519: public void setBottomPadding(int bottomPadding) {
520: this .bottomPadding = new Integer(bottomPadding);
521: }
522:
523: /**
524: *
525: */
526: public void setBottomPadding(Integer bottomPadding) {
527: this .bottomPadding = bottomPadding;
528: }
529:
530: /**
531: *
532: */
533: public byte getRightBorder() {
534: return JRStyleResolver.getRightBorder(this );
535: }
536:
537: /**
538: *
539: */
540: public Byte getOwnRightBorder() {
541: return rightBorder;
542: }
543:
544: /**
545: *
546: */
547: public void setRightBorder(byte rightBorder) {
548: this .rightBorder = new Byte(rightBorder);
549: }
550:
551: /**
552: *
553: */
554: public void setRightBorder(Byte rightBorder) {
555: this .rightBorder = rightBorder;
556: }
557:
558: /**
559: *
560: */
561: public Color getRightBorderColor() {
562: return JRStyleResolver.getRightBorderColor(this , Color.black);
563: }
564:
565: /**
566: *
567: */
568: public Color getOwnRightBorderColor() {
569: return rightBorderColor;
570: }
571:
572: /**
573: *
574: */
575: public void setRightBorderColor(Color rightBorderColor) {
576: this .rightBorderColor = rightBorderColor;
577: }
578:
579: /**
580: *
581: */
582: public int getRightPadding() {
583: return JRStyleResolver.getRightPadding(this );
584: }
585:
586: /**
587: *
588: */
589: public Integer getOwnRightPadding() {
590: return rightPadding;
591: }
592:
593: /**
594: *
595: */
596: public void setRightPadding(int rightPadding) {
597: this .rightPadding = new Integer(rightPadding);
598: }
599:
600: /**
601: *
602: */
603: public void setRightPadding(Integer rightPadding) {
604: this .rightPadding = rightPadding;
605: }
606:
607: public String getStyleNameReference() {
608: return null;
609: }
610:
611: }
|