001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.record;
019:
020: import org.apache.poi.util.BitField;
021: import org.apache.poi.util.BitFieldFactory;
022: import org.apache.poi.util.LittleEndian;
023:
024: /**
025: * Title: Window Two Record<P>
026: * Description: sheet window settings<P>
027: * REFERENCE: PG 422 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
028: * @author Andrew C. Oliver (acoliver at apache dot org)
029: * @author Jason Height (jheight at chariot dot net dot au)
030: * @version 2.0-pre
031: */
032:
033: public class WindowTwoRecord extends Record {
034: public final static short sid = 0x23e;
035: private short field_1_options;
036:
037: // bitfields
038: private BitField displayFormulas = BitFieldFactory
039: .getInstance(0x01);
040: private BitField displayGridlines = BitFieldFactory
041: .getInstance(0x02);
042: private BitField displayRowColHeadings = BitFieldFactory
043: .getInstance(0x04);
044: private BitField freezePanes = BitFieldFactory.getInstance(0x08);
045: private BitField displayZeros = BitFieldFactory.getInstance(0x10);
046: private BitField defaultHeader = BitFieldFactory.getInstance(0x20); // if false use color in field 4
047:
048: // if true use default foreground
049: // for headers
050: private BitField arabic = BitFieldFactory.getInstance(0x40); // for our desert dwelling friends
051: private BitField displayGuts = BitFieldFactory.getInstance(0x80);
052: private BitField freezePanesNoSplit = BitFieldFactory
053: .getInstance(0x100);
054: private BitField selected = BitFieldFactory.getInstance(0x200);
055: private BitField paged = BitFieldFactory.getInstance(0x400);
056: private BitField savedInPageBreakPreview = BitFieldFactory
057: .getInstance(0x800);
058:
059: // 4-7 reserved
060: // end bitfields
061: private short field_2_top_row;
062: private short field_3_left_col;
063: private int field_4_header_color;
064: private short field_5_page_break_zoom;
065: private short field_6_normal_zoom;
066: private int field_7_reserved;
067:
068: public WindowTwoRecord() {
069: }
070:
071: /**
072: * Constructs a WindowTwo record and sets its fields appropriately.
073: * @param in the RecordInputstream to read the record from
074: */
075:
076: public WindowTwoRecord(RecordInputStream in) {
077: super (in);
078: }
079:
080: protected void validateSid(short id) {
081: if (id != sid) {
082: throw new RecordFormatException(
083: "NOT A valid WindowTwo RECORD");
084: }
085: }
086:
087: protected void fillFields(RecordInputStream in) {
088: int size = in.remaining();
089: field_1_options = in.readShort();
090: field_2_top_row = in.readShort();
091: field_3_left_col = in.readShort();
092: field_4_header_color = in.readInt();
093: if (size > 10) {
094: field_5_page_break_zoom = in.readShort();
095: field_6_normal_zoom = in.readShort();
096: }
097: if (size > 14) { // there is a special case of this record that has only 14 bytes...undocumented!
098: field_7_reserved = in.readInt();
099: }
100: }
101:
102: /**
103: * set the options bitmask or just use the bit setters.
104: * @param options
105: */
106:
107: public void setOptions(short options) {
108: field_1_options = options;
109: }
110:
111: // option bitfields
112:
113: /**
114: * set whether the window should display formulas
115: * @param formulas or not
116: */
117:
118: public void setDisplayFormulas(boolean formulas) {
119: field_1_options = displayFormulas.setShortBoolean(
120: field_1_options, formulas);
121: }
122:
123: /**
124: * set whether the window should display gridlines
125: * @param gridlines or not
126: */
127:
128: public void setDisplayGridlines(boolean gridlines) {
129: field_1_options = displayGridlines.setShortBoolean(
130: field_1_options, gridlines);
131: }
132:
133: /**
134: * set whether the window should display row and column headings
135: * @param headings or not
136: */
137:
138: public void setDisplayRowColHeadings(boolean headings) {
139: field_1_options = displayRowColHeadings.setShortBoolean(
140: field_1_options, headings);
141: }
142:
143: /**
144: * set whether the window should freeze panes
145: * @param freezepanes freeze panes or not
146: */
147:
148: public void setFreezePanes(boolean freezepanes) {
149: field_1_options = freezePanes.setShortBoolean(field_1_options,
150: freezepanes);
151: }
152:
153: /**
154: * set whether the window should display zero values
155: * @param zeros or not
156: */
157:
158: public void setDisplayZeros(boolean zeros) {
159: field_1_options = displayZeros.setShortBoolean(field_1_options,
160: zeros);
161: }
162:
163: /**
164: * set whether the window should display a default header
165: * @param header or not
166: */
167:
168: public void setDefaultHeader(boolean header) {
169: field_1_options = defaultHeader.setShortBoolean(
170: field_1_options, header);
171: }
172:
173: /**
174: * is this arabic?
175: * @param isarabic arabic or not
176: */
177:
178: public void setArabic(boolean isarabic) {
179: field_1_options = arabic.setShortBoolean(field_1_options,
180: isarabic);
181: }
182:
183: /**
184: * set whether the outline symbols are displaed
185: * @param guts symbols or not
186: */
187:
188: public void setDisplayGuts(boolean guts) {
189: field_1_options = displayGuts.setShortBoolean(field_1_options,
190: guts);
191: }
192:
193: /**
194: * freeze unsplit panes or not
195: * @param freeze or not
196: */
197:
198: public void setFreezePanesNoSplit(boolean freeze) {
199: field_1_options = freezePanesNoSplit.setShortBoolean(
200: field_1_options, freeze);
201: }
202:
203: /**
204: * sheet tab is selected
205: * @param sel selected or not
206: */
207:
208: public void setSelected(boolean sel) {
209: field_1_options = selected
210: .setShortBoolean(field_1_options, sel);
211: }
212:
213: /**
214: * is the sheet currently displayed in the window
215: * @param p displayed or not
216: */
217:
218: public void setPaged(boolean p) {
219: field_1_options = paged.setShortBoolean(field_1_options, p);
220: }
221:
222: /**
223: * was the sheet saved in page break view
224: * @param p pagebreaksaved or not
225: */
226:
227: public void setSavedInPageBreakPreview(boolean p) {
228: field_1_options = savedInPageBreakPreview.setShortBoolean(
229: field_1_options, p);
230: }
231:
232: // end of bitfields.
233:
234: /**
235: * set the top row visible in the window
236: * @param topRow top row visible
237: */
238:
239: public void setTopRow(short topRow) {
240: field_2_top_row = topRow;
241: }
242:
243: /**
244: * set the leftmost column displayed in the window
245: * @param leftCol leftmost column
246: */
247:
248: public void setLeftCol(short leftCol) {
249: field_3_left_col = leftCol;
250: }
251:
252: /**
253: * set the palette index for the header color
254: * @param color
255: */
256:
257: public void setHeaderColor(int color) {
258: field_4_header_color = color;
259: }
260:
261: /**
262: * zoom magification in page break view
263: * @param zoom
264: */
265:
266: public void setPageBreakZoom(short zoom) {
267: field_5_page_break_zoom = zoom;
268: }
269:
270: /**
271: * set the zoom magnification in normal view
272: * @param zoom
273: */
274:
275: public void setNormalZoom(short zoom) {
276: field_6_normal_zoom = zoom;
277: }
278:
279: /**
280: * set the reserved (don't do this) value
281: */
282:
283: public void setReserved(int reserved) {
284: field_7_reserved = reserved;
285: }
286:
287: /**
288: * get the options bitmask or just use the bit setters.
289: * @return options
290: */
291:
292: public short getOptions() {
293: return field_1_options;
294: }
295:
296: // option bitfields
297:
298: /**
299: * get whether the window should display formulas
300: * @return formulas or not
301: */
302:
303: public boolean getDisplayFormulas() {
304: return displayFormulas.isSet(field_1_options);
305: }
306:
307: /**
308: * get whether the window should display gridlines
309: * @return gridlines or not
310: */
311:
312: public boolean getDisplayGridlines() {
313: return displayGridlines.isSet(field_1_options);
314: }
315:
316: /**
317: * get whether the window should display row and column headings
318: * @return headings or not
319: */
320:
321: public boolean getDisplayRowColHeadings() {
322: return displayRowColHeadings.isSet(field_1_options);
323: }
324:
325: /**
326: * get whether the window should freeze panes
327: * @return freeze panes or not
328: */
329:
330: public boolean getFreezePanes() {
331: return freezePanes.isSet(field_1_options);
332: }
333:
334: /**
335: * get whether the window should display zero values
336: * @return zeros or not
337: */
338:
339: public boolean getDisplayZeros() {
340: return displayZeros.isSet(field_1_options);
341: }
342:
343: /**
344: * get whether the window should display a default header
345: * @return header or not
346: */
347:
348: public boolean getDefaultHeader() {
349: return defaultHeader.isSet(field_1_options);
350: }
351:
352: /**
353: * is this arabic?
354: * @return arabic or not
355: */
356:
357: public boolean getArabic() {
358: return arabic.isSet(field_1_options);
359: }
360:
361: /**
362: * get whether the outline symbols are displaed
363: * @return symbols or not
364: */
365:
366: public boolean getDisplayGuts() {
367: return displayGuts.isSet(field_1_options);
368: }
369:
370: /**
371: * freeze unsplit panes or not
372: * @return freeze or not
373: */
374:
375: public boolean getFreezePanesNoSplit() {
376: return freezePanesNoSplit.isSet(field_1_options);
377: }
378:
379: /**
380: * sheet tab is selected
381: * @return selected or not
382: */
383:
384: public boolean getSelected() {
385: return selected.isSet(field_1_options);
386: }
387:
388: /**
389: * is the sheet currently displayed in the window
390: * @return displayed or not
391: */
392:
393: public boolean getPaged() {
394: return paged.isSet(field_1_options);
395: }
396:
397: /**
398: * was the sheet saved in page break view
399: * @return pagebreaksaved or not
400: */
401:
402: public boolean getSavedInPageBreakPreview() {
403: return savedInPageBreakPreview.isSet(field_1_options);
404: }
405:
406: // end of bitfields.
407:
408: /**
409: * get the top row visible in the window
410: * @return toprow
411: */
412:
413: public short getTopRow() {
414: return field_2_top_row;
415: }
416:
417: /**
418: * get the leftmost column displayed in the window
419: * @return leftmost
420: */
421:
422: public short getLeftCol() {
423: return field_3_left_col;
424: }
425:
426: /**
427: * get the palette index for the header color
428: * @return color
429: */
430:
431: public int getHeaderColor() {
432: return field_4_header_color;
433: }
434:
435: /**
436: * zoom magification in page break view
437: * @return zoom
438: */
439:
440: public short getPageBreakZoom() {
441: return field_5_page_break_zoom;
442: }
443:
444: /**
445: * get the zoom magnification in normal view
446: * @return zoom
447: */
448:
449: public short getNormalZoom() {
450: return field_6_normal_zoom;
451: }
452:
453: /**
454: * get the reserved bits - why would you do this?
455: * @return reserved stuff -probably garbage
456: */
457:
458: public int getReserved() {
459: return field_7_reserved;
460: }
461:
462: public String toString() {
463: StringBuffer buffer = new StringBuffer();
464:
465: buffer.append("[WINDOW2]\n");
466: buffer.append(" .options = ").append(
467: Integer.toHexString(getOptions())).append("\n");
468: buffer.append(" .dispformulas= ").append(
469: getDisplayFormulas()).append("\n");
470: buffer.append(" .dispgridlins= ").append(
471: getDisplayGridlines()).append("\n");
472: buffer.append(" .disprcheadin= ").append(
473: getDisplayRowColHeadings()).append("\n");
474: buffer.append(" .freezepanes = ")
475: .append(getFreezePanes()).append("\n");
476: buffer.append(" .displayzeros= ").append(
477: getDisplayZeros()).append("\n");
478: buffer.append(" .defaultheadr= ").append(
479: getDefaultHeader()).append("\n");
480: buffer.append(" .arabic = ").append(getArabic())
481: .append("\n");
482: buffer.append(" .displayguts = ")
483: .append(getDisplayGuts()).append("\n");
484: buffer.append(" .frzpnsnosplt= ").append(
485: getFreezePanesNoSplit()).append("\n");
486: buffer.append(" .selected = ").append(getSelected())
487: .append("\n");
488: buffer.append(" .paged = ").append(getPaged())
489: .append("\n");
490: buffer.append(" .svdinpgbrkpv= ").append(
491: getSavedInPageBreakPreview()).append("\n");
492: buffer.append(" .toprow = ").append(
493: Integer.toHexString(getTopRow())).append("\n");
494: buffer.append(" .leftcol = ").append(
495: Integer.toHexString(getLeftCol())).append("\n");
496: buffer.append(" .headercolor = ").append(
497: Integer.toHexString(getHeaderColor())).append("\n");
498: buffer.append(" .pagebreakzoom = ").append(
499: Integer.toHexString(getPageBreakZoom())).append("\n");
500: buffer.append(" .normalzoom = ").append(
501: Integer.toHexString(getNormalZoom())).append("\n");
502: buffer.append(" .reserved = ").append(
503: Integer.toHexString(getReserved())).append("\n");
504: buffer.append("[/WINDOW2]\n");
505: return buffer.toString();
506: }
507:
508: public int serialize(int offset, byte[] data) {
509: LittleEndian.putShort(data, 0 + offset, sid);
510: LittleEndian.putShort(data, 2 + offset, (short) 18);
511: LittleEndian.putShort(data, 4 + offset, getOptions());
512: LittleEndian.putShort(data, 6 + offset, getTopRow());
513: LittleEndian.putShort(data, 8 + offset, getLeftCol());
514: LittleEndian.putInt(data, 10 + offset, getHeaderColor());
515: LittleEndian.putShort(data, 14 + offset, getPageBreakZoom());
516: LittleEndian.putShort(data, 16 + offset, getNormalZoom());
517: LittleEndian.putInt(data, 18 + offset, getReserved());
518: return getRecordSize();
519: }
520:
521: public int getRecordSize() {
522: return 22;
523: }
524:
525: public short getSid() {
526: return sid;
527: }
528:
529: public Object clone() {
530: WindowTwoRecord rec = new WindowTwoRecord();
531: rec.field_1_options = field_1_options;
532: rec.field_2_top_row = field_2_top_row;
533: rec.field_3_left_col = field_3_left_col;
534: rec.field_4_header_color = field_4_header_color;
535: rec.field_5_page_break_zoom = field_5_page_break_zoom;
536: rec.field_6_normal_zoom = field_6_normal_zoom;
537: rec.field_7_reserved = field_7_reserved;
538: return rec;
539: }
540: }
|