KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > formula > Area3DPtg


1 /* ====================================================================
2    Copyright 2003-2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.record.formula;
18
19 import org.apache.poi.util.LittleEndian;
20 import org.apache.poi.hssf.util.RangeAddress;
21 import org.apache.poi.hssf.util.AreaReference;
22 import org.apache.poi.hssf.util.CellReference;
23 import org.apache.poi.hssf.util.SheetReferences;
24
25 import org.apache.poi.hssf.model.Workbook;
26 import org.apache.poi.util.BitField;
27
28 /**
29  * Title: Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
30  * Description: Defined a area in Extern Sheet. <P>
31  * REFERENCE: <P>
32  * @author Libin Roman (Vista Portal LDT. Developer)
33  * @author avik
34  * @author Jason Height (jheight at chariot dot net dot au)
35  * @version 1.0-pre
36  */

37
38 public class Area3DPtg extends Ptg
39 {
40     public final static byte sid = 0x3b;
41     private final static int SIZE = 11; // 10 + 1 for Ptg
42
private short field_1_index_extern_sheet;
43     private short field_2_first_row;
44     private short field_3_last_row;
45     private short field_4_first_column;
46     private short field_5_last_column;
47
48     private BitField rowRelative = new BitField( 0x8000 );
49     private BitField colRelative = new BitField( 0x4000 );
50
51     /** Creates new AreaPtg */
52     public Area3DPtg()
53     {
54     }
55
56     public Area3DPtg( String JavaDoc arearef, short externIdx )
57     {
58         setArea(arearef);
59         setExternSheetIndex( externIdx );
60
61     }
62
63     public Area3DPtg( byte[] data, int offset )
64     {
65         offset++;
66         field_1_index_extern_sheet = LittleEndian.getShort( data, 0 + offset );
67         field_2_first_row = LittleEndian.getShort( data, 2 + offset );
68         field_3_last_row = LittleEndian.getShort( data, 4 + offset );
69         field_4_first_column = LittleEndian.getShort( data, 6 + offset );
70         field_5_last_column = LittleEndian.getShort( data, 8 + offset );
71     }
72
73     public String JavaDoc toString()
74     {
75         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
76
77         buffer.append( "AreaPtg\n" );
78         buffer.append( "Index to Extern Sheet = " + getExternSheetIndex() ).append( "\n" );
79         buffer.append( "firstRow = " + getFirstRow() ).append( "\n" );
80         buffer.append( "lastRow = " + getLastRow() ).append( "\n" );
81         buffer.append( "firstCol = " + getFirstColumn() ).append( "\n" );
82         buffer.append( "lastCol = " + getLastColumn() ).append( "\n" );
83         buffer.append( "firstColRel= "
84                 + isFirstRowRelative() ).append( "\n" );
85         buffer.append( "lastColRowRel = "
86                 + isLastRowRelative() ).append( "\n" );
87         buffer.append( "firstColRel = " + isFirstColRelative() ).append( "\n" );
88         buffer.append( "lastColRel = " + isLastColRelative() ).append( "\n" );
89         return buffer.toString();
90     }
91
92     public void writeBytes( byte[] array, int offset )
93     {
94         array[0 + offset] = (byte) ( sid + ptgClass );
95         LittleEndian.putShort( array, 1 + offset, getExternSheetIndex() );
96         LittleEndian.putShort( array, 3 + offset, getFirstRow() );
97         LittleEndian.putShort( array, 5 + offset, getLastRow() );
98         LittleEndian.putShort( array, 7 + offset, getFirstColumnRaw() );
99         LittleEndian.putShort( array, 9 + offset, getLastColumnRaw() );
100     }
101
102     public int getSize()
103     {
104         return SIZE;
105     }
106
107     public short getExternSheetIndex()
108     {
109         return field_1_index_extern_sheet;
110     }
111
112     public void setExternSheetIndex( short index )
113     {
114         field_1_index_extern_sheet = index;
115     }
116
117     public short getFirstRow()
118     {
119         return field_2_first_row;
120     }
121
122     public void setFirstRow( short row )
123     {
124         field_2_first_row = row;
125     }
126
127     public short getLastRow()
128     {
129         return field_3_last_row;
130     }
131
132     public void setLastRow( short row )
133     {
134         field_3_last_row = row;
135     }
136
137     public short getFirstColumn()
138     {
139         return (short) ( field_4_first_column & 0xFF );
140     }
141
142     public short getFirstColumnRaw()
143     {
144         return field_4_first_column;
145     }
146
147     public boolean isFirstRowRelative()
148     {
149         return rowRelative.isSet( field_4_first_column );
150     }
151
152     public boolean isFirstColRelative()
153     {
154         return colRelative.isSet( field_4_first_column );
155     }
156
157     public void setFirstColumn( short column )
158     {
159         field_4_first_column &= 0xFF00;
160         field_4_first_column |= column & 0xFF;
161     }
162
163     public void setFirstColumnRaw( short column )
164     {
165         field_4_first_column = column;
166     }
167
168     public short getLastColumn()
169     {
170         return (short) ( field_5_last_column & 0xFF );
171     }
172
173     public short getLastColumnRaw()
174     {
175         return field_5_last_column;
176     }
177
178     public boolean isLastRowRelative()
179     {
180         return rowRelative.isSet( field_5_last_column );
181     }
182
183     public boolean isLastColRelative()
184     {
185         return colRelative.isSet( field_5_last_column );
186     }
187
188     public void setLastColumn( short column )
189     {
190         field_5_last_column &= 0xFF00;
191         field_5_last_column |= column & 0xFF;
192     }
193
194     public void setLastColumnRaw( short column )
195     {
196         field_5_last_column = column;
197     }
198
199     /**
200      * sets the first row to relative or not
201      * @param rel FIXME: Document this!
202      */

203     public void setFirstRowRelative( boolean rel )
204     {
205         field_4_first_column = rowRelative.setShortBoolean( field_4_first_column, rel );
206     }
207
208     /**
209      * set whether the first column is relative
210      */

211     public void setFirstColRelative( boolean rel )
212     {
213         field_4_first_column = colRelative.setShortBoolean( field_4_first_column, rel );
214     }
215
216     /**
217      * set whether the last row is relative or not
218      * @param rel FIXME: Document this!
219      */

220     public void setLastRowRelative( boolean rel )
221     {
222         field_5_last_column = rowRelative.setShortBoolean( field_5_last_column, rel );
223     }
224
225     /**
226      * set whether the last column should be relative or not
227      */

228     public void setLastColRelative( boolean rel )
229     {
230         field_5_last_column = colRelative.setShortBoolean( field_5_last_column, rel );
231     }
232
233
234     /*public String getArea(){
235         RangeAddress ra = new RangeAddress( getFirstColumn(),getFirstRow() + 1, getLastColumn(), getLastRow() + 1);
236         String result = ra.getAddress();
237
238         return result;
239     }*/

240
241     public void setArea( String JavaDoc ref )
242     {
243         AreaReference ar = new AreaReference( ref );
244
245         setFirstRow( (short) ar.getCells()[0].getRow() );
246         setFirstColumn( (short) ar.getCells()[0].getCol() );
247         setLastRow( (short) ar.getCells()[1].getRow() );
248         setLastColumn( (short) ar.getCells()[1].getCol() );
249         setFirstColRelative( !ar.getCells()[0].isColAbsolute() );
250         setLastColRelative( !ar.getCells()[1].isColAbsolute() );
251         setFirstRowRelative( !ar.getCells()[0].isRowAbsolute() );
252         setLastRowRelative( !ar.getCells()[1].isRowAbsolute() );
253
254     }
255
256     public String JavaDoc toFormulaString(Workbook book)
257     {
258         SheetReferences refs = book == null ? null : book.getSheetReferences();
259         StringBuffer JavaDoc retval = new StringBuffer JavaDoc();
260         if ( refs != null )
261         {
262             retval.append( refs.getSheetName( this.field_1_index_extern_sheet ) );
263             retval.append( '!' );
264         }
265         retval.append( ( new CellReference( getFirstRow(), getFirstColumn(), !isFirstRowRelative(), !isFirstColRelative() ) ).toString() );
266         retval.append( ':' );
267         retval.append( ( new CellReference( getLastRow(), getLastColumn(), !isLastRowRelative(), !isLastColRelative() ) ).toString() );
268         return retval.toString();
269     }
270
271     public byte getDefaultOperandClass()
272     {
273         return Ptg.CLASS_REF;
274     }
275
276     public Object JavaDoc clone()
277     {
278         Area3DPtg ptg = new Area3DPtg();
279         ptg.field_1_index_extern_sheet = field_1_index_extern_sheet;
280         ptg.field_2_first_row = field_2_first_row;
281         ptg.field_3_last_row = field_3_last_row;
282         ptg.field_4_first_column = field_4_first_column;
283         ptg.field_5_last_column = field_5_last_column;
284             ptg.setClass(ptgClass);
285         return ptg;
286     }
287
288
289     public boolean equals( Object JavaDoc o )
290     {
291         if ( this == o ) return true;
292         if ( !( o instanceof Area3DPtg ) ) return false;
293
294         final Area3DPtg area3DPtg = (Area3DPtg) o;
295
296         if ( field_1_index_extern_sheet != area3DPtg.field_1_index_extern_sheet ) return false;
297         if ( field_2_first_row != area3DPtg.field_2_first_row ) return false;
298         if ( field_3_last_row != area3DPtg.field_3_last_row ) return false;
299         if ( field_4_first_column != area3DPtg.field_4_first_column ) return false;
300         if ( field_5_last_column != area3DPtg.field_5_last_column ) return false;
301
302         return true;
303     }
304
305     public int hashCode()
306     {
307         int result;
308         result = (int) field_1_index_extern_sheet;
309         result = 29 * result + (int) field_2_first_row;
310         result = 29 * result + (int) field_3_last_row;
311         result = 29 * result + (int) field_4_first_column;
312         result = 29 * result + (int) field_5_last_column;
313         return result;
314     }
315
316
317 }
318
Popular Tags