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: * LabelTemplate.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.filter.templates;
030:
031: import org.jfree.report.filter.StaticDataSource;
032: import org.jfree.report.filter.StringFilter;
033: import org.jfree.report.function.ExpressionRuntime;
034:
035: /**
036: * A label template can be used to describe static text content.
037: *
038: * @author Thomas Morgner
039: */
040: public class LabelTemplate extends AbstractTemplate {
041: /**
042: * A static data source.
043: */
044: private StaticDataSource staticDataSource;
045:
046: /**
047: * A string filter.
048: */
049: private StringFilter stringFilter;
050:
051: /**
052: * Creates a new label template.
053: */
054: public LabelTemplate() {
055: staticDataSource = new StaticDataSource();
056: stringFilter = new StringFilter();
057: stringFilter.setDataSource(staticDataSource);
058: }
059:
060: /**
061: * Sets the text for the label.
062: *
063: * @param content the text.
064: */
065: public void setContent(final String content) {
066: staticDataSource.setValue(content);
067: }
068:
069: /**
070: * Returns the text for the label.
071: *
072: * @return The text.
073: */
074: public String getContent() {
075: return (String) (staticDataSource.getValue(null));
076: }
077:
078: /**
079: * Returns the string that represents <code>null</code>.
080: *
081: * @return The string that represents <code>null</code>.
082: */
083: public String getNullValue() {
084: return stringFilter.getNullValue();
085: }
086:
087: /**
088: * Sets the string that represents <code>null</code>.
089: *
090: * @param nullValue the string.
091: */
092: public void setNullValue(final String nullValue) {
093: stringFilter.setNullValue(nullValue);
094: }
095:
096: /**
097: * Returns the current value for the data source.
098: *
099: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
100: * this filter.
101: * @return the value.
102: */
103: public Object getValue(final ExpressionRuntime runtime) {
104: return stringFilter.getValue(runtime);
105: }
106:
107: /**
108: * Clones the template.
109: *
110: * @return the clone.
111: *
112: * @throws CloneNotSupportedException this should never happen.
113: */
114: public Object clone() throws CloneNotSupportedException {
115: final LabelTemplate template = (LabelTemplate) super .clone();
116: template.stringFilter = (StringFilter) stringFilter.clone();
117: template.staticDataSource = (StaticDataSource) template.stringFilter
118: .getDataSource();
119: return template;
120: }
121:
122: }
|