001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either 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, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * AbstractElementFormatFunction.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.function;
030:
031: import org.jfree.report.Band;
032: import org.jfree.report.event.PageEventListener;
033: import org.jfree.report.event.ReportEvent;
034:
035: /**
036: * The AbstractElementFormatFunction provides a common base implementation for all functions that need to modify the
037: * report definition or the style of an report element or band during the report processing.
038: * <p/>
039: * The Expression retrieves the next root-level band that will be printed and uses this band as parameter for the {@link
040: * AbstractElementFormatFunction#processRootBand(org.jfree.report.Band)} method.
041: *
042: * @author Thomas Morgner
043: */
044: public abstract class AbstractElementFormatFunction extends
045: AbstractFunction implements PageEventListener {
046: /**
047: * The name of the element that should be formatted.
048: */
049: private String element;
050:
051: /**
052: * Creates an unnamed function. Make sure the name of the function is set using {@link #setName} before the function
053: * is added to the report's function collection.
054: */
055: protected AbstractElementFormatFunction() {
056: }
057:
058: /**
059: * Sets the element name. The name denotes an element or band within the root-band or the root-band itself. It is
060: * possible to define multiple elements with the same name to apply the modification to all of these elements.
061: *
062: * @param name The element name.
063: * @see org.jfree.report.function.FunctionUtilities#findAllElements(org.jfree.report.Band,String)
064: */
065: public void setElement(final String name) {
066: this .element = name;
067: }
068:
069: /**
070: * Returns the element name.
071: *
072: * @return The element name.
073: * @see #setElement(String)
074: */
075: public String getElement() {
076: return element;
077: }
078:
079: /**
080: * Processes the No-Data-Band.
081: *
082: * @param event the report event.
083: */
084: public void itemsStarted(final ReportEvent event) {
085: if (FunctionUtilities.isLayoutLevel(event) == false) {
086: // dont do anything if there is no printing done ...
087: return;
088: }
089: final Band b = event.getReport().getNoDataBand();
090: processRootBand(b);
091: }
092:
093: /**
094: * Processes the ItemBand.
095: *
096: * @param event the event.
097: */
098: public void itemsAdvanced(final ReportEvent event) {
099: if (FunctionUtilities.isLayoutLevel(event) == false) {
100: // dont do anything if there is no printing done ...
101: return;
102: }
103: final Band b = event.getReport().getItemBand();
104: processRootBand(b);
105: }
106:
107: /**
108: * Processes the Report-Footer.
109: *
110: * @param event the event.
111: */
112: public void reportFinished(final ReportEvent event) {
113: if (FunctionUtilities.isLayoutLevel(event) == false) {
114: // dont do anything if there is no printing done ...
115: return;
116: }
117: final Band b = event.getReport().getReportFooter();
118: processRootBand(b);
119: }
120:
121: /**
122: * Processes the Report-Header.
123: *
124: * @param event the event.
125: */
126: public void reportStarted(final ReportEvent event) {
127: if (FunctionUtilities.isLayoutLevel(event) == false) {
128: // dont do anything if there is no printing done ...
129: return;
130: }
131: final Band b = event.getReport().getReportHeader();
132: processRootBand(b);
133: }
134:
135: /**
136: * Processes the group header of the current group.
137: *
138: * @param event the event.
139: */
140: public void groupStarted(final ReportEvent event) {
141: if (FunctionUtilities.isLayoutLevel(event) == false) {
142: // dont do anything if there is no printing done ...
143: return;
144: }
145: final Band b = FunctionUtilities.getCurrentGroup(event)
146: .getHeader();
147: processRootBand(b);
148: }
149:
150: /**
151: * Processes the group footer of the current group.
152: *
153: * @param event the event.
154: */
155: public void groupFinished(final ReportEvent event) {
156: if (FunctionUtilities.isLayoutLevel(event) == false) {
157: // dont do anything if there is no printing done ...
158: return;
159: }
160: final Band b = FunctionUtilities.getCurrentGroup(event)
161: .getFooter();
162: processRootBand(b);
163: }
164:
165: /**
166: * Processes the page footer.
167: *
168: * @param event the event.
169: */
170: public void pageFinished(final ReportEvent event) {
171: if (FunctionUtilities.isLayoutLevel(event) == false) {
172: // dont do anything if there is no printing done ...
173: return;
174: }
175: final Band b = event.getReport().getPageFooter();
176: processRootBand(b);
177: }
178:
179: /**
180: * Processes the page header.
181: *
182: * @param event the event.
183: */
184: public void pageStarted(final ReportEvent event) {
185: if (FunctionUtilities.isLayoutLevel(event) == false) {
186: // dont do anything if there is no printing done ...
187: return;
188: }
189: final Band b = event.getReport().getPageHeader();
190: processRootBand(b);
191:
192: final Band w = event.getReport().getWatermark();
193: processRootBand(w);
194: }
195:
196: /**
197: * Processes the root band for the current event. This method must be implemented by all subclasses and contains all
198: * code necessary to update the style or structure of the given band. The update must be deterministic, calls must
199: * result in the same layout for all calls for a given report processing state.
200: *
201: * @param b the band.
202: */
203: protected abstract void processRootBand(Band b);
204:
205: /**
206: * Format-Functions usually are not expected to return anything.
207: *
208: * @return null, as format functions do not compute values.
209: */
210: public Object getValue() {
211: return null;
212: }
213: }
|