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: * ComponentFieldElementFactory.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.DrawableElement;
032: import org.jfree.report.Element;
033: import org.jfree.report.filter.templates.ComponentFieldTemplate;
034:
035: /**
036: * The drawable field element factory can be used to create elements that display <code>Drawable</code> elements.
037: * <p/>
038: * A drawable field expects the named datasource to contain Drawable objects.
039: * <p/>
040: * Once the desired properties are set, the factory can be reused to create similiar elements.
041: *
042: * @author Thomas Morgner
043: * @see org.jfree.ui.Drawable
044: */
045: public class ComponentFieldElementFactory extends ElementFactory {
046: /**
047: * The fieldname of the datarow from where to read the element data.
048: */
049: private String fieldname;
050: /**
051: * The value-formula that computes the value for this element.
052: */
053: private String formula;
054:
055: /**
056: * DefaultConstructor.
057: */
058: public ComponentFieldElementFactory() {
059: }
060:
061: /**
062: * Returns the field name from where to read the content of the element.
063: *
064: * @return the field name.
065: */
066: public String getFieldname() {
067: return fieldname;
068: }
069:
070: /**
071: * Defines the field name from where to read the content of the element. The field name is the name of a datarow
072: * column.
073: *
074: * @param fieldname the field name.
075: */
076: public void setFieldname(final String fieldname) {
077: this .fieldname = fieldname;
078: }
079:
080: /**
081: * Returns the formula that should be used to compute the value of the field. The formula must be valid according to
082: * the OpenFormula specifications.
083: *
084: * @return the formula as string.
085: */
086: public String getFormula() {
087: return formula;
088: }
089:
090: /**
091: * Assigns a formula to the element to compute the value for this element. If a formula is defined, it will override
092: * the 'field' property.
093: *
094: * @param formula the formula as a string.
095: */
096: public void setFormula(final String formula) {
097: this .formula = formula;
098: }
099:
100: /**
101: * Creates a new drawable field element based on the defined properties.
102: *
103: * @return the generated elements
104: * @throws IllegalStateException if the field name is not set.
105: * @see ElementFactory#createElement()
106: */
107: public Element createElement() {
108: final DrawableElement element = new DrawableElement();
109: applyElementName(element);
110: applyStyle(element.getStyle());
111:
112: final ComponentFieldTemplate fieldTemplate = new ComponentFieldTemplate();
113: if (getFormula() != null) {
114: fieldTemplate.setFormula(getFormula());
115: } else {
116: fieldTemplate.setField(getFieldname());
117: }
118: element.setDataSource(fieldTemplate);
119:
120: return element;
121: }
122: }
|