KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SubReportElement.java
28  *
29  * Created on 28 febbraio 2003, 22.53
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 java.util.*;
41
42
43 public class SubReportElement extends ReportElement {
44     
45         private boolean isUsingCache = true;
46     private Vector subreportParameters=null;
47         private Vector returnValues=null;
48     private String JavaDoc subreportExpression="";
49     private String JavaDoc subreportExpressionClass="";
50     private String JavaDoc connectionExpression="";
51     private String JavaDoc dataSourceExpression="";
52     private String JavaDoc parametersMapExpression="";
53     private boolean useConnection = false;
54         
55         public static Image img=null;
56     
57     public SubReportElement(int x, int y, int width, int height)
58     {
59         super(x, y, width, height);
60             setKey("subreport");
61                 
62                 subreportParameters = new Vector();
63                 returnValues = new Vector();
64         subreportExpressionClass = "java.lang.String";
65         useConnection = false;
66                 this.transparentDefault = "Transparent";
67                 if (img == null)
68                       img = Misc.loadBufferedImageFromResources(new java.awt.Panel JavaDoc() ,"it/businesslogic/ireport/icons/subreportTool1.jpg");
69     }
70         
71         public void drawObject(Graphics2D g,double zoom_factor, int x_shift_origin, int y_shift_origin)
72     {
73            
74                 position.x -= 10;
75         position.y -= 10;
76         x_shift_origin -= 10;
77         y_shift_origin -= 10;
78         
79         this.zoom_factor = zoom_factor;
80                 
81                 Color ccc = new Color(204,204,204,150);
82                 
83                 g.setColor( ccc );
84                 Paint paint=g.getPaint();
85                 g.setPaint( new GradientPaint( getZoomedDim(position.x)-x_shift_origin,
86                             getZoomedDim(position.y)-y_shift_origin,
87                             ccc, getZoomedDim(position.x)-x_shift_origin+getZoomedDim(width),
88                             getZoomedDim(position.x)-x_shift_origin + getZoomedDim(height), ccc.brighter() ) );
89
90                 g.fillRect( getZoomedDim(position.x)-x_shift_origin,
91                 getZoomedDim(position.y)-y_shift_origin,
92                 getZoomedDim(width),
93                 getZoomedDim(height));
94                 g.setPaint(paint);
95                 
96         position.x += 10;
97         position.y += 10;
98         x_shift_origin += 10;
99         y_shift_origin += 10;
100                 
101                 drawGraphicsElement(g,zoom_factor, x_shift_origin,y_shift_origin);
102     }
103         
104     public void drawGraphicsElement(Graphics2D g, double zoom_factor, int x_shift_origin, int y_shift_origin)
105     {
106                 drawGraphicsElement(g,"Thin", zoom_factor, x_shift_origin,y_shift_origin);
107                 int correction = 0; //(zoom_factor <= 1) ? -1 : 0;
108

109         position.x -= 10;
110         position.y -= 10;
111         x_shift_origin -= 10;
112         y_shift_origin -= 10;
113                 
114                 
115                 if (img != null)
116                 {/*
117                     g.drawImage(img,
118                         getZoomedDim(position.x)-x_shift_origin,
119                         getZoomedDim(position.y)-y_shift_origin,
120                         getZoomedDim(width)+correction,getZoomedDim(height)+correction, null);
121                 */

122                     int imageWidth = img.getWidth(null);
123                     int imageHeight = img.getHeight(null);
124                     /*
125             if (imgx instanceof Image)
126             {
127                 ((Image)imgx).setTransparent(true);
128             }
129                      */

130             
131             //
132
if (imageWidth < width && imageHeight< height)
133             {
134                 Rectangle destination = new Rectangle(getZoomedDim(position.x)-x_shift_origin,
135                                                                       getZoomedDim(position.y)-y_shift_origin,getZoomedDim( imageWidth), getZoomedDim( imageHeight-1));
136                 Rectangle source = new Rectangle(0,0,imageWidth,imageHeight);
137                 // Calculate y shift based on hAlign...
138
int elem_height = getZoomedDim(this.height);
139                 elem_height -= getZoomedDim( imageHeight);
140                 // Calculate x shift based on hAlign...
141
int elem_width = getZoomedDim(this.width);
142                 elem_width -= getZoomedDim( imageWidth);
143                 g.drawImage( img,destination.x+1, destination.y+1, destination.x+destination.width+1, destination.y+destination.height+1,
144                                                        source.x,source.y,source.width,source.height,
145                                                        null,null);
146             }
147             else if (width>0 && height>0)// Resize based on minor x/WIDTH... e y/HEIGHT
148
{
149                 if ((double)((double)imageWidth/(double)width)> (double)((double)imageHeight/(double)height))
150                 {
151                     
152                     Rectangle source = new Rectangle(0,0,imageWidth,imageHeight);
153                     Rectangle destination = new Rectangle(getZoomedDim(position.x)-x_shift_origin,
154                                                                       getZoomedDim(position.y)-y_shift_origin,getZoomedDim(width) ,getZoomedDim(Math.min( (imageHeight*width)/imageWidth, height-1)) );
155                     
156                     // Calculate y shift based on hAlign...
157
int elem_height = getZoomedDim(this.height);
158                     elem_height -= getZoomedDim(Math.min( (imageHeight*width)/imageWidth, height));
159                         
160                     g.drawImage( img,destination.x+1, destination.y+1, destination.x+destination.width, destination.y+destination.height,
161                                                         source.x,source.y,source.width,source.height,
162                                                         null,null);
163                     }
164                     else
165                     {
166                         Rectangle source = new Rectangle(0,0,imageWidth,imageHeight);
167                         Rectangle destination = new Rectangle(getZoomedDim(position.x)-x_shift_origin,
168                                                                       getZoomedDim(position.y)-y_shift_origin, getZoomedDim( Math.min( (imageWidth*height)/imageHeight, width)) ,getZoomedDim( height-1) );
169                         
170                         // Calculate x shift based on hAlign...
171
int elem_width = getZoomedDim(this.width);
172                         elem_width -= getZoomedDim( Math.min( (imageWidth*height)/imageHeight, width));
173                     
174                         g.drawImage( img,destination.x+1, destination.y+1, destination.x+destination.width, destination.y+destination.height,
175                                                         source.x,source.y,source.width,source.height,
176                                                         null,null);
177                     }
178                                 }
179                         }
180                 position.x += 10;
181         position.y += 10;
182                        
183         }
184         
185         /** Getter for property connectionExpression.
186          * @return Value of property connectionExpression.
187          *
188          */

189         public java.lang.String JavaDoc getConnectionExpression() {
190             return connectionExpression;
191         }
192         
193         /** Setter for property connectionExpression.
194          * @param connectionExpression New value of property connectionExpression.
195          *
196          */

197         public void setConnectionExpression(java.lang.String JavaDoc connectionExpression) {
198             this.connectionExpression = connectionExpression;
199         }
200         
201         /** Getter for property dataSourceExpression.
202          * @return Value of property dataSourceExpression.
203          *
204          */

205         public java.lang.String JavaDoc getDataSourceExpression() {
206             return dataSourceExpression;
207         }
208         
209         /** Setter for property dataSourceExpression.
210          * @param dataSourceExpression New value of property dataSourceExpression.
211          *
212          */

213         public void setDataSourceExpression(java.lang.String JavaDoc dataSourceExpression) {
214             this.dataSourceExpression = dataSourceExpression;
215         }
216         
217         /** Getter for property isUsingCache.
218          * @return Value of property isUsingCache.
219          *
220          */

221         public boolean isIsUsingCache() {
222             return isUsingCache;
223         }
224         
225         /** Setter for property isUsingCache.
226          * @param isUsingCache New value of property isUsingCache.
227          *
228          */

229         public void setIsUsingCache(boolean isUsingCache) {
230             this.isUsingCache = isUsingCache;
231         }
232         
233         /** Getter for property parametersMapExpression.
234          * @return Value of property parametersMapExpression.
235          *
236          */

237         public java.lang.String JavaDoc getParametersMapExpression() {
238             return parametersMapExpression;
239         }
240         
241         /** Setter for property parametersMapExpression.
242          * @param parametersMapExpression New value of property parametersMapExpression.
243          *
244          */

245         public void setParametersMapExpression(java.lang.String JavaDoc parametersMapExpression) {
246             this.parametersMapExpression = parametersMapExpression;
247         }
248         
249         /** Getter for property subreportExpression.
250          * @return Value of property subreportExpression.
251          *
252          */

253         public java.lang.String JavaDoc getSubreportExpression() {
254             return subreportExpression;
255         }
256         
257         /** Setter for property subreportExpression.
258          * @param subreportExpression New value of property subreportExpression.
259          *
260          */

261         public void setSubreportExpression(java.lang.String JavaDoc subreportExpression) {
262             this.subreportExpression = subreportExpression;
263         }
264         
265         /** Getter for property subreportExpressionClass.
266          * @return Value of property subreportExpressionClass.
267          *
268          */

269         public java.lang.String JavaDoc getSubreportExpressionClass() {
270             return subreportExpressionClass;
271         }
272         
273         /** Setter for property subreportExpressionClass.
274          * @param subreportExpressionClass New value of property subreportExpressionClass.
275          *
276          */

277         public void setSubreportExpressionClass(java.lang.String JavaDoc subreportExpressionClass) {
278             this.subreportExpressionClass = subreportExpressionClass;
279         }
280         
281         /** Getter for property subreportParameters.
282          * @return Value of property subreportParameters.
283          *
284          */

285         public java.util.Vector JavaDoc getSubreportParameters() {
286             return subreportParameters;
287         }
288         
289         /** Setter for property subreportParameters.
290          * @param subreportParameters New value of property subreportParameters.
291          *
292          */

293         public void setSubreportParameters(java.util.Vector JavaDoc subreportParameters) {
294             this.subreportParameters = subreportParameters;
295         }
296         
297         /** Getter for property useConnection.
298          * @return Value of property useConnection.
299          *
300          */

301         public boolean isUseConnection() {
302             return useConnection;
303         }
304         
305         /** Setter for property useConnection.
306          * @param useConnection New value of property useConnection.
307          *
308          */

309         public void setUseConnection(boolean useConnection) {
310             this.useConnection = useConnection;
311         }
312         
313         
314         public ReportElement cloneMe()
315     {
316     SubReportElement newReportElement = new SubReportElement(position.x, position.y, width, height);
317     copyBaseReportElement(newReportElement, this);
318     return newReportElement;
319     }
320         
321     public void copyBaseReportElement(ReportElement destination, ReportElement source)
322         {
323                 super.copyBaseReportElement(destination, source);
324                 
325                 if (destination instanceof SubReportElement &&
326                     source instanceof SubReportElement )
327                 {
328                     
329                     
330                     ((SubReportElement)destination).setIsUsingCache( ((SubReportElement)source).isIsUsingCache());
331                     ((SubReportElement)destination).setParametersMapExpression( new String JavaDoc( ((SubReportElement)source).getParametersMapExpression() ));
332                     ((SubReportElement)destination).setSubreportExpression ( new String JavaDoc( ((SubReportElement)source).getSubreportExpression() ));
333                     ((SubReportElement)destination).setSubreportExpressionClass( new String JavaDoc( ((SubReportElement)source).getSubreportExpressionClass() ));
334                     ((SubReportElement)destination).setUseConnection( ((SubReportElement)source).isUseConnection() );
335                     if ( ((SubReportElement)destination).isUseConnection())
336                         ((SubReportElement)destination).setConnectionExpression( new String JavaDoc( ((SubReportElement)source).getConnectionExpression() ));
337                     else
338                         ((SubReportElement)destination).setDataSourceExpression( new String JavaDoc( ((SubReportElement)source).getDataSourceExpression() ));
339                     
340                     Enumeration e = ((SubReportElement)source).getSubreportParameters().elements();
341                     while (e.hasMoreElements())
342                     {
343             JRSubreportParameter jp = (JRSubreportParameter)e.nextElement();
344             ((SubReportElement)destination).getSubreportParameters().addElement(jp.cloneMe());
345                     }
346                 }
347         }
348
349     public Vector getReturnValues() {
350         return returnValues;
351     }
352
353     public void setReturnValues(Vector returnValues) {
354         this.returnValues = returnValues;
355     }
356 }
357
Popular Tags