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: * AnchorFieldElementFactory.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.elementfactory;
030:
031: import org.jfree.report.AnchorElement;
032: import org.jfree.report.Element;
033: import org.jfree.report.filter.templates.AnchorFieldTemplate;
034:
035: /**
036: * The AnchorFieldElementFactory can be used to construct Anchor fields. Anchor fields generate Anchor-Objects from
037: * content found in a DataRow-column or function.
038: *
039: * @author Thomas Morgner
040: * @deprecated Anchor elements have been rendered obsolete by introducing the Anchor-Stylekey and the
041: * style-expressions.
042: */
043: public class AnchorFieldElementFactory extends ElementFactory {
044: /**
045: * The fieldname.
046: */
047: private String fieldname;
048: /**
049: * The value-formula that computes the value for this element.
050: */
051: private String formula;
052:
053: /**
054: * Creates a new Factory.
055: */
056: public AnchorFieldElementFactory() {
057: }
058:
059: /**
060: * Returns the element's field name.
061: *
062: * @return the fieldname
063: */
064: public String getFieldname() {
065: return fieldname;
066: }
067:
068: /**
069: * Defines the field name. The field name should be the name of a 'marked' report property, a function or expression
070: * name or the name of a table model column.
071: *
072: * @param field the field name.
073: */
074: public void setFieldname(final String field) {
075: this .fieldname = field;
076: }
077:
078: /**
079: * Returns the formula that should be used to compute the value of the field. The formula must be valid according to
080: * the OpenFormula specifications.
081: *
082: * @return the formula as string.
083: */
084: public String getFormula() {
085: return formula;
086: }
087:
088: /**
089: * Assigns a formula to the element to compute the value for this element. If a formula is defined, it will override
090: * the 'field' property.
091: *
092: * @param formula the formula as a string.
093: */
094: public void setFormula(final String formula) {
095: this .formula = formula;
096: }
097:
098: /**
099: * Creates a new instance of the element.
100: *
101: * @return the newly generated instance of the element.
102: */
103: public Element createElement() {
104: final AnchorElement element = new AnchorElement();
105: final AnchorFieldTemplate fieldTemplate = new AnchorFieldTemplate();
106: if (getFormula() != null) {
107: fieldTemplate.setFormula(getFormula());
108: } else {
109: fieldTemplate.setField(getFieldname());
110: }
111:
112: applyElementName(element);
113: applyStyle(element.getStyle());
114: element.setDataSource(fieldTemplate);
115: return element;
116: }
117: }
|