KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.poi.util.BitField;
23
24 /**
25  * Title: Print Setup Record<P>
26  * Description: Stores print setup options -- bogus for HSSF (and marked as such)<P>
27  * REFERENCE: PG 385 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 PrintSetupRecord
34     extends Record
35 {
36     public final static short sid = 0xa1;
37     private short field_1_paper_size;
38     private short field_2_scale;
39     private short field_3_page_start;
40     private short field_4_fit_width;
41     private short field_5_fit_height;
42     private short field_6_options;
43     static final private BitField lefttoright =
44         new BitField(0x01); // print over then down
45
static final private BitField landscape =
46         new BitField(0x02); // landscape mode
47
static final private BitField validsettings = new BitField(
48         0x04); // if papersize, scale, resolution, copies, landscape
49

50     // weren't obtained from the print consider them
51
// mere bunk
52
static final private BitField nocolor =
53         new BitField(0x08); // print mono/b&w, colorless
54
static final private BitField draft =
55         new BitField(0x10); // print draft quality
56
static final private BitField notes =
57         new BitField(0x20); // print the notes
58
static final private BitField noOrientation =
59         new BitField(0x40); // the orientation is not set
60
static final private BitField usepage =
61         new BitField(0x80); // use a user set page no, instead of auto
62
private short field_7_hresolution;
63     private short field_8_vresolution;
64     private double field_9_headermargin;
65     private double field_10_footermargin;
66     private short field_11_copies;
67
68     public PrintSetupRecord()
69     {
70     }
71
72     /**
73      * Constructs a PrintSetup (SETUP) record and sets its fields appropriately.
74      *
75      * @param id id must be 0xa1 or an exception will be throw upon validation
76      * @param size the size of the data area of the record
77      * @param data data of the record (should not contain sid/len)
78      */

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

