KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > BreakReportElement


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * LineReportElement.java
28  *
29  * Created on 28 febbraio 2003, 20.02
30  *
31  */

32
33 package it.businesslogic.ireport;
34
35 import it.businesslogic.ireport.gui.*;
36 import it.businesslogic.ireport.util.*;
37 import java.awt.*;
38 import java.awt.image.*;
39 import java.awt.geom.*;
40 import javax.swing.ImageIcon JavaDoc;
41 import javax.swing.JPanel JavaDoc;
42
43 public class BreakReportElement extends ReportElement
44 {
45
46         public static ImageIcon JavaDoc img=null;
47         
48         static {
49                img = new ImageIcon JavaDoc( BreakReportElement.class.getResource("/it/businesslogic/ireport/icons/tree/elements/break.png"));
50         }
51         
52     private String JavaDoc type = "Page";
53     
54     public BreakReportElement(int x, int y, int width, int height)
55     {
56             super(x, y, Math.abs(width) , Math.abs(height) );
57     }
58     
59     public BreakReportElement(int x, int y, int width, int height, String JavaDoc type)
60     {
61         super(x, y, Math.abs(width) , Math.abs(height) );
62         //graphicElementPen = "Thin";
63
//this.bgcolor = Color.WHITE;
64
//this.fgcolor = Color.BLACK;
65
this.type = type;
66                 setKey("break");
67     }
68     
69     public void drawObject(Graphics2D g,double zoom_factor, int x_shift_origin, int y_shift_origin)
70     {
71         this.zoom_factor = zoom_factor;
72         int height_draw = 0;
73                 if (height <= 1) height_draw = 0;
74                 else height_draw = height-1;
75                 int width_draw = 0;
76                 if (width <= 1) width_draw = 0;
77                 else width_draw = width-1;
78         
79                 int leftX = 0;
80                 int rightX = 0;
81                 if (this.getBand() != null && this.getBand().getParent() != null)
82                 {
83                    Report report = this.getBand().getParent();
84                    rightX = (int)(report.getLeftMargin()*zoom_factor);
85                    leftX = (int)((report.getWidth() - report.getRightMargin()) *zoom_factor);
86                 }
87                 
88                 //g.fill( position.x,position.y,width,height,new Brush(bgcolor, BrushStyle.SOLID));
89
Point a = new Point( rightX + 10 - x_shift_origin, getZoomedDim( position.y-10) +10-y_shift_origin );
90         Point b = new Point( leftX + 10 - x_shift_origin, (int)a.getY());
91         
92                 
93                 Stroke stroke = this.getPenStroke( "Dotted" ,1 );
94         if(stroke != null){
95                     Stroke oldStroke = g.getStroke();
96                     g.setStroke(stroke);
97                 
98             g.setColor( getFgcolor() );
99             g.drawLine(a.x,a.y,b.x,b.y);
100                     g.setStroke(oldStroke);
101         }
102                 
103                 if (img != null)
104                     g.drawImage( img.getImage(),a.x-18, a.y-7, img.getImageObserver());
105     }
106     
107     public ReportElement cloneMe()
108     {
109         BreakReportElement newReportElement = new BreakReportElement(position.x, position.y, width, height);
110         copyBaseReportElement(newReportElement, this);
111         
112         return newReportElement;
113     }
114                 
115         public void copyBaseReportElement(ReportElement destination, ReportElement source)
116         {
117                 super.copyBaseReportElement(destination, source);
118                 
119                 if (destination instanceof BreakReportElement &&
120                     source instanceof BreakReportElement )
121                 {
122                     ((BreakReportElement)destination).setType( new String JavaDoc( ((BreakReportElement)source).getType()));
123                 }
124         }
125         
126          public boolean insideBand()
127         {
128
129             int r_height = (height == 0) ? 1 : height;
130             if (band == null)
131             {
132
133                 return false;
134             }
135
136             int yband = band.getBandYLocation();
137
138             if (position.y - yband + r_height > band.getHeight())
139             {
140                 return false;
141             }
142             return super.insideBand();
143         }
144
145     public String JavaDoc getType() {
146         return type;
147     }
148
149     public void setType(String JavaDoc type) {
150         this.type = type;
151     }
152 }
153
Popular Tags