1 30 31 package it.businesslogic.ireport; 32 60 61 import java.awt.*; 62 import java.io.File ; 63 64 import it.businesslogic.ireport.util.*; 65 66 import java.util.*; 67 import it.businesslogic.ireport.chart.Chart; 68 69 73 public class ChartReportElement extends it.businesslogic.ireport.ImageReportElement { 74 75 private java.util.Properties props; 76 77 78 80 public ChartReportElement(int x, int y, int width, int height) 81 { 82 super(x,y,width,height); 83 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 (); 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 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 { 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 143 144 } 145 157 158 public void updateChartImage() 159 { 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 { 168 String key = (String )enum_keys.nextElement(); 169 String val = ""+getProps().get(key); 170 171 if (key.startsWith("serie")) 172 { 173 val = ""; 174 } 175 176 params_strings[i] = key + "=" + val; 177 178 i++; 180 } 181 java.awt.Image imgx = it.businesslogic.ireport.chart.DefaultChartFactory.drawChart(params_strings, null); 182 this.setImg( imgx ); 183 } catch (Exception 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 |