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: * DrawableURLFieldElementFactory.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.elementfactory;
030:
031: import java.net.URL;
032:
033: import org.jfree.report.DrawableElement;
034: import org.jfree.report.Element;
035: import org.jfree.report.filter.templates.DrawableURLFieldTemplate;
036:
037: /**
038: * The DrawableURLField can be used to load drawables from an URL specified in the named column of the datarow.
039: *
040: * @author Thomas Morgner
041: */
042: public class DrawableURLFieldElementFactory extends ElementFactory {
043: /**
044: * The fieldname of the datarow from where to read the content.
045: */
046: private String fieldname;
047: /**
048: * The value-formula for this field-element.
049: */
050: private String formula;
051:
052: /**
053: * The base URL is used to resolve relative URLs.
054: */
055: private URL baseURL;
056:
057: /**
058: * Creates a new Factory.
059: */
060: public DrawableURLFieldElementFactory() {
061: }
062:
063: /**
064: * Returns the field name from where to read the content of the element.
065: *
066: * @return the field name.
067: */
068: public String getFieldname() {
069: return fieldname;
070: }
071:
072: /**
073: * Defines the field name from where to read the content of the element. The field name is the name of a datarow
074: * column.
075: *
076: * @param fieldname the field name.
077: */
078: public void setFieldname(final String fieldname) {
079: this .fieldname = fieldname;
080: }
081:
082: /**
083: * Returns the formula that should be used to compute the value of the field. The formula must be valid according to
084: * the OpenFormula specifications.
085: *
086: * @return the formula as string.
087: */
088: public String getFormula() {
089: return formula;
090: }
091:
092: /**
093: * Assigns a formula to the element to compute the value for this element. If a formula is defined, it will override
094: * the 'field' property.
095: *
096: * @param formula the formula as a string.
097: */
098: public void setFormula(final String formula) {
099: this .formula = formula;
100: }
101:
102: /**
103: * Returns the base url. The BaseURL is used to resolve relative URLs found in the datasource.
104: *
105: * @return the base url.
106: */
107: public URL getBaseURL() {
108: return baseURL;
109: }
110:
111: /**
112: * Defines a BaseURL for the new element. The BaseURL is used to resolve relative URLs found in the datasource.
113: *
114: * @param baseURL the base URL.
115: */
116: public void setBaseURL(final URL baseURL) {
117: this .baseURL = baseURL;
118: }
119:
120: /**
121: * Creates a new drawable field element based on the defined properties.
122: *
123: * @return the generated elements
124: * @throws IllegalStateException if the field name is not set.
125: * @see ElementFactory#createElement()
126: */
127: public Element createElement() {
128: final DrawableElement element = new DrawableElement();
129: applyElementName(element);
130: applyStyle(element.getStyle());
131:
132: final DrawableURLFieldTemplate fieldTemplate = new DrawableURLFieldTemplate();
133: if (getFormula() != null) {
134: fieldTemplate.setFormula(getFormula());
135: } else {
136: fieldTemplate.setField(getFieldname());
137: }
138: fieldTemplate.setBaseURL(getBaseURL());
139: element.setDataSource(fieldTemplate);
140:
141: return element;
142: }
143:
144: }
|