KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ChartReportElement.java
28  *
29  */

30
31 package it.businesslogic.ireport;
32 /*
33  * ChartReportElement.java
34  *
35  * iReport -- Visual designer for generating JasperReports Documents
36  * Copyright (C) 2002-2003 Giulio Toffoli gt@businesslogic.it
37  *
38  * This program is free software; you can redistribute and/or modify
39  * it under the terms of the GNU General Public License as published by
40  * the Free Software Foundation; either version 2 of the License, or
41  * (at your option) any later version.
42  *
43  * This program is distributed in the hope that it will be useful,
44  * but WITHOUT ANY WARRANTY; without even the implied warranty of
45  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  * GNU General Public License for more details.
47  *
48  * You should have received a copy of the GNU General Public License
49  * along with this program; if not, write to the Free Software
50  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
51  *
52  * Giulio Toffoli
53  * Via T.Aspetti, 233
54  * 35100 Padova ITALY
55  * gt@businesslogic.it
56  *
57  *
58  * Created on 3 giugno 2003, 23.28
59  */

60
61 import java.awt.*;
62 import java.io.File JavaDoc;
63
64 import it.businesslogic.ireport.util.*;
65
66 import java.util.*;
67 import it.businesslogic.ireport.chart.Chart;
68
69 /**
70  *
71  * @author Administrator
72  */

73 public class ChartReportElement extends it.businesslogic.ireport.ImageReportElement {
74     
75     private java.util.Properties JavaDoc props;
76
77     /** Creates a new instance of ChartReportElement */
78    // private JFreeChart chart = null;
79

80     public ChartReportElement(int x, int y, int width, int height)
81     {
82         super(x,y,width,height);
83                 //setGraphicElementPen("Thin");
84
this.setBgcolor(Color.WHITE);
85         this.setFgcolor(Color.BLACK);
86                 setKey("chart");
87                 
88              
89         setImg( null );
90     setIsUsingCache(false);
91     setImageExpression("");
92     setImageClass("java.awt.Image");
93     setScaleImage("RetainShape");
94     setGraphicElementPen("None");
95         setHyperlinkType("None");
96         setAnchorNameExpression("");
97         
98         setImg(it.businesslogic.ireport.chart.AvailableCharts.getChartIcon( "" ).getImage());
99        
100         props = new java.util.Properties JavaDoc();
101         props.setProperty("width", ""+width );
102         props.setProperty("height", ""+height );
103     }
104     
105     
106     public void drawObject(Graphics2D g, double zoom_factor, int x_shift_origin, int y_shift_origin)
107     {
108           
109     if (this.getImg() == null)
110     {
111                       updateChartImage();
112     }
113                 
114         super.drawObject(g, zoom_factor, x_shift_origin, y_shift_origin);
115     }
116
117     public java.util.Properties JavaDoc getProps() {
118         return props;
119     }
120
121     public void setProps(java.util.Properties JavaDoc props) {
122         this.props=props;
123     }
124          
125     public void parseProperties( Vector reportProperties )
126     {
127         for (int i=0; i< reportProperties.size(); ++i )
128         {
129             JRProperty property = (JRProperty)reportProperties.elementAt(i);
130             if (property.getName().startsWith("chart." + getName() ))
131             {
132                 props.setProperty( property.getName().substring(("chart."+getName()+".").length()) , 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      public void parseExpression(String expression)
147      {
148          expression = expression.trim();
149          expression = Misc.string_replace("","(java.awt.Image)it.businesslogic.ireport.chart.IReportChartFactory.iReportChart(", expression);
150          // REmove last )
151          if (expression.endsWith(")"))
152              expression = expression.substring(0, expression.length() -1);
153              
154          StringTokenizer st = new StringTokenizer(expression, "\n");
155      }
156     */

157     
158     public void updateChartImage()
159     {
160         try {
161             String JavaDoc[] params_strings = null;
162             params_strings = new String JavaDoc[this.getProps().size()];
163             
164             Enumeration enum_keys = getProps().keys();
165             int i=0;
166             while (enum_keys.hasMoreElements())
167             {
168                 String JavaDoc key = (String JavaDoc)enum_keys.nextElement();
169                 String JavaDoc val = ""+getProps().get(key);
170                 
171                 if (key.startsWith("serie"))
172                 {
173                     val = "";
174                 }
175                 
176                 params_strings[i] = key + "=" + val;
177                 
178                 //
179
i++;
180             }
181             java.awt.Image JavaDoc imgx = it.businesslogic.ireport.chart.DefaultChartFactory.drawChart(params_strings, null);
182             this.setImg( imgx );
183         } catch (Exception JavaDoc ex)
184         {
185             ex.printStackTrace();
186         }
187     }
188     
189     public void updateBounds() {
190         bounds = new Rectangle(position.x,position.y,width,height);
191     }
192     
193     public Point trasform(Point delta, int type) {
194        Point p = super.trasform(delta,type);
195        getProps().setProperty("width",""+width);
196         getProps().setProperty("height",""+height);
197         updateChartImage();
198         return p;
199     }
200     
201 }
202
Popular Tags