KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > crosstabs > fill > calculation > HeaderCell


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.crosstabs.fill.calculation;
29
30 /**
31  * Crosstab header cell produced by the crosstab bucketing engine.
32  *
33  * @author Lucian Chirita (lucianc@users.sourceforge.net)
34  * @version $Id: HeaderCell.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
35  */

36 public class HeaderCell
37 {
38     private final BucketDefinition.Bucket[] bucketValues;
39     private final int levelSpan;
40     private final int depthSpan;
41     private final boolean isTotal;
42     
43     
44     /**
45      * Creates a crosstab header cell.
46      *
47      * @param bucketValues the bucket values for the cell
48      * @param levelSpan the span across cells on the same level (bucket)
49      * @param depthSpan the span across cells on subsequent levels (buckets)
50      */

51     public HeaderCell(
52             BucketDefinition.Bucket[] bucketValues,
53             int levelSpan,
54             int depthSpan)
55     {
56         this.bucketValues = bucketValues;
57         this.levelSpan = levelSpan;
58         this.depthSpan = depthSpan;
59         
60         boolean foundTotal = false;
61         for (int i = 0; i < bucketValues.length; i++)
62         {
63             if (bucketValues[i] != null && bucketValues[i].isTotal())
64             {
65                 foundTotal = true;
66                 break;
67             }
68         }
69         
70         isTotal = foundTotal;
71     }
72
73
74     /**
75      * Returns the bucket values for this cell.
76      *
77      * @return the bucket values for this cell
78      */

79     public BucketDefinition.Bucket[] getBucketValues()
80     {
81         return bucketValues;
82     }
83
84
85     /**
86      * Returns the span across cells on the same level (bucket).
87      * <p>
88      * This is used for headers of buckets having sub-buckets.
89      *
90      * @return the span across cells on the same level (bucket)
91      */

92     public int getLevelSpan()
93     {
94         return levelSpan;
95     }
96
97
98     /**
99      * Returns the span across cells on subsequent levels (buckets).
100      * <p>
101      * This is used for total headers.
102      *
103      * @return the span across cells on subsequent levels (buckets)
104      */

105     public int getDepthSpan()
106     {
107         return depthSpan;
108     }
109     
110     
111     /**
112      * Returns whether this header is a total header.
113      *
114      * @return whether this header is a total header
115      */

116     public boolean isTotal()
117     {
118         return isTotal;
119     }
120     
121     public static HeaderCell createLevelSpanCopy(HeaderCell cell, int newLevelSpan)
122     {
123         return new HeaderCell(cell.bucketValues, newLevelSpan, cell.getDepthSpan());
124     }
125 }
126
Popular Tags