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: * CreateGroupAnchorsFunction.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.Anchor;
032: import org.jfree.report.event.ReportEvent;
033:
034: /**
035: * Creates anchor objects for the current group. The anchors generated consist of the group's name and the current group
036: * count.
037: * <p/>
038: * To use the CreateGroupAnchorsFunction set the group's name as the function's group-property value. Next, add a
039: * AnchorElement to where the anchor should be generated (usually either the group-header or footer) and give the
040: * function's name as fieldname in the anchor-field.
041: *
042: * @author Thomas Morgner
043: * @deprecated It is easier to create anchors using a Style-expression. The Anchor-Field has been deprecated now.
044: */
045: public class CreateGroupAnchorsFunction extends AbstractFunction {
046: /**
047: * The name of the group for which anchors should be created.
048: */
049: private String group;
050: /**
051: * A prefix for the anchor name.
052: */
053: private String anchorPrefix;
054: /**
055: * A temporary variable holding the last anchor created by this function.
056: */
057: private Anchor anchor;
058: /**
059: * A counter to create unique anchor names.
060: */
061: private int count;
062:
063: /**
064: * Default Constructor. Does nothing.
065: */
066: public CreateGroupAnchorsFunction() {
067: anchorPrefix = "anchor";
068: }
069:
070: /**
071: * Returns the prefix for the generated anchor.
072: *
073: * @return the anchor prefix.
074: */
075: public String getAnchorPrefix() {
076: return anchorPrefix;
077: }
078:
079: /**
080: * Defines the prefix for the generated anchor.
081: *
082: * @param anchorPrefix the prefix for the anchor.
083: */
084: public void setAnchorPrefix(final String anchorPrefix) {
085: if (anchorPrefix == null) {
086: throw new NullPointerException(
087: "The Anchor-Prefix must not be null.");
088: }
089: this .anchorPrefix = anchorPrefix;
090: }
091:
092: /**
093: * Returns the name of the group for which an anchor should be generated.
094: *
095: * @return the name of the group.
096: */
097: public String getGroup() {
098: return group;
099: }
100:
101: /**
102: * Defines the name of the group for which an anchor should be generated.
103: *
104: * @param group the name of the group.
105: */
106: public void setGroup(final String group) {
107: this .group = group;
108: }
109:
110: /**
111: * Receives notification that report generation initializes the current run. <P> The event carries a
112: * ReportState.Started state. Use this to initialize the report.
113: *
114: * @param event The event.
115: */
116: public void reportInitialized(final ReportEvent event) {
117: count = 0;
118:
119: final StringBuffer targetBuffer = new StringBuffer();
120: final String prefix = getAnchorPrefix();
121: targetBuffer.append(prefix);
122: targetBuffer.append(getGroup());
123: targetBuffer.append("%3D");
124: targetBuffer.append(count);
125: anchor = new Anchor(targetBuffer.toString());
126: }
127:
128: /**
129: * Receives notification that a group has started.
130: *
131: * @param event the event.
132: */
133: public void groupStarted(final ReportEvent event) {
134: if (FunctionUtilities.isDefinedGroup(getGroup(), event) == false) {
135: return;
136: }
137:
138: final StringBuffer targetBuffer = new StringBuffer();
139: final String prefix = getAnchorPrefix();
140: targetBuffer.append(prefix);
141: targetBuffer.append(getGroup());
142: targetBuffer.append("%3D");
143: targetBuffer.append(count);
144: anchor = new Anchor(targetBuffer.toString());
145: }
146:
147: /**
148: * Return the current expression value. <P> The value depends (obviously) on the expression implementation.
149: *
150: * @return the value of the function.
151: */
152: public Object getValue() {
153: return anchor;
154: }
155: }
|