001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * SubReportElement.java
028: *
029: * Created on 28 febbraio 2003, 22.53
030: *
031: */
032:
033: package it.businesslogic.ireport;
034:
035: import it.businesslogic.ireport.gui.*;
036: import it.businesslogic.ireport.util.*;
037: import java.awt.*;
038: import java.awt.image.*;
039: import java.awt.geom.*;
040: import java.util.*;
041:
042: public class SubReportElement extends ReportElement {
043:
044: private boolean isUsingCache = true;
045: private Vector subreportParameters = null;
046: private Vector returnValues = null;
047: private String subreportExpression = "";
048: private String subreportExpressionClass = "";
049: private String connectionExpression = "";
050: private String dataSourceExpression = "";
051: private String parametersMapExpression = "";
052: private boolean useConnection = false;
053:
054: public static Image img = null;
055:
056: public SubReportElement(int x, int y, int width, int height) {
057: super (x, y, width, height);
058: setKey("subreport");
059:
060: subreportParameters = new Vector();
061: returnValues = new Vector();
062: subreportExpressionClass = "java.lang.String";
063: useConnection = false;
064: this .transparentDefault = "Transparent";
065: if (img == null)
066: img = Misc
067: .loadBufferedImageFromResources(
068: new java.awt.Panel(),
069: "it/businesslogic/ireport/icons/subreportTool1.jpg");
070: }
071:
072: public void drawObject(Graphics2D g, double zoom_factor,
073: int x_shift_origin, int y_shift_origin) {
074:
075: position.x -= 10;
076: position.y -= 10;
077: x_shift_origin -= 10;
078: y_shift_origin -= 10;
079:
080: this .zoom_factor = zoom_factor;
081:
082: Color ccc = new Color(204, 204, 204, 150);
083:
084: g.setColor(ccc);
085: Paint paint = g.getPaint();
086: g.setPaint(new GradientPaint(getZoomedDim(position.x)
087: - x_shift_origin, getZoomedDim(position.y)
088: - y_shift_origin, ccc, getZoomedDim(position.x)
089: - x_shift_origin + getZoomedDim(width),
090: getZoomedDim(position.x) - x_shift_origin
091: + getZoomedDim(height), ccc.brighter()));
092:
093: g.fillRect(getZoomedDim(position.x) - x_shift_origin,
094: getZoomedDim(position.y) - y_shift_origin,
095: getZoomedDim(width), getZoomedDim(height));
096: g.setPaint(paint);
097:
098: position.x += 10;
099: position.y += 10;
100: x_shift_origin += 10;
101: y_shift_origin += 10;
102:
103: drawGraphicsElement(g, zoom_factor, x_shift_origin,
104: y_shift_origin);
105: }
106:
107: public void drawGraphicsElement(Graphics2D g, double zoom_factor,
108: int x_shift_origin, int y_shift_origin) {
109: drawGraphicsElement(g, "Thin", zoom_factor, x_shift_origin,
110: y_shift_origin);
111: int correction = 0; //(zoom_factor <= 1) ? -1 : 0;
112:
113: position.x -= 10;
114: position.y -= 10;
115: x_shift_origin -= 10;
116: y_shift_origin -= 10;
117:
118: if (img != null) {/*
119: g.drawImage(img,
120: getZoomedDim(position.x)-x_shift_origin,
121: getZoomedDim(position.y)-y_shift_origin,
122: getZoomedDim(width)+correction,getZoomedDim(height)+correction, null);
123: */
124: int imageWidth = img.getWidth(null);
125: int imageHeight = img.getHeight(null);
126: /*
127: if (imgx instanceof Image)
128: {
129: ((Image)imgx).setTransparent(true);
130: }
131: */
132:
133: //
134: if (imageWidth < width && imageHeight < height) {
135: Rectangle destination = new Rectangle(
136: getZoomedDim(position.x) - x_shift_origin,
137: getZoomedDim(position.y) - y_shift_origin,
138: getZoomedDim(imageWidth),
139: getZoomedDim(imageHeight - 1));
140: Rectangle source = new Rectangle(0, 0, imageWidth,
141: imageHeight);
142: // Calculate y shift based on hAlign...
143: int elem_height = getZoomedDim(this .height);
144: elem_height -= getZoomedDim(imageHeight);
145: // Calculate x shift based on hAlign...
146: int elem_width = getZoomedDim(this .width);
147: elem_width -= getZoomedDim(imageWidth);
148: g.drawImage(img, destination.x + 1, destination.y + 1,
149: destination.x + destination.width + 1,
150: destination.y + destination.height + 1,
151: source.x, source.y, source.width,
152: source.height, null, null);
153: } else if (width > 0 && height > 0)// Resize based on minor x/WIDTH... e y/HEIGHT
154: {
155: if ((double) ((double) imageWidth / (double) width) > (double) ((double) imageHeight / (double) height)) {
156:
157: Rectangle source = new Rectangle(0, 0, imageWidth,
158: imageHeight);
159: Rectangle destination = new Rectangle(
160: getZoomedDim(position.x) - x_shift_origin,
161: getZoomedDim(position.y) - y_shift_origin,
162: getZoomedDim(width), getZoomedDim(Math.min(
163: (imageHeight * width) / imageWidth,
164: height - 1)));
165:
166: // Calculate y shift based on hAlign...
167: int elem_height = getZoomedDim(this .height);
168: elem_height -= getZoomedDim(Math.min(
169: (imageHeight * width) / imageWidth, height));
170:
171: g.drawImage(img, destination.x + 1,
172: destination.y + 1, destination.x
173: + destination.width, destination.y
174: + destination.height, source.x,
175: source.y, source.width, source.height,
176: null, null);
177: } else {
178: Rectangle source = new Rectangle(0, 0, imageWidth,
179: imageHeight);
180: Rectangle destination = new Rectangle(
181: getZoomedDim(position.x) - x_shift_origin,
182: getZoomedDim(position.y) - y_shift_origin,
183: getZoomedDim(Math.min((imageWidth * height)
184: / imageHeight, width)),
185: getZoomedDim(height - 1));
186:
187: // Calculate x shift based on hAlign...
188: int elem_width = getZoomedDim(this .width);
189: elem_width -= getZoomedDim(Math.min(
190: (imageWidth * height) / imageHeight, width));
191:
192: g.drawImage(img, destination.x + 1,
193: destination.y + 1, destination.x
194: + destination.width, destination.y
195: + destination.height, source.x,
196: source.y, source.width, source.height,
197: null, null);
198: }
199: }
200: }
201: position.x += 10;
202: position.y += 10;
203:
204: }
205:
206: /** Getter for property connectionExpression.
207: * @return Value of property connectionExpression.
208: *
209: */
210: public java.lang.String getConnectionExpression() {
211: return connectionExpression;
212: }
213:
214: /** Setter for property connectionExpression.
215: * @param connectionExpression New value of property connectionExpression.
216: *
217: */
218: public void setConnectionExpression(
219: java.lang.String connectionExpression) {
220: this .connectionExpression = connectionExpression;
221: }
222:
223: /** Getter for property dataSourceExpression.
224: * @return Value of property dataSourceExpression.
225: *
226: */
227: public java.lang.String getDataSourceExpression() {
228: return dataSourceExpression;
229: }
230:
231: /** Setter for property dataSourceExpression.
232: * @param dataSourceExpression New value of property dataSourceExpression.
233: *
234: */
235: public void setDataSourceExpression(
236: java.lang.String dataSourceExpression) {
237: this .dataSourceExpression = dataSourceExpression;
238: }
239:
240: /** Getter for property isUsingCache.
241: * @return Value of property isUsingCache.
242: *
243: */
244: public boolean isIsUsingCache() {
245: return isUsingCache;
246: }
247:
248: /** Setter for property isUsingCache.
249: * @param isUsingCache New value of property isUsingCache.
250: *
251: */
252: public void setIsUsingCache(boolean isUsingCache) {
253: this .isUsingCache = isUsingCache;
254: }
255:
256: /** Getter for property parametersMapExpression.
257: * @return Value of property parametersMapExpression.
258: *
259: */
260: public java.lang.String getParametersMapExpression() {
261: return parametersMapExpression;
262: }
263:
264: /** Setter for property parametersMapExpression.
265: * @param parametersMapExpression New value of property parametersMapExpression.
266: *
267: */
268: public void setParametersMapExpression(
269: java.lang.String parametersMapExpression) {
270: this .parametersMapExpression = parametersMapExpression;
271: }
272:
273: /** Getter for property subreportExpression.
274: * @return Value of property subreportExpression.
275: *
276: */
277: public java.lang.String getSubreportExpression() {
278: return subreportExpression;
279: }
280:
281: /** Setter for property subreportExpression.
282: * @param subreportExpression New value of property subreportExpression.
283: *
284: */
285: public void setSubreportExpression(
286: java.lang.String subreportExpression) {
287: this .subreportExpression = subreportExpression;
288: }
289:
290: /** Getter for property subreportExpressionClass.
291: * @return Value of property subreportExpressionClass.
292: *
293: */
294: public java.lang.String getSubreportExpressionClass() {
295: return subreportExpressionClass;
296: }
297:
298: /** Setter for property subreportExpressionClass.
299: * @param subreportExpressionClass New value of property subreportExpressionClass.
300: *
301: */
302: public void setSubreportExpressionClass(
303: java.lang.String subreportExpressionClass) {
304: this .subreportExpressionClass = subreportExpressionClass;
305: }
306:
307: /** Getter for property subreportParameters.
308: * @return Value of property subreportParameters.
309: *
310: */
311: public java.util.Vector getSubreportParameters() {
312: return subreportParameters;
313: }
314:
315: /** Setter for property subreportParameters.
316: * @param subreportParameters New value of property subreportParameters.
317: *
318: */
319: public void setSubreportParameters(
320: java.util.Vector subreportParameters) {
321: this .subreportParameters = subreportParameters;
322: }
323:
324: /** Getter for property useConnection.
325: * @return Value of property useConnection.
326: *
327: */
328: public boolean isUseConnection() {
329: return useConnection;
330: }
331:
332: /** Setter for property useConnection.
333: * @param useConnection New value of property useConnection.
334: *
335: */
336: public void setUseConnection(boolean useConnection) {
337: this .useConnection = useConnection;
338: }
339:
340: public ReportElement cloneMe() {
341: SubReportElement newReportElement = new SubReportElement(
342: position.x, position.y, width, height);
343: copyBaseReportElement(newReportElement, this );
344: return newReportElement;
345: }
346:
347: public void copyBaseReportElement(ReportElement destination,
348: ReportElement source) {
349: super .copyBaseReportElement(destination, source);
350:
351: if (destination instanceof SubReportElement
352: && source instanceof SubReportElement) {
353:
354: ((SubReportElement) destination)
355: .setIsUsingCache(((SubReportElement) source)
356: .isIsUsingCache());
357: ((SubReportElement) destination)
358: .setParametersMapExpression(new String(
359: ((SubReportElement) source)
360: .getParametersMapExpression()));
361: ((SubReportElement) destination)
362: .setSubreportExpression(new String(
363: ((SubReportElement) source)
364: .getSubreportExpression()));
365: ((SubReportElement) destination)
366: .setSubreportExpressionClass(new String(
367: ((SubReportElement) source)
368: .getSubreportExpressionClass()));
369: ((SubReportElement) destination)
370: .setUseConnection(((SubReportElement) source)
371: .isUseConnection());
372: if (((SubReportElement) destination).isUseConnection())
373: ((SubReportElement) destination)
374: .setConnectionExpression(new String(
375: ((SubReportElement) source)
376: .getConnectionExpression()));
377: else
378: ((SubReportElement) destination)
379: .setDataSourceExpression(new String(
380: ((SubReportElement) source)
381: .getDataSourceExpression()));
382:
383: Enumeration e = ((SubReportElement) source)
384: .getSubreportParameters().elements();
385: while (e.hasMoreElements()) {
386: JRSubreportParameter jp = (JRSubreportParameter) e
387: .nextElement();
388: ((SubReportElement) destination)
389: .getSubreportParameters().addElement(
390: jp.cloneMe());
391: }
392: }
393: }
394:
395: public Vector getReturnValues() {
396: return returnValues;
397: }
398:
399: public void setReturnValues(Vector returnValues) {
400: this.returnValues = returnValues;
401: }
402: }
|