KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > RefModeRecord


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

17         
18
19 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * Title: RefMode Record<P>
25  * Description: Describes which reference mode to use<P>
26  * REFERENCE: PG 376 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
27  * @author Andrew C. Oliver (acoliver at apache dot org)
28  * @author Jason Height (jheight at chariot dot net dot au)
29  * @version 2.0-pre
30  */

31
32 public class RefModeRecord
33     extends Record
34 {
35     public final static short sid = 0xf;
36     public final static short USE_A1_MODE = 1;
37     public final static short USE_R1C1_MODE = 0;
38     private short field_1_mode;
39
40     public RefModeRecord()
41     {
42     }
43
44     /**
45      * Constructs a RefMode record and sets its fields appropriately.
46      *
47      * @param id id must be 0xf or an exception will be throw upon validation
48      * @param size the size of the data area of the record
49      * @param data data of the record (should not contain sid/len)
50      */

51
52     public RefModeRecord(short id, short size, byte [] data)
53     {
54         super(id, size, data);
55     }
56
57     /**
58      * Constructs a RefMode record and sets its fields appropriately.
59      *
60      * @param id id must be 0xf or an exception will be throw upon validation
61      * @param size the size of the data area of the record
62      * @param data data of the record (should not contain sid/len)
63      * @param offset of the record's data
64      */

65
66     public RefModeRecord(short id, short size, byte [] data, int offset)
67     {
68         super(id, size, data, offset);
69     }
70
71     protected void validateSid(short id)
72     {
73         if (id != sid)
74         {
75             throw new RecordFormatException("NOT An RefMode RECORD");
76         }
77     }
78
79     protected void fillFields(byte [] data, short size, int offset)
80     {
81         field_1_mode = LittleEndian.getShort(data, 0 + offset);
82     }
83
84     /**
85      * set the reference mode to use (HSSF uses/assumes A1)
86      * @param mode the mode to use
87      * @see #USE_A1_MODE
88      * @see #USE_R1C1_MODE
89      *
90      */

91
92     public void setMode(short mode)
93     {
94         field_1_mode = mode;
95     }
96
97     /**
98      * get the reference mode to use (HSSF uses/assumes A1)
99      * @return mode to use
100      * @see #USE_A1_MODE
101      * @see #USE_R1C1_MODE
102      */

103
104     public short getMode()
105     {
106         return field_1_mode;
107     }
108
109     public String JavaDoc toString()
110     {
111         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
112
113         buffer.append("[REFMODE]\n");
114         buffer.append(" .mode = ")
115             .append(Integer.toHexString(getMode())).append("\n");
116         buffer.append("[/REFMODE]\n");
117         return buffer.toString();
118     }
119
120     public int serialize(int offset, byte [] data)
121     {
122         LittleEndian.putShort(data, 0 + offset, sid);
123         LittleEndian.putShort(data, 2 + offset, ( short ) 0x2);
124         LittleEndian.putShort(data, 4 + offset, getMode());
125         return getRecordSize();
126     }
127
128     public int getRecordSize()
129     {
130         return 6;
131     }
132
133     public short getSid()
134     {
135         return this.sid;
136     }
137
138     public Object JavaDoc clone() {
139       RefModeRecord rec = new RefModeRecord();
140       rec.field_1_mode = field_1_mode;
141       return rec;
142     }
143 }
144
Popular Tags