001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * 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,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.crosstabs.fill.calculation;
029:
030: /**
031: * Crosstab header cell produced by the crosstab bucketing engine.
032: *
033: * @author Lucian Chirita (lucianc@users.sourceforge.net)
034: * @version $Id: HeaderCell.java 1229 2006-04-19 10:27:35Z teodord $
035: */
036: public class HeaderCell {
037: private final BucketDefinition.Bucket[] bucketValues;
038: private final int levelSpan;
039: private final int depthSpan;
040: private final boolean isTotal;
041:
042: /**
043: * Creates a crosstab header cell.
044: *
045: * @param bucketValues the bucket values for the cell
046: * @param levelSpan the span across cells on the same level (bucket)
047: * @param depthSpan the span across cells on subsequent levels (buckets)
048: */
049: public HeaderCell(BucketDefinition.Bucket[] bucketValues,
050: int levelSpan, int depthSpan) {
051: this .bucketValues = bucketValues;
052: this .levelSpan = levelSpan;
053: this .depthSpan = depthSpan;
054:
055: boolean foundTotal = false;
056: for (int i = 0; i < bucketValues.length; i++) {
057: if (bucketValues[i] != null && bucketValues[i].isTotal()) {
058: foundTotal = true;
059: break;
060: }
061: }
062:
063: isTotal = foundTotal;
064: }
065:
066: /**
067: * Returns the bucket values for this cell.
068: *
069: * @return the bucket values for this cell
070: */
071: public BucketDefinition.Bucket[] getBucketValues() {
072: return bucketValues;
073: }
074:
075: /**
076: * Returns the span across cells on the same level (bucket).
077: * <p>
078: * This is used for headers of buckets having sub-buckets.
079: *
080: * @return the span across cells on the same level (bucket)
081: */
082: public int getLevelSpan() {
083: return levelSpan;
084: }
085:
086: /**
087: * Returns the span across cells on subsequent levels (buckets).
088: * <p>
089: * This is used for total headers.
090: *
091: * @return the span across cells on subsequent levels (buckets)
092: */
093: public int getDepthSpan() {
094: return depthSpan;
095: }
096:
097: /**
098: * Returns whether this header is a total header.
099: *
100: * @return whether this header is a total header
101: */
102: public boolean isTotal() {
103: return isTotal;
104: }
105:
106: public static HeaderCell createLevelSpanCopy(HeaderCell cell,
107: int newLevelSpan) {
108: return new HeaderCell(cell.bucketValues, newLevelSpan, cell
109: .getDepthSpan());
110: }
111: }
|