KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > base > JRBaseBox


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.base;
29
30 import java.awt.Color JavaDoc;
31 import java.io.Serializable JavaDoc;
32
33 import net.sf.jasperreports.engine.JRBox;
34 import net.sf.jasperreports.engine.JRConstants;
35 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
36 import net.sf.jasperreports.engine.JRGraphicElement;
37 import net.sf.jasperreports.engine.JRStyle;
38 import net.sf.jasperreports.engine.util.JRStyleResolver;
39
40
41 /**
42  * This is useful for drawing borders around text elements and images. Boxes can have borders and paddings, which can
43  * have different width and colour on each side of the element.
44  * @author Teodor Danciu (teodord@users.sourceforge.net)
45  * @version $Id: JRBaseBox.java 1473 2006-11-09 19:48:03 +0200 (Thu, 09 Nov 2006) lucianc $
46  */

47 public class JRBaseBox implements JRBox, Serializable JavaDoc
48 {
49
50
51     /**
52      *
53      */

54     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
55
56     /**
57      *
58      */

59     protected Byte JavaDoc border = null;
60     protected Byte JavaDoc topBorder = null;
61     protected Byte JavaDoc leftBorder = null;
62     protected Byte JavaDoc bottomBorder = null;
63     protected Byte JavaDoc rightBorder = null;
64     protected Color JavaDoc borderColor = null;
65     protected Color JavaDoc topBorderColor = null;
66     protected Color JavaDoc leftBorderColor = null;
67     protected Color JavaDoc bottomBorderColor = null;
68     protected Color JavaDoc rightBorderColor = null;
69     protected Integer JavaDoc padding = null;
70     protected Integer JavaDoc topPadding = null;
71     protected Integer JavaDoc leftPadding = null;
72     protected Integer JavaDoc bottomPadding = null;
73     protected Integer JavaDoc rightPadding = null;
74
75     
76     /**
77      *
78      */

79     public JRBaseBox()
80     {
81         super();
82     }
83     
84     
85     public JRBaseBox(byte pen, Color JavaDoc color)
86     {
87         setBorder(pen);
88         setBorderColor(color);
89     }
90
91     /**
92      * Creates a clone of a box object.
93      *
94      * @param box the object to be cloned
95      */

96     public JRBaseBox(JRBox box)
97     {
98         border = box.getOwnBorder();
99         borderColor = box.getOwnBorderColor();
100         padding = box.getOwnPadding();
101         
102         topBorder = box.getOwnTopBorder();
103         topBorderColor = box.getOwnTopBorderColor();
104         topPadding = box.getOwnTopPadding();
105         
106         leftBorder = box.getOwnLeftBorder();
107         leftBorderColor = box.getOwnLeftBorderColor();
108         leftPadding = box.getOwnLeftPadding();
109         
110         bottomBorder = box.getOwnBottomBorder();
111         bottomBorderColor = box.getOwnBottomBorderColor();
112         bottomPadding = box.getOwnBottomPadding();
113         
114         rightBorder = box.getOwnRightBorder();
115         rightBorderColor = box.getOwnRightBorderColor();
116         rightPadding = box.getOwnRightPadding();
117     }
118     
119
120     /**
121      * Creates a copy of a box object by keeping only some of the border sides.
122      *
123      * @param box the object to be cloned
124      * @param left whether to keep the left border
125      * @param right whether to keep the right border
126      * @param top whether to keep the top border
127      * @param bottom whether to keep the bottom border
128      * @param complementaryBox complementary box
129      */

130     public JRBaseBox(JRBox box, boolean left, boolean right, boolean top, boolean bottom, JRBox complementaryBox)
131     {
132         if (left && box.getLeftBorder() != JRGraphicElement.PEN_NONE)
133         {
134             leftBorder = new Byte JavaDoc(box.getLeftBorder());
135             leftBorderColor = box.getLeftBorderColor();
136             leftPadding = new Integer JavaDoc(box.getLeftPadding());
137         }
138         else if (complementaryBox != null)
139         {
140             leftBorder = new Byte JavaDoc(complementaryBox.getLeftBorder());
141             leftBorderColor = complementaryBox.getLeftBorderColor();
142             leftPadding = new Integer JavaDoc(complementaryBox.getLeftPadding());
143         }
144         
145         if (right && box.getRightBorder() != JRGraphicElement.PEN_NONE)
146         {
147             rightBorder = new Byte JavaDoc(box.getRightBorder());
148             rightBorderColor = box.getRightBorderColor();
149             rightPadding = new Integer JavaDoc(box.getRightPadding());
150         }
151         else if (complementaryBox != null)
152         {
153             rightBorder = new Byte JavaDoc(complementaryBox.getRightBorder());
154             rightBorderColor = complementaryBox.getRightBorderColor();
155             rightPadding = new Integer JavaDoc(complementaryBox.getRightPadding());
156         }
157         
158         if (top && box.getTopBorder() != JRGraphicElement.PEN_NONE)
159         {
160             topBorder = new Byte JavaDoc(box.getTopBorder());
161             topBorderColor = box.getTopBorderColor();
162             topPadding = new Integer JavaDoc(box.getTopPadding());
163         }
164         else if (complementaryBox != null)
165         {
166             topBorder = new Byte JavaDoc(complementaryBox.getTopBorder());
167             topBorderColor = complementaryBox.getTopBorderColor();
168             topPadding = new Integer JavaDoc(complementaryBox.getTopPadding());
169         }
170         
171         if (bottom && box.getBottomBorder() != JRGraphicElement.PEN_NONE)
172         {
173             bottomBorder = new Byte JavaDoc(box.getBottomBorder());
174             bottomBorderColor = box.getBottomBorderColor();
175             bottomPadding = new Integer JavaDoc(box.getBottomPadding());
176         }
177         else if (complementaryBox != null)
178         {
179             bottomBorder = new Byte JavaDoc(complementaryBox.getBottomBorder());
180             bottomBorderColor = complementaryBox.getBottomBorderColor();
181             bottomPadding = new Integer JavaDoc(complementaryBox.getBottomPadding());
182         }
183     }
184
185     
186     public JRBaseBox(JRBox box, boolean resetLeft, boolean resetRight, boolean resetTop, boolean resetBottom)
187     {
188         border = box.getOwnBorder();
189         borderColor = box.getOwnBorderColor();
190         padding = box.getOwnPadding();
191         
192         if (resetLeft)
193         {
194             leftBorder = new Byte JavaDoc(JRGraphicElement.PEN_NONE);
195             leftBorderColor = null;
196             leftPadding = new Integer JavaDoc(0);
197         }
198         else
199         {
200             leftBorder = box.getOwnLeftBorder();
201             leftBorderColor = box.getOwnLeftBorderColor();
202             leftPadding = box.getOwnLeftPadding();
203         }
204         
205         if (resetTop)
206         {
207             topBorder = new Byte JavaDoc(JRGraphicElement.PEN_NONE);
208             topBorderColor = null;
209             topPadding = new Integer JavaDoc(0);
210         }
211         else
212         {
213             topBorder = box.getOwnTopBorder();
214             topBorderColor = box.getOwnTopBorderColor();
215             topPadding = box.getOwnTopPadding();
216         }
217         
218         if (resetRight)
219         {
220             rightBorder = new Byte JavaDoc(JRGraphicElement.PEN_NONE);
221             rightBorderColor = null;
222             rightPadding = new Integer JavaDoc(0);
223         }
224         else
225         {
226             rightBorder = box.getOwnRightBorder();
227             rightBorderColor = box.getOwnRightBorderColor();
228             rightPadding = box.getOwnRightPadding();
229         }
230         
231         if (resetBottom)
232         {
233             bottomBorder = new Byte JavaDoc(JRGraphicElement.PEN_NONE);
234             bottomBorderColor = null;
235             bottomPadding = new Integer JavaDoc(0);
236         }
237         else
238         {
239             bottomBorder = box.getOwnBottomBorder();
240             bottomBorderColor = box.getOwnBottomBorderColor();
241             bottomPadding = box.getOwnBottomPadding();
242         }
243     }
244     
245     /**
246      *
247      */

248     public JRDefaultStyleProvider getDefaultStyleProvider()
249     {
250         return null;
251     }
252
253     /**
254      *
255      */

256     public JRStyle getStyle()
257     {
258         return null;
259     }
260
261     /**
262      *
263      */

264     public byte getBorder()
265     {
266         return JRStyleResolver.getBorder(this);
267     }
268
269     /**
270      *
271      */

272     public Byte JavaDoc getOwnBorder()
273     {
274         return border;
275     }
276
277     /**
278      *
279      */

280     public void setBorder(byte border)
281     {
282         this.border = new Byte JavaDoc(border);
283     }
284
285     /**
286      *
287      */

288     public void setBorder(Byte JavaDoc border)
289     {
290         this.border = border;
291     }
292
293     /**
294      *
295      */

296     public Color JavaDoc getBorderColor()
297     {
298         return JRStyleResolver.getBorderColor(this, Color.black);
299     }
300
301     public Color JavaDoc getOwnBorderColor()
302     {
303         return borderColor;
304     }
305     
306     /**
307      *
308      */

309     public void setBorderColor(Color JavaDoc borderColor)
310     {
311         this.borderColor = borderColor;
312     }
313
314     /**
315      *
316      */

317     public int getPadding()
318     {
319         return JRStyleResolver.getPadding(this);
320     }
321
322     public Integer JavaDoc getOwnPadding()
323     {
324         return padding;
325     }
326     
327     /**
328      *
329      */

330     public void setPadding(int padding)
331     {
332         this.padding = new Integer JavaDoc(padding);
333     }
334
335     /**
336      *
337      */

338     public void setPadding(Integer JavaDoc padding)
339     {
340         this.padding = padding;
341     }
342
343     /**
344      *
345      */

346     public byte getTopBorder()
347     {
348         return JRStyleResolver.getTopBorder(this);
349     }
350
351     /**
352      *
353      */

354     public Byte JavaDoc getOwnTopBorder()
355     {
356         return topBorder;
357     }
358
359     /**
360      *
361      */

362     public void setTopBorder(byte topBorder)
363     {
364         this.topBorder = new Byte JavaDoc(topBorder);
365     }
366
367     /**
368      *
369      */

370     public void setTopBorder(Byte JavaDoc topBorder)
371     {
372         this.topBorder = topBorder;
373     }
374
375     /**
376      *
377      */

378     public Color JavaDoc getTopBorderColor()
379     {
380         return JRStyleResolver.getTopBorderColor(this, Color.black);
381     }
382
383     /**
384      *
385      */

386     public Color JavaDoc getOwnTopBorderColor()
387     {
388         return topBorderColor;
389     }
390
391     /**
392      *
393      */

394     public void setTopBorderColor(Color JavaDoc topBorderColor)
395     {
396         this.topBorderColor = topBorderColor;
397     }
398
399     /**
400      *
401      */

402     public int getTopPadding()
403     {
404         return JRStyleResolver.getTopPadding(this);
405     }
406
407     /**
408      *
409      */

410     public Integer JavaDoc getOwnTopPadding()
411     {
412         return topPadding;
413     }
414
415     /**
416      *
417      */

418     public void setTopPadding(int topPadding)
419     {
420         this.topPadding = new Integer JavaDoc(topPadding);
421     }
422
423     /**
424      *
425      */

426     public void setTopPadding(Integer JavaDoc topPadding)
427     {
428         this.topPadding = topPadding;
429     }
430
431     /**
432      *
433      */

434     public byte getLeftBorder()
435     {
436         return JRStyleResolver.getLeftBorder(this);
437     }
438
439     /**
440      *
441      */

442     public Byte JavaDoc getOwnLeftBorder()
443     {
444         return leftBorder;
445     }
446
447     /**
448      *
449      */

450     public void setLeftBorder(byte leftBorder)
451     {
452         this.leftBorder = new Byte JavaDoc(leftBorder);
453     }
454
455     /**
456      *
457      */

458     public void setLeftBorder(Byte JavaDoc leftBorder)
459     {
460         this.leftBorder = leftBorder;
461     }
462
463     /**
464      *
465      */

466     public Color JavaDoc getLeftBorderColor()
467     {
468         return JRStyleResolver.getLeftBorderColor(this, Color.black);
469     }
470
471     /**
472      *
473      */

474     public Color JavaDoc getOwnLeftBorderColor()
475     {
476         return leftBorderColor;
477     }
478
479     /**
480      *
481      */

482     public void setLeftBorderColor(Color JavaDoc leftBorderColor)
483     {
484         this.leftBorderColor = leftBorderColor;
485     }
486
487     /**
488      *
489      */

490     public int getLeftPadding()
491     {
492         return JRStyleResolver.getLeftPadding(this);
493     }
494
495     /**
496      *
497      */

498     public Integer JavaDoc getOwnLeftPadding()
499     {
500         return leftPadding;
501     }
502
503     /**
504      *
505      */

506     public void setLeftPadding(int leftPadding)
507     {
508         this.leftPadding = new Integer JavaDoc(leftPadding);
509     }
510
511     /**
512      *
513      */

514     public void setLeftPadding(Integer JavaDoc leftPadding)
515     {
516         this.leftPadding = leftPadding;
517     }
518
519     /**
520      *
521      */

522     public byte getBottomBorder()
523     {
524         return JRStyleResolver.getBottomBorder(this);
525     }
526
527     /**
528      *
529      */

530     public Byte JavaDoc getOwnBottomBorder()
531     {
532         return bottomBorder;
533     }
534
535     /**
536      *
537      */

538     public void setBottomBorder(byte bottomBorder)
539     {
540         this.bottomBorder = new Byte JavaDoc(bottomBorder);
541     }
542
543     /**
544      *
545      */

546     public void setBottomBorder(Byte JavaDoc bottomBorder)
547     {
548         this.bottomBorder = bottomBorder;
549     }
550
551     /**
552      *
553      */

554     public Color JavaDoc getBottomBorderColor()
555     {
556         return JRStyleResolver.getBottomBorderColor(this, Color.black);
557     }
558
559     /**
560      *
561      */

562     public Color JavaDoc getOwnBottomBorderColor()
563     {
564         return bottomBorderColor;
565     }
566
567     /**
568      *
569      */

570     public void setBottomBorderColor(Color JavaDoc bottomBorderColor)
571     {
572         this.bottomBorderColor = bottomBorderColor;
573     }
574
575     /**
576      *
577      */

578     public int getBottomPadding()
579     {
580         return JRStyleResolver.getBottomPadding(this);
581     }
582
583     /**
584      *
585      */

586     public Integer JavaDoc getOwnBottomPadding()
587     {
588         return bottomPadding;
589     }
590
591     /**
592      *
593      */

594     public void setBottomPadding(int bottomPadding)
595     {
596         this.bottomPadding = new Integer JavaDoc(bottomPadding);
597     }
598
599     /**
600      *
601      */

602     public void setBottomPadding(Integer JavaDoc bottomPadding)
603     {
604         this.bottomPadding = bottomPadding;
605     }
606
607     /**
608      *
609      */

610     public byte getRightBorder()
611     {
612         return JRStyleResolver.getRightBorder(this);
613     }
614
615     /**
616      *
617      */

618     public Byte JavaDoc getOwnRightBorder()
619     {
620         return rightBorder;
621     }
622
623     /**
624      *
625      */

626     public void setRightBorder(byte rightBorder)
627     {
628         this.rightBorder = new Byte JavaDoc(rightBorder);
629     }
630
631     /**
632      *
633      */

634     public void setRightBorder(Byte JavaDoc rightBorder)
635     {
636         this.rightBorder = rightBorder;
637     }
638
639     /**
640      *
641      */

642     public Color JavaDoc getRightBorderColor()
643     {
644         return JRStyleResolver.getRightBorderColor(this, Color.black);
645     }
646
647     /**
648      *
649      */

650     public Color JavaDoc getOwnRightBorderColor()
651     {
652         return rightBorderColor;
653     }
654
655     /**
656      *
657      */

658     public void setRightBorderColor(Color JavaDoc rightBorderColor)
659     {
660         this.rightBorderColor = rightBorderColor;
661     }
662
663     /**
664      *
665      */

666     public int getRightPadding()
667     {
668         return JRStyleResolver.getRightPadding(this);
669     }
670
671     /**
672      *
673      */

674     public Integer JavaDoc getOwnRightPadding()
675     {
676         return rightPadding;
677     }
678
679     /**
680      *
681      */

682     public void setRightPadding(int rightPadding)
683     {
684         this.rightPadding = new Integer JavaDoc(rightPadding);
685     }
686
687     /**
688      *
689      */

690     public void setRightPadding(Integer JavaDoc rightPadding)
691     {
692         this.rightPadding = rightPadding;
693     }
694
695
696 }
697
Popular Tags