001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine;
029:
030: import net.sf.jasperreports.engine.fill.JRBaseFiller;
031: import net.sf.jasperreports.engine.fill.JRFillChart;
032: import net.sf.jasperreports.engine.fill.JRFillChartDataset;
033:
034: /**
035: * Abstract implementation of {@link net.sf.jasperreports.engine.JRChartCustomizer JRChartCustomizer} that provides
036: * access to parameter, variable and field values.
037: *
038: * @author Lucian Chirita (lucianc@users.sourceforge.net)
039: * @version $Id: JRAbstractChartCustomizer.java 1229 2006-04-19 10:27:35Z teodord $
040: */
041: public abstract class JRAbstractChartCustomizer implements
042: JRChartCustomizer {
043: private JRBaseFiller filler;
044: private JRFillChartDataset chartDataset;
045:
046: /**
047: * Default constructor.
048: */
049: protected JRAbstractChartCustomizer() {
050: }
051:
052: /**
053: * Initializes the chart customizer.
054: *
055: * @param chartFiller the filler instance
056: * @param chart the fill chart object
057: */
058: public void init(JRBaseFiller chartFiller, JRFillChart chart) {
059: this .filler = chartFiller;
060: this .chartDataset = (JRFillChartDataset) chart.getDataset();
061: }
062:
063: /**
064: * Returns the value of a report parameter.
065: *
066: * @param parameterName the parameter name
067: * @return the value of a report parameter
068: */
069: protected final Object getParameterValue(String parameterName) {
070: return getParameterValue(parameterName, false);
071: }
072:
073: /**
074: * Returns the value of a report or input dataset parameter.
075: * <p>
076: * The input dataset differs from the report dataset when the chart
077: * uses a sub dataset as input.
078: *
079: * @param parameterName the parameter name
080: * @param fromInputDataset whether the parameter belongs to the input dataset rather than the report.
081: * <p>
082: * This is usefull only when the chart uses a sub dataset as input.
083: *
084: * @return the value of the parameter
085: */
086: protected final Object getParameterValue(String parameterName,
087: boolean fromInputDataset) {
088: return (fromInputDataset ? chartDataset.getInputDataset()
089: : filler.getMainDataset())
090: .getParameterValue(parameterName);
091: }
092:
093: /**
094: * Returns the value of a report variable.
095: *
096: * @param variableName the variable name
097: * @return the value of a report variable
098: */
099: protected final Object getVariableValue(String variableName) {
100: return getVariableValue(variableName, false);
101: }
102:
103: /**
104: * Returns the value of a report or input dataset variable.
105: * <p>
106: * The input dataset differs from the report dataset when the chart
107: * uses a sub dataset as input.
108: *
109: * @param variableName the variable name
110: * @param fromInputDataset whether the variable belongs to the input dataset rather than the report.
111: * <p>
112: * This is usefull only when the chart uses a sub dataset as input.
113: *
114: * @return the value of the variable
115: */
116: protected final Object getVariableValue(String variableName,
117: boolean fromInputDataset) {
118: return (fromInputDataset ? chartDataset.getInputDataset()
119: : filler.getMainDataset())
120: .getVariableValue(variableName);
121: }
122:
123: /**
124: * Returns the value of a report field.
125: *
126: * @param fieldName the field name
127: * @return the value of a report field
128: */
129: protected final Object getFieldValue(String fieldName) {
130: return getFieldValue(fieldName, false);
131: }
132:
133: /**
134: * Returns the value of a report or input dataset field.
135: * <p>
136: * The input dataset differs from the report dataset when the chart
137: * uses a sub dataset as input.
138: *
139: * @param fieldName the field name
140: * @param fromInputDataset whether the field belongs to the input dataset rather than the report.
141: * <p>
142: * This is usefull only when the chart uses a sub dataset as input.
143: *
144: * @return the value of the field
145: */
146: protected final Object getFieldValue(String fieldName,
147: boolean fromInputDataset) {
148: return (fromInputDataset ? chartDataset.getInputDataset()
149: : filler.getMainDataset()).getFieldValue(fieldName);
150: }
151: }
|