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: * ElementVisibilityFunction.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.function;
030:
031: import org.jfree.report.Band;
032: import org.jfree.report.Element;
033:
034: /**
035: * Triggers the visiblity of an element based on the boolean value read from the defined field.
036: *
037: * @author Thomas Morgner
038: * @deprecated add a style-expression for the visible style-key instead.
039: */
040: public class ElementVisibilityFunction extends
041: AbstractElementFormatFunction {
042: /**
043: * The field name of the data-row column from where to read the boolean value.
044: */
045: private String field;
046:
047: /**
048: * Default Constructor.
049: */
050: public ElementVisibilityFunction() {
051: }
052:
053: /**
054: * Returns the field name of the data-row column from where to read the boolean value.
055: *
056: * @return the field name.
057: */
058: public String getField() {
059: return field;
060: }
061:
062: /**
063: * Defines field name of the data-row column from where to read the boolean value.
064: *
065: * @param field the name of the field.
066: */
067: public void setField(final String field) {
068: this .field = field;
069: }
070:
071: /**
072: * Returns whether the element will be visible or not.
073: *
074: * @return Boolean.TRUE or Boolean.FALSE.
075: */
076: public Object getValue() {
077: if (isVisible()) {
078: return Boolean.TRUE;
079: } else {
080: return Boolean.FALSE;
081: }
082: }
083:
084: /**
085: * Applies the visibility to all elements of the band with the given name.
086: *
087: * @param b the root band.
088: */
089: protected void processRootBand(final Band b) {
090: final boolean visible = isVisible();
091: final Element[] elements = FunctionUtilities.findAllElements(b,
092: getElement());
093: for (int i = 0; i < elements.length; i++) {
094: final Element element = elements[i];
095: element.setVisible(visible);
096: }
097:
098: }
099:
100: /**
101: * Computes the visiblity of the element.
102: *
103: * @return true, if the field contains the Boolean.TRUE object, false otherwise.
104: */
105: protected boolean isVisible() {
106: return Boolean.TRUE.equals(getDataRow().get(getField()));
107: }
108: }
|