KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ChartReportElement2.java
28  *
29  * Created on 8 luglio 2005, 17.06
30  *
31  */

32
33 package it.businesslogic.ireport;
34
35 import it.businesslogic.ireport.chart.Chart;
36 import java.awt.*;
37 import java.util.Vector JavaDoc;
38 /**
39  *
40  * @author Administrator
41  */

42 public class ChartReportElement2 extends ReportElement implements BoxElement, java.awt.image.ImageObserver JavaDoc, HyperLinkableReportElement {
43     
44     private Box box = null;
45     private Chart chart = null;
46     private String JavaDoc evaluationTime="Now";
47     private String JavaDoc evaluationGroup="";
48     
49     /** Creates a new instance of JRChartReportElement */
50     public ChartReportElement2(int x, int y, int width, int height)
51    {
52       super(x,y,width,height);
53           setBox(new Box());
54           
55    }
56
57     public Box getBox() {
58         return box;
59     }
60
61     public void setBox(Box box) {
62         this.box = box;
63     }
64
65     public Chart getChart() {
66         return chart;
67     }
68
69     public void setChart(Chart chart) {
70         this.chart = chart;
71     }
72     
73    public void drawObject(Graphics2D g,double zoom_factor, int x_shift_origin, int y_shift_origin)
74    {
75           position.x += -10 + box.getLeftPadding();
76         position.y += -10 + box.getTopPadding();
77                 width = width - box.getLeftPadding() - box.getRightPadding();
78                 height = height - box.getTopPadding() - box.getBottomPadding();
79
80         x_shift_origin -= 10;
81         y_shift_origin -= 10;
82                 
83         this.zoom_factor = zoom_factor;
84         Image imgx = getChart().getChartImage();
85         
86                 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
87                 g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
88                 
89         if (imgx != null)
90         {
91                     int imageWidth = imgx.getWidth(this);
92                     int imageHeight = imgx.getHeight(this);
93                     /*
94             if (imgx instanceof Image)
95             {
96                 ((Image)imgx).setTransparent(true);
97             }
98                      */

99             
100             //
101

102                             
103                     g.drawImage(imgx, getZoomedDim(position.x)-x_shift_origin,
104                     getZoomedDim(position.y)-y_shift_origin,
105                     getZoomedDim(position.x+width)-x_shift_origin,
106                     getZoomedDim(position.y+height)-y_shift_origin,
107                     0,0,imageWidth,imageHeight,null,this);
108
109                                 //-x_shift_origin+ getZoomedDim( position.x-10)+10 ,-y_shift_origin+getZoomedDim(position.y)+10, getZoomedDim( this.width), getZoomedDim( this.height),
110

111         }
112                 
113                 if (it.businesslogic.ireport.gui.MainFrame.getMainInstance().getProperties().getProperty("Antialias","true").equals("false"))
114                 {
115                     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
116                     g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
117                 }
118                 //position.x += 10;
119
//position.y += 10;
120

121                 position.x += 10 - box.getLeftPadding();
122         position.y += 10 - box.getTopPadding();
123                 width = width + box.getLeftPadding() + box.getRightPadding();
124                 height = height + box.getTopPadding() + box.getBottomPadding();
125
126                 
127         x_shift_origin += 10;
128         y_shift_origin += 10;
129                 
130                 super.drawBorder((Graphics2D)g, zoom_factor, x_shift_origin,y_shift_origin);
131                 drawBorder( g, zoom_factor, x_shift_origin,y_shift_origin,getBox());
132    }
133
134     public String JavaDoc getEvaluationTime() {
135         return evaluationTime;
136     }
137
138     public void setEvaluationTime(String JavaDoc evaluationTime) {
139         this.evaluationTime = evaluationTime;
140     }
141
142     public String JavaDoc getEvaluationGroup() {
143         return evaluationGroup;
144     }
145
146     public void setEvaluationGroup(String JavaDoc evaluationGroup) {
147         this.evaluationGroup = evaluationGroup;
148     }
149     
150     public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
151         return true;
152     }
153     
154     public ReportElement cloneMe()
155     {
156     ChartReportElement2 newReportElement = new ChartReportElement2(position.x, position.y, width, height);
157     copyBaseReportElement(newReportElement, this);
158     return newReportElement;
159     }
160     
161     public void copyBaseReportElement(ReportElement destination, ReportElement source)
162     {
163             super.copyBaseReportElement(destination, source);
164
165             if (destination instanceof ChartReportElement2 &&
166                 source instanceof ChartReportElement2 )
167             {
168                 ((ChartReportElement2)destination).setBox( ((ChartReportElement2)source).getBox().cloneMe() );
169                 ((ChartReportElement2)destination).setChart( ((ChartReportElement2)source).getChart().cloneMe() );
170                 ((ChartReportElement2)destination).setEvaluationGroup( ((ChartReportElement2)source).getEvaluationGroup() );
171                 ((ChartReportElement2)destination).setEvaluationTime( ((ChartReportElement2)source).getEvaluationTime() );
172             }
173     }
174
175     public String JavaDoc getAnchorNameExpression() {
176         return getChart().getAnchorNameExpression();
177     }
178
179     public String JavaDoc getHyperlinkAnchorExpression() {
180         return getChart().getHyperlinkAnchorExpression();
181     }
182
183     public String JavaDoc getHyperlinkPageExpression() {
184         return getChart().getHyperlinkPageExpression();
185     }
186
187     public String JavaDoc getHyperlinkReferenceExpression() {
188         return getChart().getHyperlinkReferenceExpression();
189     }
190
191     public String JavaDoc getHyperlinkTarget() {
192         return getChart().getHyperlinkTarget();
193     }
194
195     public String JavaDoc getHyperlinkType() {
196         return getChart().getHyperlinkType();
197     }
198
199     public void setAnchorNameExpression(String JavaDoc anchorNameExpression) {
200         getChart().setAnchorNameExpression(anchorNameExpression);
201     }
202
203     public void setHyperlinkAnchorExpression(String JavaDoc hyperlinkAnchorExpression) {
204         getChart().setHyperlinkAnchorExpression(hyperlinkAnchorExpression);
205     }
206
207     public void setHyperlinkPageExpression(String JavaDoc hyperlinkPageExpression) {
208         getChart().setHyperlinkPageExpression(hyperlinkPageExpression);
209     }
210
211     public void setHyperlinkReferenceExpression(String JavaDoc hyperlinkReferenceExpression) {
212         getChart().setHyperlinkReferenceExpression(hyperlinkReferenceExpression);
213     }
214
215     public void setHyperlinkTarget(String JavaDoc hyperlinkTarget) {
216         getChart().setHyperlinkTarget(hyperlinkTarget);
217     }
218
219     public void setHyperlinkType(String JavaDoc hyperlinkType) {
220         getChart().setHyperlinkType(hyperlinkType);
221     }
222
223     public int getBookmarkLevel() {
224         return getChart().getBookmarkLevel();
225     }
226
227     public void setBookmarkLevel(int bookmarkLevel) {
228         getChart().setBookmarkLevel(bookmarkLevel);
229     }
230     
231     public void setStyle(Style style) {
232      
233         super.setStyle(style);
234         
235         if (style != null)
236         {
237             // BOX
238
if (style.getAttributeString(style.ATTRIBUTE_border, null, true) != null)
239                 this.getBox().setBorder( style.getAttributeString(style.ATTRIBUTE_border, null, true) );
240             if (style.getAttributeColor(style.ATTRIBUTE_borderColor, null, true) != null)
241                 this.getBox().setBorderColor( style.getAttributeColor(style.ATTRIBUTE_borderColor, null, true));
242             if (style.getAttributeString(style.ATTRIBUTE_padding, null, true) != null)
243                 this.getBox().setPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_padding, null, true) ));
244             
245             if (style.getAttributeString(style.ATTRIBUTE_topBorder, null, true) != null)
246                 this.getBox().setTopBorder( style.getAttributeString(style.ATTRIBUTE_topBorder, null, true) );
247             if (style.getAttributeColor(style.ATTRIBUTE_topBorderColor, null, true) != null)
248                 this.getBox().setTopBorderColor( style.getAttributeColor(style.ATTRIBUTE_topBorderColor, null, true));
249             if (style.getAttributeString(style.ATTRIBUTE_topPadding, null, true) != null)
250                 this.getBox().setTopPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_topPadding, null, true) ));
251             
252             if (style.getAttributeString(style.ATTRIBUTE_leftBorder, null, true) != null)
253                 this.getBox().setLeftBorder( style.getAttributeString(style.ATTRIBUTE_leftBorder, null, true) );
254             if (style.getAttributeColor(style.ATTRIBUTE_leftBorderColor, null, true) != null)
255                 this.getBox().setLeftBorderColor( style.getAttributeColor(style.ATTRIBUTE_leftBorderColor, null, true));
256             if (style.getAttributeString(style.ATTRIBUTE_leftPadding, null, true) != null)
257                 this.getBox().setLeftPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_leftPadding, null, true) ));
258             
259             if (style.getAttributeString(style.ATTRIBUTE_rightBorder, null, true) != null)
260                 this.getBox().setRightBorder( style.getAttributeString(style.ATTRIBUTE_rightBorder, null, true) );
261             if (style.getAttributeColor(style.ATTRIBUTE_rightBorderColor, null, true) != null)
262                 this.getBox().setRightBorderColor( style.getAttributeColor(style.ATTRIBUTE_rightBorderColor, null, true));
263             if (style.getAttributeString(style.ATTRIBUTE_rightPadding, null, true) != null)
264                 this.getBox().setRightPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_rightPadding, null, true) ));
265             
266             if (style.getAttributeString(style.ATTRIBUTE_bottomBorder, null, true) != null)
267                 this.getBox().setBottomBorder( style.getAttributeString(style.ATTRIBUTE_bottomBorder, null, true) );
268             if (style.getAttributeColor(style.ATTRIBUTE_bottomBorderColor, null, true) != null)
269                 this.getBox().setBottomBorderColor( style.getAttributeColor(style.ATTRIBUTE_bottomBorderColor, null, true));
270             if (style.getAttributeString(style.ATTRIBUTE_bottomPadding, null, true) != null)
271                 this.getBox().setBottomPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_bottomPadding, null, true) ));
272             
273         }
274      }
275     
276     public java.util.List JavaDoc getLinkParameters() {
277         return getChart().getLinkParameters();
278     }
279
280     public void setLinkParameters(java.util.List JavaDoc linkParameters) {
281         getChart().setLinkParameters(linkParameters);
282     }
283
284 }
285
Popular Tags