KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > ListLevel


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.hwpf.model;
20
21 import org.apache.poi.util.BitField;
22 import org.apache.poi.util.LittleEndian;
23
24 import org.apache.poi.hwpf.usermodel.CharacterProperties;
25 import org.apache.poi.hwpf.usermodel.ParagraphProperties;
26
27 import org.apache.poi.hwpf.sprm.ParagraphSprmCompressor;
28 import org.apache.poi.hwpf.sprm.CharacterSprmCompressor;
29
30 import java.util.Arrays JavaDoc;
31
32 public class ListLevel
33 {
34   private int _iStartAt;
35   private byte _nfc;
36   private byte _info;
37     private static BitField _jc;
38     private static BitField _fLegal;
39     private static BitField _fNoRestart;
40     private static BitField _fPrev;
41     private static BitField _fPrevSpace;
42     private static BitField _fWord6;
43   private byte[] _rgbxchNums;
44   private byte _ixchFollow;
45   private int _dxaSpace;
46   private int _dxaIndent;
47   private int _cbGrpprlChpx;
48   private int _cbGrpprlPapx;
49   private short _reserved;
50   private byte[] _grpprlPapx;
51   private byte[] _grpprlChpx;
52   private char[] _numberText=null;
53
54   public ListLevel(int startAt, int numberFormatCode, int alignment,
55                    byte[] numberProperties, byte[] entryProperties,
56                    String JavaDoc numberText)
57   {
58     _iStartAt = startAt;
59     _nfc = (byte)numberFormatCode;
60     _jc.setValue(_info, alignment);
61     _grpprlChpx = numberProperties;
62     _grpprlPapx = entryProperties;
63     _numberText = numberText.toCharArray();
64   }
65
66   public ListLevel(int level, boolean numbered)
67   {
68     _iStartAt = 1;
69     _grpprlPapx = new byte[0];
70     _grpprlChpx = new byte[0];
71     _numberText = new char[0];
72     _rgbxchNums = new byte[9];
73
74     if (numbered)
75     {
76       _rgbxchNums[0] = 1;
77       _numberText = new char[]{(char)level, '.'};
78     }
79     else
80     {
81       _numberText = new char[]{'\u2022'};
82     }
83   }
84
85   public ListLevel(byte[] buf, int offset)
86   {
87     _iStartAt = LittleEndian.getInt(buf, offset);
88     offset += LittleEndian.INT_SIZE;
89     _nfc = buf[offset++];
90     _info = buf[offset++];
91
92     _rgbxchNums = new byte[9];
93     for (int x = 0; x < 9; x++)
94     {
95       _rgbxchNums[x] = buf[offset++];
96     }
97     _ixchFollow = buf[offset++];
98     _dxaSpace = LittleEndian.getInt(buf, offset);
99     offset += LittleEndian.INT_SIZE;
100     _dxaIndent = LittleEndian.getInt(buf, offset);
101     offset += LittleEndian.INT_SIZE;
102     _cbGrpprlChpx = LittleEndian.getUnsignedByte(buf, offset++);
103     _cbGrpprlPapx = LittleEndian.getUnsignedByte(buf, offset++);
104     _reserved = LittleEndian.getShort(buf, offset);
105     offset += LittleEndian.SHORT_SIZE;
106
107     _grpprlPapx = new byte[_cbGrpprlPapx];
108     _grpprlChpx = new byte[_cbGrpprlChpx];
109     System.arraycopy(buf, offset, _grpprlPapx, 0, _cbGrpprlPapx);
110     offset += _cbGrpprlPapx;
111     System.arraycopy(buf, offset, _grpprlChpx, 0, _cbGrpprlChpx);
112     offset += _cbGrpprlChpx;
113
114     int numberTextLength = LittleEndian.getShort(buf, offset);
115     /* sometimes numberTextLength<0 */
116     /* by derjohng */
117     if (numberTextLength>0)
118     {
119         _numberText = new char[numberTextLength];
120         offset += LittleEndian.SHORT_SIZE;
121         for (int x = 0; x < numberTextLength; x++)
122         {
123           _numberText[x] = (char)LittleEndian.getShort(buf, offset);
124           offset += LittleEndian.SHORT_SIZE;
125         }
126     }
127
128   }
129
130   public int getStartAt()
131   {
132     return _iStartAt;
133   }
134
135   public int getNumberFormat()
136   {
137     return _nfc;
138   }
139
140   public int getAlignment()
141   {
142     return _jc.getValue(_info);
143   }
144
145   public String JavaDoc getNumberText()
146   {
147     return new String JavaDoc(_numberText);
148   }
149
150   public void setStartAt(int startAt)
151   {
152     _iStartAt = startAt;
153   }
154
155   public void setNumberFormat(int numberFormatCode)
156   {
157     _nfc = (byte)numberFormatCode;
158   }
159
160   public void setAlignment(int alignment)
161   {
162     _jc.setValue(_info, alignment);
163   }
164
165   public void setNumberProperties(byte[] grpprl)
166   {
167     _grpprlChpx = grpprl;
168
169   }
170
171   public void setLevelProperties(byte[] grpprl)
172   {
173     _grpprlPapx = grpprl;
174   }
175
176   public byte[] getLevelProperties()
177   {
178     return _grpprlPapx;
179   }
180
181   public boolean equals(Object JavaDoc obj)
182   {
183     if (obj == null)
184     {
185       return false;
186     }
187
188     ListLevel lvl = (ListLevel)obj;
189     return _cbGrpprlChpx == lvl._cbGrpprlChpx && lvl._cbGrpprlPapx == _cbGrpprlPapx &&
190       lvl._dxaIndent == _dxaIndent && lvl._dxaSpace == _dxaSpace &&
191       Arrays.equals(lvl._grpprlChpx, _grpprlChpx) &&
192       Arrays.equals(lvl._grpprlPapx, _grpprlPapx) &&
193       lvl._info == _info && lvl._iStartAt == _iStartAt &&
194       lvl._ixchFollow == _ixchFollow && lvl._nfc == _nfc &&
195       Arrays.equals(lvl._numberText, _numberText) &&
196       Arrays.equals(lvl._rgbxchNums, _rgbxchNums) &&
197       lvl._reserved == _reserved;
198
199
200   }
201   public byte[] toByteArray()
202   {
203     byte[] buf = new byte[getSizeInBytes()];
204     int offset = 0;
205     LittleEndian.putInt(buf, offset, _iStartAt);
206     offset += LittleEndian.INT_SIZE;
207     buf[offset++] = _nfc;
208     buf[offset++] = _info;
209     System.arraycopy(_rgbxchNums, 0, buf, offset, _rgbxchNums.length);
210     offset += _rgbxchNums.length;
211     buf[offset++] = _ixchFollow;
212     LittleEndian.putInt(buf, offset, _dxaSpace);
213     offset += LittleEndian.INT_SIZE;
214     LittleEndian.putInt(buf, offset, _dxaIndent);
215     offset += LittleEndian.INT_SIZE;
216
217     buf[offset++] = (byte)_cbGrpprlChpx;
218     buf[offset++] = (byte)_cbGrpprlPapx;
219     LittleEndian.putShort(buf, offset, _reserved);
220     offset += LittleEndian.SHORT_SIZE;
221
222     System.arraycopy(_grpprlChpx, 0, buf, offset, _cbGrpprlChpx);
223     offset += _cbGrpprlChpx;
224     System.arraycopy(_grpprlPapx, 0, buf, offset, _cbGrpprlPapx);
225     offset += _cbGrpprlPapx;
226
227     LittleEndian.putShort(buf, offset, (short)_numberText.length);
228     offset += LittleEndian.SHORT_SIZE;
229     for (int x = 0; x < _numberText.length; x++)
230     {
231       LittleEndian.putShort(buf, offset, (short)_numberText[x]);
232       offset += LittleEndian.SHORT_SIZE;
233     }
234     return buf;
235   }
236   public int getSizeInBytes()
237   {
238       if (_numberText!=null)
239       {
240             return 28 + _cbGrpprlChpx + _cbGrpprlPapx + (_numberText.length * LittleEndian.SHORT_SIZE) + 2;
241       } else {
242           return 28 + _cbGrpprlChpx + _cbGrpprlPapx + 2;
243       }
244   }
245
246 }
247
Popular Tags