1 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 subreportExpression=""; 49 private String subreportExpressionClass=""; 50 private String connectionExpression=""; 51 private String dataSourceExpression=""; 52 private String 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 () ,"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; 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 { 122 int imageWidth = img.getWidth(null); 123 int imageHeight = img.getHeight(null); 124 130 131 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 int elem_height = getZoomedDim(this.height); 139 elem_height -= getZoomedDim( imageHeight); 140 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) { 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 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 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 189 public java.lang.String getConnectionExpression() { 190 return connectionExpression; 191 } 192 193 197 public void setConnectionExpression(java.lang.String connectionExpression) { 198 this.connectionExpression = connectionExpression; 199 } 200 201 205 public java.lang.String getDataSourceExpression() { 206 return dataSourceExpression; 207 } 208 209 213 public void setDataSourceExpression(java.lang.String dataSourceExpression) { 214 this.dataSourceExpression = dataSourceExpression; 215 } 216 217 221 public boolean isIsUsingCache() { 222 return isUsingCache; 223 } 224 225 229 public void setIsUsingCache(boolean isUsingCache) { 230 this.isUsingCache = isUsingCache; 231 } 232 233 237 public java.lang.String getParametersMapExpression() { 238 return parametersMapExpression; 239 } 240 241 245 public void setParametersMapExpression(java.lang.String parametersMapExpression) { 246 this.parametersMapExpression = parametersMapExpression; 247 } 248 249 253 public java.lang.String getSubreportExpression() { 254 return subreportExpression; 255 } 256 257 261 public void setSubreportExpression(java.lang.String subreportExpression) { 262 this.subreportExpression = subreportExpression; 263 } 264 265 269 public java.lang.String getSubreportExpressionClass() { 270 return subreportExpressionClass; 271 } 272 273 277 public void setSubreportExpressionClass(java.lang.String subreportExpressionClass) { 278 this.subreportExpressionClass = subreportExpressionClass; 279 } 280 281 285 public java.util.Vector getSubreportParameters() { 286 return subreportParameters; 287 } 288 289 293 public void setSubreportParameters(java.util.Vector subreportParameters) { 294 this.subreportParameters = subreportParameters; 295 } 296 297 301 public boolean isUseConnection() { 302 return useConnection; 303 } 304 305 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 ( ((SubReportElement)source).getParametersMapExpression() )); 332 ((SubReportElement)destination).setSubreportExpression ( new String ( ((SubReportElement)source).getSubreportExpression() )); 333 ((SubReportElement)destination).setSubreportExpressionClass( new String ( ((SubReportElement)source).getSubreportExpressionClass() )); 334 ((SubReportElement)destination).setUseConnection( ((SubReportElement)source).isUseConnection() ); 335 if ( ((SubReportElement)destination).isUseConnection()) 336 ((SubReportElement)destination).setConnectionExpression( new String ( ((SubReportElement)source).getConnectionExpression() )); 337 else 338 ((SubReportElement)destination).setDataSourceExpression( new String ( ((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 |