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: * ShapeFilter.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.filter;
030:
031: import java.awt.Shape;
032:
033: import org.jfree.report.function.ExpressionRuntime;
034:
035: /**
036: * A shape filter.
037: *
038: * @author Thomas Morgner.
039: */
040: public class ShapeFilter implements DataFilter {
041: /**
042: * The data source.
043: */
044: private DataSource dataSource;
045:
046: /**
047: * Default constructor.
048: */
049: public ShapeFilter() {
050: }
051:
052: /**
053: * Returns the data source for the filter.
054: *
055: * @return The data source.
056: */
057: public DataSource getDataSource() {
058: return dataSource;
059: }
060:
061: /**
062: * Sets the data source for the filter.
063: *
064: * @param dataSource The data source.
065: */
066: public void setDataSource(final DataSource dataSource) {
067: this .dataSource = dataSource;
068: }
069:
070: /**
071: * Returns the current value for the data source. <P> The returned object, unless it is
072: * null, will be an instance of ImageReference.
073: *
074: * @param runtime the expression runtime that is used to evaluate formulas and expressions when computing the value of
075: * this filter.
076: * @return The value.
077: */
078: public Object getValue(final ExpressionRuntime runtime) {
079: final DataSource ds = getDataSource();
080: if (ds == null) {
081: return null;
082: }
083: final Object o = ds.getValue(runtime);
084: if (o instanceof Shape) {
085: return o;
086: }
087: return null;
088: }
089:
090: /**
091: * Clones the filter.
092: *
093: * @return A clone of this filter.
094: *
095: * @throws CloneNotSupportedException this should never happen.
096: */
097: public Object clone() throws CloneNotSupportedException {
098: final ShapeFilter r = (ShapeFilter) super .clone();
099: if (dataSource != null) {
100: r.dataSource = (DataSource) dataSource.clone();
101: }
102: return r;
103: }
104:
105: }
|