KickJava   Java API By Example, From Geeks To Geeks.

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


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: Window Two Record<P>
26  * Description: sheet window settings<P>
27  * REFERENCE: PG 422 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
28  * @author Andrew C. Oliver (acoliver at apache dot org)
29  * @author Jason Height (jheight at chariot dot net dot au)
30  * @version 2.0-pre
31  */

32
33 public class WindowTwoRecord
34     extends Record
35 {
36     public final static short sid = 0x23e;
37     private short field_1_options;
38
39     // bitfields
40
private BitField displayFormulas = new BitField(0x01);
41     private BitField displayGridlines = new BitField(0x02);
42     private BitField displayRowColHeadings = new BitField(0x04);
43     private BitField freezePanes = new BitField(0x08);
44     private BitField displayZeros = new BitField(0x10);
45     private BitField defaultHeader =
46         new BitField(0x20); // if false use color in field 4
47

48     // if true use default foreground
49
// for headers
50
private BitField arabic =
51         new BitField(0x40); // for our desert dwelling friends
52
private BitField displayGuts = new BitField(0x80);
53     private BitField freezePanesNoSplit = new BitField(0x100);
54     private BitField selected = new BitField(0x200);
55     private BitField paged = new BitField(0x400);
56     private BitField savedInPageBreakPreview = new BitField(0x800);
57
58     // 4-7 reserved
59
// end bitfields
60
private short field_2_top_row;
61     private short field_3_left_col;
62     private int field_4_header_color;
63     private short field_5_page_break_zoom;
64     private short field_6_normal_zoom;
65     private int field_7_reserved;
66
67     public WindowTwoRecord()
68     {
69     }
70
71     /**
72      * Constructs a WindowTwo record and sets its fields appropriately.
73      *
74      * @param id id must be 0x23e or an exception will be throw upon validation
75      * @param size the size of the data area of the record
76      * @param data data of the record (should not contain sid/len)
77      */

78
79     public WindowTwoRecord(short id, short size, byte [] data)
80     {
81         super(id, size, data);
82     }
83
84     /**
85      * Constructs a WindowTwo record and sets its fields appropriately.
86      *
87      * @param id id must be 0x23e or an exception will be throw upon validation
88      * @param size the size of the data area of the record
89      * @param data data of the record (should not contain sid/len)
90      * @param offset of the record's data
91      */

92
93     public WindowTwoRecord(short id, short size, byte [] data, int offset)
94     {
95         super(id, size, data, offset);
96     }
97
98     protected void validateSid(short id)
99     {
100         if (id != sid)
101         {
102             throw new RecordFormatException("NOT A valid WindowTwo RECORD");
103         }
104     }
105
106     protected void fillFields(byte [] data, short size, int offset)
107     {
108         field_1_options = LittleEndian.getShort(data, 0 + offset);
109         field_2_top_row = LittleEndian.getShort(data, 2 + offset);
110         field_3_left_col = LittleEndian.getShort(data, 4 + offset);
111         field_4_header_color = LittleEndian.getInt(data, 6 + offset);
112         if (size > 10)
113         {
114             field_5_page_break_zoom = LittleEndian.getShort(data,
115                     10 + offset);
116             field_6_normal_zoom = LittleEndian.getShort(data,
117                     12 + offset);
118         }
119         if (size > 14)
120         { // there is a special case of this record that has only 14 bytes...undocumented!
121
field_7_reserved = LittleEndian.getInt(data, 14 + offset);
122         }
123     }
124
125     /**
126      * set the options bitmask or just use the bit setters.
127      * @param options
128      */

129
130     public void setOptions(short options)
131     {
132         field_1_options = options;
133     }
134
135     // option bitfields
136

137     /**
138      * set whether the window should display formulas
139      * @param formulas or not
140      */

141
142     public void setDisplayFormulas(boolean formulas)
143     {
144         field_1_options = displayFormulas.setShortBoolean(field_1_options, formulas);
145     }
146
147     /**
148      * set whether the window should display gridlines
149      * @param gridlines or not
150      */

151
152     public void setDisplayGridlines(boolean gridlines)
153     {
154         field_1_options = displayGridlines.setShortBoolean(field_1_options, gridlines);
155     }
156
157     /**
158      * set whether the window should display row and column headings
159      * @param headings or not
160      */

161
162     public void setDisplayRowColHeadings(boolean headings)
163     {
164         field_1_options = displayRowColHeadings.setShortBoolean(field_1_options, headings);
165     }
166
167     /**
168      * set whether the window should freeze panes
169      * @param freezepanes freeze panes or not
170      */

171
172     public void setFreezePanes(boolean freezepanes)
173     {
174         field_1_options = freezePanes.setShortBoolean(field_1_options, freezepanes);
175     }
176
177     /**
178      * set whether the window should display zero values
179      * @param zeros or not
180      */

181
182     public void setDisplayZeros(boolean zeros)
183     {
184         field_1_options = displayZeros.setShortBoolean(field_1_options, zeros);
185     }
186
187     /**
188      * set whether the window should display a default header
189      * @param header or not
190      */

191
192     public void setDefaultHeader(boolean header)
193     {
194         field_1_options = defaultHeader.setShortBoolean(field_1_options, header);
195     }
196
197     /**
198      * is this arabic?
199      * @param isarabic arabic or not
200      */

201
202     public void setArabic(boolean isarabic)
203     {
204         field_1_options = arabic.setShortBoolean(field_1_options, isarabic);
205     }
206
207     /**
208      * set whether the outline symbols are displaed
209      * @param guts symbols or not
210      */

211
212     public void setDisplayGuts(boolean guts)
213     {
214         field_1_options = displayGuts.setShortBoolean(field_1_options, guts);
215     }
216
217     /**
218      * freeze unsplit panes or not
219      * @param freeze or not
220      */

221
222     public void setFreezePanesNoSplit(boolean freeze)
223     {
224         field_1_options = freezePanesNoSplit.setShortBoolean(field_1_options, freeze);
225     }
226
227     /**
228      * sheet tab is selected
229      * @param sel selected or not
230      */

231
232     public void setSelected(boolean sel)
233     {
234         field_1_options = selected.setShortBoolean(field_1_options, sel);
235     }
236
237     /**
238      * is the sheet currently displayed in the window
239      * @param p displayed or not
240      */

241
242     public void setPaged(boolean p)
243     {
244         field_1_options = paged.setShortBoolean(field_1_options, p);
245     }
246
247     /**
248      * was the sheet saved in page break view
249      * @param p pagebreaksaved or not
250      */

251
252     public void setSavedInPageBreakPreview(boolean p)
253     {
254         field_1_options = savedInPageBreakPreview.setShortBoolean(field_1_options, p);
255     }
256
257     // end of bitfields.
258

259     /**
260      * set the top row visible in the window
261      * @param topRow top row visible
262      */

263
264     public void setTopRow(short topRow)
265     {
266         field_2_top_row = topRow;
267     }
268
269     /**
270      * set the leftmost column displayed in the window
271      * @param leftCol leftmost column
272      */

273
274     public void setLeftCol(short leftCol)
275     {
276         field_3_left_col = leftCol;
277     }
278
279     /**
280      * set the palette index for the header color
281      * @param color
282      */

283
284     public void setHeaderColor(int color)
285     {
286         field_4_header_color = color;
287     }
288
289     /**
290      * zoom magification in page break view
291      * @param zoom
292      */

293
294     public void setPageBreakZoom(short zoom)
295     {
296         field_5_page_break_zoom = zoom;
297     }
298
299     /**
300      * set the zoom magnification in normal view
301      * @param zoom
302      */

303
304     public void setNormalZoom(short zoom)
305     {
306         field_6_normal_zoom = zoom;
307     }
308
309     /**
310      * set the reserved (don't do this) value
311      */

312
313     public void setReserved(int reserved)
314     {
315         field_7_reserved = reserved;
316     }
317
318     /**
319      * get the options bitmask or just use the bit setters.
320      * @return options
321      */

322
323     public short getOptions()
324     {
325         return field_1_options;
326     }
327
328     // option bitfields
329

330     /**
331      * get whether the window should display formulas
332      * @return formulas or not
333      */

334
335     public boolean getDisplayFormulas()
336     {
337         return displayFormulas.isSet(field_1_options);
338     }
339
340     /**
341      * get whether the window should display gridlines
342      * @return gridlines or not
343      */

344
345     public boolean getDisplayGridlines()
346     {
347         return displayGridlines.isSet(field_1_options);
348     }
349
350     /**
351      * get whether the window should display row and column headings
352      * @return headings or not
353      */

354
355     public boolean getDisplayRowColHeadings()
356     {
357         return displayRowColHeadings.isSet(field_1_options);
358     }
359
360     /**
361      * get whether the window should freeze panes
362      * @return freeze panes or not
363      */

364
365     public boolean getFreezePanes()
366     {
367         return freezePanes.isSet(field_1_options);
368     }
369
370     /**
371      * get whether the window should display zero values
372      * @return zeros or not
373      */

374
375     public boolean getDisplayZeros()
376     {
377         return displayZeros.isSet(field_1_options);
378     }
379
380     /**
381      * get whether the window should display a default header
382      * @return header or not
383      */

384
385     public boolean getDefaultHeader()
386     {
387         return defaultHeader.isSet(field_1_options);
388     }
389
390     /**
391      * is this arabic?
392      * @return arabic or not
393      */

394
395     public boolean getArabic()
396     {
397         return arabic.isSet(field_1_options);
398     }
399
400     /**
401      * get whether the outline symbols are displaed
402      * @return symbols or not
403      */

404
405     public boolean getDisplayGuts()
406     {
407         return displayGuts.isSet(field_1_options);
408     }
409
410     /**
411      * freeze unsplit panes or not
412      * @return freeze or not
413      */

414
415     public boolean getFreezePanesNoSplit()
416     {
417         return freezePanesNoSplit.isSet(field_1_options);
418     }
419
420     /**
421      * sheet tab is selected
422      * @return selected or not
423      */

424
425     public boolean getSelected()
426     {
427         return selected.isSet(field_1_options);
428     }
429
430     /**
431      * is the sheet currently displayed in the window
432      * @return displayed or not
433      */

434
435     public boolean getPaged()
436     {
437         return paged.isSet(field_1_options);
438     }
439
440     /**
441      * was the sheet saved in page break view
442      * @return pagebreaksaved or not
443      */

444
445     public boolean getSavedInPageBreakPreview()
446     {
447         return savedInPageBreakPreview.isSet(field_1_options);
448     }
449
450     // end of bitfields.
451

452     /**
453      * get the top row visible in the window
454      * @return toprow
455      */

456
457     public short getTopRow()
458     {
459         return field_2_top_row;
460     }
461
462     /**
463      * get the leftmost column displayed in the window
464      * @return leftmost
465      */

466
467     public short getLeftCol()
468     {
469         return field_3_left_col;
470     }
471
472     /**
473      * get the palette index for the header color
474      * @return color
475      */

476
477     public int getHeaderColor()
478     {
479         return field_4_header_color;
480     }
481
482     /**
483      * zoom magification in page break view
484      * @return zoom
485      */

486
487     public short getPageBreakZoom()
488     {
489         return field_5_page_break_zoom;
490     }
491
492     /**
493      * get the zoom magnification in normal view
494      * @return zoom
495      */

496
497     public short getNormalZoom()
498     {
499         return field_6_normal_zoom;
500     }
501
502     /**
503      * get the reserved bits - why would you do this?
504      * @return reserved stuff -probably garbage
505      */

506
507     public int getReserved()
508     {
509         return field_7_reserved;
510     }
511
512     public String JavaDoc toString()
513     {
514         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
515
516         buffer.append("[WINDOW2]\n");
517         buffer.append(" .options = ")
518             .append(Integer.toHexString(getOptions())).append("\n");
519         buffer.append(" .dispformulas= ").append(getDisplayFormulas())
520             .append("\n");
521         buffer.append(" .dispgridlins= ").append(getDisplayGridlines())
522             .append("\n");
523         buffer.append(" .disprcheadin= ")
524             .append(getDisplayRowColHeadings()).append("\n");
525         buffer.append(" .freezepanes = ").append(getFreezePanes())
526             .append("\n");
527         buffer.append(" .displayzeros= ").append(getDisplayZeros())
528             .append("\n");
529         buffer.append(" .defaultheadr= ").append(getDefaultHeader())
530             .append("\n");
531         buffer.append(" .arabic = ").append(getArabic())
532             .append("\n");
533         buffer.append(" .displayguts = ").append(getDisplayGuts())
534             .append("\n");
535         buffer.append(" .frzpnsnosplt= ")
536             .append(getFreezePanesNoSplit()).append("\n");
537         buffer.append(" .selected = ").append(getSelected())
538             .append("\n");
539         buffer.append(" .paged = ").append(getPaged())
540             .append("\n");
541         buffer.append(" .svdinpgbrkpv= ")
542             .append(getSavedInPageBreakPreview()).append("\n");
543         buffer.append(" .toprow = ")
544             .append(Integer.toHexString(getTopRow())).append("\n");
545         buffer.append(" .leftcol = ")
546             .append(Integer.toHexString(getLeftCol())).append("\n");
547         buffer.append(" .headercolor = ")
548             .append(Integer.toHexString(getHeaderColor())).append("\n");
549         buffer.append(" .pagebreakzoom = ")
550             .append(Integer.toHexString(getPageBreakZoom())).append("\n");
551         buffer.append(" .normalzoom = ")
552             .append(Integer.toHexString(getNormalZoom())).append("\n");
553         buffer.append(" .reserved = ")
554             .append(Integer.toHexString(getReserved())).append("\n");
555         buffer.append("[/WINDOW2]\n");
556         return buffer.toString();
557     }
558
559     public int serialize(int offset, byte [] data)
560     {
561         LittleEndian.putShort(data, 0 + offset, sid);
562         LittleEndian.putShort(data, 2 + offset, ( short ) 18);
563         LittleEndian.putShort(data, 4 + offset, getOptions());
564         LittleEndian.putShort(data, 6 + offset, getTopRow());
565         LittleEndian.putShort(data, 8 + offset, getLeftCol());
566         LittleEndian.putInt(data, 10 + offset, getHeaderColor());
567         LittleEndian.putShort(data, 14 + offset, getPageBreakZoom());
568         LittleEndian.putShort(data, 16 + offset, getNormalZoom());
569         LittleEndian.putInt(data, 18 + offset, getReserved());
570         return getRecordSize();
571     }
572
573     public int getRecordSize()
574     {
575         return 22;
576     }
577
578     public short getSid()
579     {
580         return this.sid;
581     }
582
583     public Object JavaDoc clone() {
584       WindowTwoRecord rec = new WindowTwoRecord();
585       rec.field_1_options = field_1_options;
586       rec.field_2_top_row = field_2_top_row;
587       rec.field_3_left_col = field_3_left_col;
588       rec.field_4_header_color = field_4_header_color;
589       rec.field_5_page_break_zoom = field_5_page_break_zoom;
590       rec.field_6_normal_zoom = field_6_normal_zoom;
591       rec.field_7_reserved = field_7_reserved;
592       return rec;
593     }
594 }
595
Popular Tags