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: * AnchorFilter.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.filter;
030:
031: import org.jfree.report.Anchor;
032: import org.jfree.report.function.ExpressionRuntime;
033:
034: /**
035: * The AnchorFilter converts arbitary objects into Anchors.
036: *
037: * @author Thomas Morgner
038: * @see Anchor
039: * @deprecated The anchor filter is deprecated now. Use the stylekey "anchor" instead.
040: */
041: public class AnchorFilter implements DataFilter {
042: /**
043: * The data source from where to get the values for the anchor.
044: */
045: private DataSource dataSource;
046:
047: /**
048: * DefaultConstructor.
049: */
050: public AnchorFilter() {
051: }
052:
053: /**
054: * Clones this <code>DataSource</code>.
055: *
056: * @return the clone.
057: * @throws CloneNotSupportedException this should never happen.
058: */
059: public Object clone() throws CloneNotSupportedException {
060: final AnchorFilter af = (AnchorFilter) super .clone();
061: if (dataSource == null) {
062: af.dataSource = null;
063: } else {
064: af.dataSource = (DataSource) dataSource.clone();
065: }
066: return af;
067: }
068:
069: /**
070: * Returns the current value for the data source.
071: *
072: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
073: * this filter.
074: * @return the value.
075: */
076: public Object getValue(final ExpressionRuntime runtime) {
077: if (dataSource == null) {
078: return null;
079: }
080: final Object value = dataSource.getValue(runtime);
081: if (value == null) {
082: return null;
083: }
084: if (value instanceof Anchor) {
085: return value;
086: }
087: return new Anchor(String.valueOf(value));
088: }
089:
090: /**
091: * Returns the assigned DataSource for this Target.
092: *
093: * @return The datasource.
094: */
095: public DataSource getDataSource() {
096: return dataSource;
097: }
098:
099: /**
100: * Assigns a DataSource for this Target.
101: *
102: * @param ds The data source.
103: */
104: public void setDataSource(final DataSource ds) {
105: this.dataSource = ds;
106: }
107: }
|