KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > JRAbstractChartCustomizer


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine;
29
30 import net.sf.jasperreports.engine.fill.JRBaseFiller;
31 import net.sf.jasperreports.engine.fill.JRFillChart;
32 import net.sf.jasperreports.engine.fill.JRFillChartDataset;
33
34 /**
35  * Abstract implementation of {@link net.sf.jasperreports.engine.JRChartCustomizer JRChartCustomizer} that provides
36  * access to parameter, variable and field values.
37  *
38  * @author Lucian Chirita (lucianc@users.sourceforge.net)
39  * @version $Id: JRAbstractChartCustomizer.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
40  */

41 public abstract class JRAbstractChartCustomizer implements JRChartCustomizer
42 {
43     private JRBaseFiller filler;
44     private JRFillChartDataset chartDataset;
45     
46     
47     /**
48      * Default constructor.
49      */

50     protected JRAbstractChartCustomizer()
51     {
52     }
53
54     
55     /**
56      * Initializes the chart customizer.
57      *
58      * @param chartFiller the filler instance
59      * @param chart the fill chart object
60      */

61     public void init(JRBaseFiller chartFiller, JRFillChart chart)
62     {
63         this.filler = chartFiller;
64         this.chartDataset = (JRFillChartDataset) chart.getDataset();
65     }
66     
67     
68     /**
69      * Returns the value of a report parameter.
70      *
71      * @param parameterName the parameter name
72      * @return the value of a report parameter
73      */

74     protected final Object JavaDoc getParameterValue(String JavaDoc parameterName)
75     {
76         return getParameterValue(parameterName, false);
77     }
78     
79     
80     /**
81      * Returns the value of a report or input dataset parameter.
82      * <p>
83      * The input dataset differs from the report dataset when the chart
84      * uses a sub dataset as input.
85      *
86      * @param parameterName the parameter name
87      * @param fromInputDataset whether the parameter belongs to the input dataset rather than the report.
88      * <p>
89      * This is usefull only when the chart uses a sub dataset as input.
90      *
91      * @return the value of the parameter
92      */

93     protected final Object JavaDoc getParameterValue(String JavaDoc parameterName, boolean fromInputDataset)
94     {
95         return (fromInputDataset ? chartDataset.getInputDataset() : filler.getMainDataset()).getParameterValue(parameterName);
96     }
97     
98         
99     /**
100      * Returns the value of a report variable.
101      *
102      * @param variableName the variable name
103      * @return the value of a report variable
104      */

105     protected final Object JavaDoc getVariableValue(String JavaDoc variableName)
106     {
107         return getVariableValue(variableName, false);
108     }
109     
110     
111     /**
112      * Returns the value of a report or input dataset variable.
113      * <p>
114      * The input dataset differs from the report dataset when the chart
115      * uses a sub dataset as input.
116      *
117      * @param variableName the variable name
118      * @param fromInputDataset whether the variable belongs to the input dataset rather than the report.
119      * <p>
120      * This is usefull only when the chart uses a sub dataset as input.
121      *
122      * @return the value of the variable
123      */

124     protected final Object JavaDoc getVariableValue(String JavaDoc variableName, boolean fromInputDataset)
125     {
126         return (fromInputDataset ? chartDataset.getInputDataset() : filler.getMainDataset()).getVariableValue(variableName);
127     }
128     
129         
130     /**
131      * Returns the value of a report field.
132      *
133      * @param fieldName the field name
134      * @return the value of a report field
135      */

136     protected final Object JavaDoc getFieldValue(String JavaDoc fieldName)
137     {
138         return getFieldValue(fieldName, false);
139     }
140     
141     
142     /**
143      * Returns the value of a report or input dataset field.
144      * <p>
145      * The input dataset differs from the report dataset when the chart
146      * uses a sub dataset as input.
147      *
148      * @param fieldName the field name
149      * @param fromInputDataset whether the field belongs to the input dataset rather than the report.
150      * <p>
151      * This is usefull only when the chart uses a sub dataset as input.
152      *
153      * @return the value of the field
154      */

155     protected final Object JavaDoc getFieldValue(String JavaDoc fieldName, boolean fromInputDataset)
156     {
157         return (fromInputDataset ? chartDataset.getInputDataset() : filler.getMainDataset()).getFieldValue(fieldName);
158     }
159 }
160
Popular Tags