KickJava   Java API By Example, From Geeks To Geeks.

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


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.BitField;
22 import org.apache.poi.util.LittleEndian;
23
24 /**
25  * Title: Window1 Record<P>
26  * Description: Stores the attributes of the workbook window. This is basically
27  * so the gui knows how big to make the window holding the spreadsheet
28  * document.<P>
29  * REFERENCE: PG 421 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
30  * @author Andrew C. Oliver (acoliver at apache dot org)
31  * @version 2.0-pre
32  */

33
34 public class WindowOneRecord
35     extends Record
36 {
37     public final static short sid = 0x3d;
38
39     // our variable names stolen from old TV sets.
40
private short field_1_h_hold; // horizontal position
41
private short field_2_v_hold; // vertical position
42
private short field_3_width;
43     private short field_4_height;
44     private short field_5_options;
45     static final private BitField hidden =
46         new BitField(0x01); // is this window is hidden
47
static final private BitField iconic =
48         new BitField(0x02); // is this window is an icon
49
static final private BitField reserved = new BitField(0x04); // reserved
50
static final private BitField hscroll =
51         new BitField(0x08); // display horizontal scrollbar
52
static final private BitField vscroll =
53         new BitField(0x10); // display vertical scrollbar
54
static final private BitField tabs =
55         new BitField(0x20); // display tabs at the bottom
56

57     // all the rest are "reserved"
58
private short field_6_selected_tab;
59     private short field_7_displayed_tab;
60     private short field_8_num_selected_tabs;
61     private short field_9_tab_width_ratio;
62
63     public WindowOneRecord()
64     {
65     }
66
67     /**
68      * Constructs a WindowOne record and sets its fields appropriately.
69      *
70      * @param id id must be 0x3d or an exception will be throw upon validation
71      * @param size the size of the data area of the record
72      * @param data data of the record (should not contain sid/len)
73      */

74
75     public WindowOneRecord(short id, short size, byte [] data)
76     {
77         super(id, size, data);
78     }
79
80     /**
81      * Constructs a WindowOne record and sets its fields appropriately.
82      *
83      * @param id id must be 0x3d or an exception will be throw upon validation
84      * @param size the size of the data area of the record
85      * @param data data of the record (should not contain sid/len)
86      */

87
88     public WindowOneRecord(short id, short size, byte [] data, int offset)
89     {
90         super(id, size, data, offset);
91     }
92
93     protected void validateSid(short id)
94     {
95         if (id != sid)
96         {
97             throw new RecordFormatException("NOT A WINDOW1 RECORD");
98         }
99     }
100
101     protected void fillFields(byte [] data, short size, int offset)
102     {
103         field_1_h_hold = LittleEndian.getShort(data, 0 + offset);
104         field_2_v_hold = LittleEndian.getShort(data, 2 + offset);
105         field_3_width = LittleEndian.getShort(data, 4 + offset);
106         field_4_height = LittleEndian.getShort(data, 6 + offset);
107         field_5_options = LittleEndian.getShort(data, 8 + offset);
108         field_6_selected_tab = LittleEndian.getShort(data, 10 + offset);
109         field_7_displayed_tab = LittleEndian.getShort(data, 12 + offset);
110         field_8_num_selected_tabs = LittleEndian.getShort(data, 14 + offset);
111         field_9_tab_width_ratio = LittleEndian.getShort(data, 16 + offset);
112     }
113
114     /**
115      * set the horizontal position of the window (in 1/20ths of a point)
116      * @param h - horizontal location
117      */

118
119     public void setHorizontalHold(short h)
120     {
121         field_1_h_hold = h;
122     }
123
124     /**
125      * set the vertical position of the window (in 1/20ths of a point)
126      * @param v - vertical location
127      */

128
129     public void setVerticalHold(short v)
130     {
131         field_2_v_hold = v;
132     }
133
134     /**
135      * set the width of the window
136      * @param w width
137      */

138
139     public void setWidth(short w)
140     {
141         field_3_width = w;
142     }
143
144     /**
145      * set teh height of the window
146      * @param h height
147      */

148
149     public void setHeight(short h)
150     {
151         field_4_height = h;
152     }
153
154     /**
155      * set the options bitmask (see bit setters)
156      *
157      * @param o - the bitmask
158      */

159
160     public void setOptions(short o)
161     {
162         field_5_options = o;
163     }
164
165     // bitfields for options
166

167     /**
168      * set whether the window is hidden or not
169      * @param ishidden or not
170      */

171
172     public void setHidden(boolean ishidden)
173     {
174         field_5_options = hidden.setShortBoolean(field_5_options, ishidden);
175     }
176
177     /**
178      * set whether the window has been iconized or not
179      * @param isiconic iconize or not
180      */

181
182     public void setIconic(boolean isiconic)
183     {
184         field_5_options = iconic.setShortBoolean(field_5_options, isiconic);
185     }
186
187     /**
188      * set whether to display the horizontal scrollbar or not
189      * @param scroll display or not
190      */

191
192     public void setDisplayHorizonalScrollbar(boolean scroll)
193     {
194         field_5_options = hscroll.setShortBoolean(field_5_options, scroll);
195     }
196
197     /**
198      * set whether to display the vertical scrollbar or not
199      * @param scroll display or not
200      */

201
202     public void setDisplayVerticalScrollbar(boolean scroll)
203     {
204         field_5_options = vscroll.setShortBoolean(field_5_options, scroll);
205     }
206
207     /**
208      * set whether to display the tabs or not
209      * @param disptabs display or not
210      */

211
212     public void setDisplayTabs(boolean disptabs)
213     {
214         field_5_options = tabs.setShortBoolean(field_5_options, disptabs);
215     }
216
217     // end bitfields
218

219     /**
220      * set the selected tab number
221      * @param s tab number
222      */

223
224     public void setSelectedTab(short s)
225     {
226         field_6_selected_tab = s;
227     }
228
229     /**
230      * set the displayed tab number
231      * @param t tab number
232      */

233
234     public void setDisplayedTab(short t)
235     {
236         field_7_displayed_tab = t;
237     }
238
239     /**
240      * set the number of selected tabs
241      * @param n number of tabs
242      */

243
244     public void setNumSelectedTabs(short n)
245     {
246         field_8_num_selected_tabs = n;
247     }
248
249     /**
250      * ratio of the width of the tabs to the horizontal scrollbar
251      * @param r ratio
252      */

253
254     public void setTabWidthRatio(short r)
255     {
256         field_9_tab_width_ratio = r;
257     }
258
259     /**
260      * get the horizontal position of the window (in 1/20ths of a point)
261      * @return h - horizontal location
262      */

263
264     public short getHorizontalHold()
265     {
266         return field_1_h_hold;
267     }
268
269     /**
270      * get the vertical position of the window (in 1/20ths of a point)
271      * @return v - vertical location
272      */

273
274     public short getVerticalHold()
275     {
276         return field_2_v_hold;
277     }
278
279     /**
280      * get the width of the window
281      * @return width
282      */

283
284     public short getWidth()
285     {
286         return field_3_width;
287     }
288
289     /**
290      * get the height of the window
291      * @return height
292      */

293
294     public short getHeight()
295     {
296         return field_4_height;
297     }
298
299     /**
300      * get the options bitmask (see bit setters)
301      *
302      * @return o - the bitmask
303      */

304
305     public short getOptions()
306     {
307         return field_5_options;
308     }
309
310     // bitfields for options
311

312     /**
313      * get whether the window is hidden or not
314      * @return ishidden or not
315      */

316
317     public boolean getHidden()
318     {
319         return hidden.isSet(field_5_options);
320     }
321
322     /**
323      * get whether the window has been iconized or not
324      * @return iconize or not
325      */

326
327     public boolean getIconic()
328     {
329         return iconic.isSet(field_5_options);
330     }
331
332     /**
333      * get whether to display the horizontal scrollbar or not
334      * @return display or not
335      */

336
337     public boolean getDisplayHorizontalScrollbar()
338     {
339         return hscroll.isSet(field_5_options);
340     }
341
342     /**
343      * get whether to display the vertical scrollbar or not
344      * @return display or not
345      */

346
347     public boolean getDisplayVerticalScrollbar()
348     {
349         return vscroll.isSet(field_5_options);
350     }
351
352     /**
353      * get whether to display the tabs or not
354      * @return display or not
355      */

356
357     public boolean getDisplayTabs()
358     {
359         return tabs.isSet(field_5_options);
360     }
361
362     // end options bitfields
363

364     /**
365      * get the selected tab number
366      * @return Tab number
367      */

368
369     public short getSelectedTab()
370     {
371         return field_6_selected_tab;
372     }
373
374     /**
375      * get the displayed tab number
376      * @return Tab number
377      */

378
379     public short getDisplayedTab()
380     {
381         return field_7_displayed_tab;
382     }
383
384     /**
385      * get the number of selected tabs
386      * @return number of tabs
387      */

388
389     public short getNumSelectedTabs()
390     {
391         return field_8_num_selected_tabs;
392     }
393
394     /**
395      * ratio of the width of the tabs to the horizontal scrollbar
396      * @return ratio
397      */

398
399     public short getTabWidthRatio()
400     {
401         return field_9_tab_width_ratio;
402     }
403
404     public String JavaDoc toString()
405     {
406         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
407
408         buffer.append("[WINDOW1]\n");
409         buffer.append(" .h_hold = ")
410             .append(Integer.toHexString(getHorizontalHold())).append("\n");
411         buffer.append(" .v_hold = ")
412             .append(Integer.toHexString(getVerticalHold())).append("\n");
413         buffer.append(" .width = ")
414             .append(Integer.toHexString(getWidth())).append("\n");
415         buffer.append(" .height = ")
416             .append(Integer.toHexString(getHeight())).append("\n");
417         buffer.append(" .options = ")
418             .append(Integer.toHexString(getOptions())).append("\n");
419         buffer.append(" .hidden = ").append(getHidden())
420             .append("\n");
421         buffer.append(" .iconic = ").append(getIconic())
422             .append("\n");
423         buffer.append(" .hscroll = ")
424             .append(getDisplayHorizontalScrollbar()).append("\n");
425         buffer.append(" .vscroll = ")
426             .append(getDisplayVerticalScrollbar()).append("\n");
427         buffer.append(" .tabs = ").append(getDisplayTabs())
428             .append("\n");
429         buffer.append(" .selectedtab = ")
430             .append(Integer.toHexString(getSelectedTab())).append("\n");
431         buffer.append(" .displayedtab = ")
432             .append(Integer.toHexString(getDisplayedTab())).append("\n");
433         buffer.append(" .numselectedtabs = ")
434             .append(Integer.toHexString(getNumSelectedTabs())).append("\n");
435         buffer.append(" .tabwidthratio = ")
436             .append(Integer.toHexString(getTabWidthRatio())).append("\n");
437         buffer.append("[/WINDOW1]\n");
438         return buffer.toString();
439     }
440
441     public int serialize(int offset, byte [] data)
442     {
443         LittleEndian.putShort(data, 0 + offset, sid);
444         LittleEndian.putShort(data, 2 + offset,
445                               (( short ) 0x12)); // 18 bytes (22 total)
446
LittleEndian.putShort(data, 4 + offset, getHorizontalHold());
447         LittleEndian.putShort(data, 6 + offset, getVerticalHold());
448         LittleEndian.putShort(data, 8 + offset, getWidth());
449         LittleEndian.putShort(data, 10 + offset, getHeight());
450         LittleEndian.putShort(data, 12 + offset, getOptions());
451         LittleEndian.putShort(data, 14 + offset, getSelectedTab());
452         LittleEndian.putShort(data, 16 + offset, getDisplayedTab());
453         LittleEndian.putShort(data, 18 + offset, getNumSelectedTabs());
454         LittleEndian.putShort(data, 20 + offset, getTabWidthRatio());
455         return getRecordSize();
456     }
457
458     public int getRecordSize()
459     {
460         return 22;
461     }
462
463     public short getSid()
464     {
465         return this.sid;
466     }
467 }
468
Popular Tags