KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > span > Span


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.table.span;
14
15 import org.apache.log4j.Logger;
16
17 import com.tonbeller.jpivot.olap.model.Axis;
18 import com.tonbeller.jpivot.olap.model.Displayable;
19 import com.tonbeller.jpivot.olap.model.Member;
20 import com.tonbeller.jpivot.olap.model.Position;
21
22
23 /**
24  * contains info about one cell of an table axis.
25  */

26
27 public class Span implements Cloneable JavaDoc {
28   int positionSpan = 1;
29   int hierarchySpan = 1;
30   int positionIndex;
31   int hierarchyIndex;
32   boolean significant = true;
33   int indent;
34   private static final Logger logger = Logger.getLogger(Span.class);
35
36   Axis axis;
37   Position position;
38   Displayable object;
39
40   public Span(Axis axis, Position position, Displayable object) {
41     this.axis = axis;
42     this.position = position;
43     this.object = object;
44   }
45
46   public Span(Displayable object) {
47     this.object = object;
48   }
49
50   public String JavaDoc toString() {
51     StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Span[");
52     if (object == null)
53       sb.append("null ");
54     else
55       sb.append(object.getLabel());
56     sb.append(" positionSpan=").append(positionSpan);
57     sb.append(" hierarchySpan=").append(hierarchySpan);
58     sb.append(" positionIndex=").append(positionIndex);
59     sb.append(" hierarchyIndex=").append(hierarchyIndex);
60     sb.append(" significant=").append(significant);
61     sb.append(" indent=").append(indent);
62     sb.append("]");
63     return sb.toString();
64   }
65
66
67   /**
68    * initializes this to 1 row and 1 column
69    */

70   void initialize(int posIndex, int hierIndex) {
71     this.positionIndex = posIndex;
72     this.hierarchyIndex = hierIndex;
73     this.positionSpan = 1;
74     this.hierarchySpan = 1;
75     this.significant = true;
76   }
77
78   /**
79    * Returns the hierarchySpan.
80    * @return int
81    */

82   public int getHierarchySpan() {
83     return hierarchySpan;
84   }
85
86   /**
87    * Returns the data of this axis cell. Common types are Member, Level or Hierarchy but other
88    * objects are possible too.
89    * @return Object
90    */

91   public Displayable getObject() {
92     return object;
93   }
94
95   /**
96    * Sets the object.
97    * @param object The object to set
98    */

99   public void setObject(Displayable object) {
100     this.object = object;
101   }
102
103   /**
104    * Returns the positionSpan.
105    * @return int
106    */

107   public int getPositionSpan() {
108     return positionSpan;
109   }
110
111   /**
112    * Returns the axis.
113    * @return Axis
114    */

115   public Axis getAxis() {
116     return axis;
117   }
118
119   /**
120    * Returns the position.
121    * @return Position
122    */

123   public Position getPosition() {
124     return position;
125   }
126
127   /**
128    * shorthand for (Member)span.getObject()
129    */

130   public Member getMember() {
131     return (Member)object;
132   }
133
134   /**
135    * Returns the hierarchyIndex.
136    * @return int
137    */

138   public int getHierarchyIndex() {
139     return hierarchyIndex;
140   }
141
142   /**
143    * Returns the positionIndex.
144    * @return int
145    */

146   public int getPositionIndex() {
147     return positionIndex;
148   }
149
150   /**
151    * true if this span denotes a member. I.e. getObject() instanceof Member
152    */

153   public boolean isMember() {
154     return object instanceof Member;
155   }
156
157   /**
158    * @see java.lang.Object#clone()
159    */

160   public Object JavaDoc clone() {
161     try {
162       return super.clone();
163     } catch (CloneNotSupportedException JavaDoc e) {
164             logger.error("exception caught", e);
165       throw new RuntimeException JavaDoc(e.toString());
166     }
167   }
168
169   /**
170    * true, if this introduces a new span, i.e. is positioned on the upper left of a multi column or multi row field.
171    * @return boolean
172    */

173   public boolean isSignificant() {
174     return significant;
175   }
176
177   /**
178    * Sets the axis.
179    * @param axis The axis to set
180    */

181   public void setAxis(Axis axis) {
182     this.axis = axis;
183   }
184
185
186   /**
187    * Sets the position.
188    * @param position The position to set
189    */

190   public void setPosition(Position position) {
191     this.position = position;
192   }
193
194   /**
195    * @return
196    */

197   public int getIndent() {
198     return indent;
199   }
200
201   /**
202    * @param i
203    */

204   public void setIndent(int i) {
205     indent = i;
206   }
207
208 }
209
210
Popular Tags