92
93     public PrintSetupRecord(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(
103                 "NOT A valid PrintSetup record RECORD");
104         }
105     }
106
107     protected void fillFields(byte [] data, short size, int offset)
108     {
109         field_1_paper_size = LittleEndian.getShort(data, 0 + offset);
110         field_2_scale = LittleEndian.getShort(data, 2 + offset);
111         field_3_page_start = LittleEndian.getShort(data, 4 + offset);
112         field_4_fit_width = LittleEndian.getShort(data, 6 + offset);
113         field_5_fit_height = LittleEndian.getShort(data, 8 + offset);
114         field_6_options = LittleEndian.getShort(data, 10 + offset);
115         field_7_hresolution = LittleEndian.getShort(data, 12 + offset);
116         field_8_vresolution = LittleEndian.getShort(data, 14 + offset);
117         field_9_headermargin = LittleEndian.getDouble(data, 16 + offset);
118         field_10_footermargin = LittleEndian.getDouble(data, 24 + offset);
119         field_11_copies = LittleEndian.getShort(data, 32 + offset);
120     }
121
122     public void setPaperSize(short size)
123     {
124         field_1_paper_size = size;
125     }
126
127     public void setScale(short scale)
128     {
129         field_2_scale = scale;
130     }
131
132     public void setPageStart(short start)
133     {
134         field_3_page_start = start;
135     }
136
137     public void setFitWidth(short width)
138     {
139         field_4_fit_width = width;
140     }
141
142     public void setFitHeight(short height)
143     {
144         field_5_fit_height = height;
145     }
146
147     public void setOptions(short options)
148     {
149         field_6_options = options;
150     }
151
152     // option bitfields
153
public void setLeftToRight(boolean ltor)
154     {
155         field_6_options = lefttoright.setShortBoolean(field_6_options, ltor);
156     }
157
158     public void setLandscape(boolean ls)
159     {
160         field_6_options = landscape.setShortBoolean(field_6_options, ls);
161     }
162
163     public void setValidSettings(boolean valid)
164     {
165         field_6_options = validsettings.setShortBoolean(field_6_options, valid);
166     }
167
168     public void setNoColor(boolean mono)
169     {
170         field_6_options = nocolor.setShortBoolean(field_6_options, mono);
171     }
172
173     public void setDraft(boolean d)
174     {
175         field_6_options = draft.setShortBoolean(field_6_options, d);
176     }
177
178     public void setNotes(boolean printnotes)
179     {
180         field_6_options = notes.setShortBoolean(field_6_options, printnotes);
181     }
182
183     public void setNoOrientation(boolean orientation)
184     {
185         field_6_options = noOrientation.setShortBoolean(field_6_options, orientation);
186     }
187
188     public void setUsePage(boolean page)
189     {
190         field_6_options = usepage.setShortBoolean(field_6_options, page);
191     }
192
193     // end option bitfields
194
public void setHResolution(short resolution)
195     {
196         field_7_hresolution = resolution;
197     }
198
199     public void setVResolution(short resolution)
200     {
201         field_8_vresolution = resolution;
202     }
203
204     public void setHeaderMargin(double headermargin)
205     {
206         field_9_headermargin = headermargin;
207     }
208
209     public void setFooterMargin(double footermargin)
210     {
211         field_10_footermargin = footermargin;
212     }
213
214     public void setCopies(short copies)
215     {
216         field_11_copies = copies;
217     }
218
219     public short getPaperSize()
220     {
221         return field_1_paper_size;
222     }
223
224     public short getScale()
225     {
226         return field_2_scale;
227     }
228
229     public short getPageStart()
230     {
231         return field_3_page_start;
232     }
233
234     public short getFitWidth()
235     {
236         return field_4_fit_width;
237     }
238
239     public short getFitHeight()
240     {
241         return field_5_fit_height;
242     }
243
244     public short getOptions()
245     {
246         return field_6_options;
247     }
248
249     // option bitfields
250
public boolean getLeftToRight()
251     {
252         return lefttoright.isSet(field_6_options);
253     }
254
255     public boolean getLandscape()
256     {
257         return landscape.isSet(field_6_options);
258     }
259
260     public boolean getValidSettings()
261     {
262         return validsettings.isSet(field_6_options);
263     }
264
265     public boolean getNoColor()
266     {
267         return nocolor.isSet(field_6_options);
268     }
269
270     public boolean getDraft()
271     {
272         return draft.isSet(field_6_options);
273     }
274
275     public boolean getNotes()
276     {
277         return notes.isSet(field_6_options);
278     }
279
280     public boolean getNoOrientation()
281     {
282         return noOrientation.isSet(field_6_options);
283     }
284
285     public boolean getUsePage()
286     {
287         return usepage.isSet(field_6_options);
288     }
289
290     // end option bitfields
291
public short getHResolution()
292     {
293         return field_7_hresolution;
294     }
295
296     public short getVResolution()
297     {
298         return field_8_vresolution;
299     }
300
301     public double getHeaderMargin()
302     {
303         return field_9_headermargin;
304     }
305
306     public double getFooterMargin()
307     {
308         return field_10_footermargin;
309     }
310
311     public short getCopies()
312     {
313         return field_11_copies;
314     }
315
316     public String JavaDoc toString()
317     {
318         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
319
320         buffer.append("[PRINTSETUP]\n");
321         buffer.append(" .papersize = ").append(getPaperSize())
322             .append("\n");
323         buffer.append(" .scale = ").append(getScale())
324             .append("\n");
325         buffer.append(" .pagestart = ").append(getPageStart())
326             .append("\n");
327         buffer.append(" .fitwidth = ").append(getFitWidth())
328             .append("\n");
329         buffer.append(" .fitheight = ").append(getFitHeight())
330             .append("\n");
331         buffer.append(" .options = ").append(getOptions())
332             .append("\n");
333         buffer.append(" .ltor = ").append(getLeftToRight())
334             .append("\n");
335         buffer.append(" .landscape = ").append(getLandscape())
336             .append("\n");
337         buffer.append(" .valid = ").append(getValidSettings())
338             .append("\n");
339         buffer.append(" .mono = ").append(getNoColor())
340             .append("\n");
341         buffer.append(" .draft = ").append(getDraft())
342             .append("\n");
343         buffer.append(" .notes = ").append(getNotes())
344             .append("\n");
345         buffer.append(" .noOrientat = ").append(getNoOrientation())
346             .append("\n");
347         buffer.append(" .usepage = ").append(getUsePage())
348             .append("\n");
349         buffer.append(" .hresolution = ").append(getHResolution())
350             .append("\n");
351         buffer.append(" .vresolution = ").append(getVResolution())
352             .append("\n");
353         buffer.append(" .headermargin = ").append(getHeaderMargin())
354             .append("\n");
355         buffer.append(" .footermargin = ").append(getFooterMargin())
356             .append("\n");
357         buffer.append(" .copies = ").append(getCopies())
358             .append("\n");
359         buffer.append("[/PRINTSETUP]\n");
360         return buffer.toString();
361     }
362
363     public int serialize(int offset, byte [] data)
364     {
365         LittleEndian.putShort(data, 0 + offset, sid);
366         LittleEndian.putShort(data, 2 + offset, ( short ) 34);
367         LittleEndian.putShort(data, 4 + offset, getPaperSize());
368         LittleEndian.putShort(data, 6 + offset, getScale());
369         LittleEndian.putShort(data, 8 + offset, getPageStart());
370         LittleEndian.putShort(data, 10 + offset, getFitWidth());
371         LittleEndian.putShort(data, 12 + offset, getFitHeight());
372         LittleEndian.putShort(data, 14 + offset, getOptions());
373         LittleEndian.putShort(data, 16 + offset, getHResolution());
374         LittleEndian.putShort(data, 18 + offset, getVResolution());
375         LittleEndian.putDouble(data, 20 + offset, getHeaderMargin());
376         LittleEndian.putDouble(data, 28 + offset, getFooterMargin());
377         LittleEndian.putShort(data, 36 + offset, getCopies());
378         return getRecordSize();
379     }
380
381     public int getRecordSize()
382     {
383         return 38;
384     }
385
386     public short getSid()
387     {
388         return this.sid;
389     }
390
391     public Object JavaDoc clone() {
392       PrintSetupRecord rec = new PrintSetupRecord();
393       rec.field_1_paper_size = field_1_paper_size;
394       rec.field_2_scale = field_2_scale;
395       rec.field_3_page_start = field_3_page_start;
396       rec.field_4_fit_width = field_4_fit_width;
397       rec.field_5_fit_height = field_5_fit_height;
398       rec.field_6_options = field_6_options;
399       rec.field_7_hresolution = field_7_hresolution;
400       rec.field_8_vresolution = field_8_vresolution;
401       rec.field_9_headermargin = field_9_headermargin;
402       rec.field_10_footermargin = field_10_footermargin;
403       rec.field_11_copies = field_11_copies;
404       return rec;
405     }
406 }
407
Popular Tags