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: * ChartReportElement.java
028: *
029: */
030:
031: package it.businesslogic.ireport;
032:
033: /*
034: * ChartReportElement.java
035: *
036: * iReport -- Visual designer for generating JasperReports Documents
037: * Copyright (C) 2002-2003 Giulio Toffoli gt@businesslogic.it
038: *
039: * This program is free software; you can redistribute and/or modify
040: * it under the terms of the GNU General Public License as published by
041: * the Free Software Foundation; either version 2 of the License, or
042: * (at your option) any later version.
043: *
044: * This program is distributed in the hope that it will be useful,
045: * but WITHOUT ANY WARRANTY; without even the implied warranty of
046: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
047: * GNU General Public License for more details.
048: *
049: * You should have received a copy of the GNU General Public License
050: * along with this program; if not, write to the Free Software
051: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
052: *
053: * Giulio Toffoli
054: * Via T.Aspetti, 233
055: * 35100 Padova ITALY
056: * gt@businesslogic.it
057: *
058: *
059: * Created on 3 giugno 2003, 23.28
060: */
061:
062: import java.awt.*;
063: import java.io.File;
064:
065: import it.businesslogic.ireport.util.*;
066:
067: import java.util.*;
068: import it.businesslogic.ireport.chart.Chart;
069:
070: /**
071: *
072: * @author Administrator
073: */
074: public class ChartReportElement extends
075: it.businesslogic.ireport.ImageReportElement {
076:
077: private java.util.Properties props;
078:
079: /** Creates a new instance of ChartReportElement */
080: // private JFreeChart chart = null;
081: public ChartReportElement(int x, int y, int width, int height) {
082: super (x, y, width, height);
083: //setGraphicElementPen("Thin");
084: this .setBgcolor(Color.WHITE);
085: this .setFgcolor(Color.BLACK);
086: setKey("chart");
087:
088: setImg(null);
089: setIsUsingCache(false);
090: setImageExpression("");
091: setImageClass("java.awt.Image");
092: setScaleImage("RetainShape");
093: setGraphicElementPen("None");
094: setHyperlinkType("None");
095: setAnchorNameExpression("");
096:
097: setImg(it.businesslogic.ireport.chart.AvailableCharts
098: .getChartIcon("").getImage());
099:
100: props = new java.util.Properties();
101: props.setProperty("width", "" + width);
102: props.setProperty("height", "" + height);
103: }
104:
105: public void drawObject(Graphics2D g, double zoom_factor,
106: int x_shift_origin, int y_shift_origin) {
107:
108: if (this .getImg() == null) {
109: updateChartImage();
110: }
111:
112: super
113: .drawObject(g, zoom_factor, x_shift_origin,
114: y_shift_origin);
115: }
116:
117: public java.util.Properties getProps() {
118: return props;
119: }
120:
121: public void setProps(java.util.Properties props) {
122: this .props = props;
123: }
124:
125: public void parseProperties(Vector reportProperties) {
126: for (int i = 0; i < reportProperties.size(); ++i) {
127: JRProperty property = (JRProperty) reportProperties
128: .elementAt(i);
129: if (property.getName().startsWith("chart." + getName())) {
130: props.setProperty(property.getName().substring(
131: ("chart." + getName() + ".").length()),
132: property.getValue());
133: }
134: }
135:
136: // Try to get Icon...
137: /*
138: if (props.getProperty("chartName") != null)
139: {
140: setImg( it.businesslogic.ireport.chart.AvailableCharts.getChartIcon( props.getProperty("chartName") ).getImage() );
141: }
142: */
143:
144: }
145:
146: /*
147: public void parseExpression(String expression)
148: {
149: expression = expression.trim();
150: expression = Misc.string_replace("","(java.awt.Image)it.businesslogic.ireport.chart.IReportChartFactory.iReportChart(", expression);
151: // REmove last )
152: if (expression.endsWith(")"))
153: expression = expression.substring(0, expression.length() -1);
154:
155: StringTokenizer st = new StringTokenizer(expression, "\n");
156: }
157: */
158:
159: public void updateChartImage() {
160: try {
161: String[] params_strings = null;
162: params_strings = new String[this .getProps().size()];
163:
164: Enumeration enum_keys = getProps().keys();
165: int i = 0;
166: while (enum_keys.hasMoreElements()) {
167: String key = (String) enum_keys.nextElement();
168: String val = "" + getProps().get(key);
169:
170: if (key.startsWith("serie")) {
171: val = "";
172: }
173:
174: params_strings[i] = key + "=" + val;
175:
176: //
177: i++;
178: }
179: java.awt.Image imgx = it.businesslogic.ireport.chart.DefaultChartFactory
180: .drawChart(params_strings, null);
181: this .setImg(imgx);
182: } catch (Exception ex) {
183: ex.printStackTrace();
184: }
185: }
186:
187: public void updateBounds() {
188: bounds = new Rectangle(position.x, position.y, width, height);
189: }
190:
191: public Point trasform(Point delta, int type) {
192: Point p = super .trasform(delta, type);
193: getProps().setProperty("width", "" + width);
194: getProps().setProperty("height", "" + height);
195: updateChartImage();
196: return p;
197: }
198:
199: }
|