KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > write > biff > SetupRecord


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.write.biff;
21
22 import common.Logger;
23 import jxl.SheetSettings;
24 import jxl.biff.Type;
25 import jxl.biff.IntegerHelper;
26 import jxl.biff.StringHelper;
27 import jxl.biff.DoubleHelper;
28 import jxl.biff.WritableRecordData;
29 import jxl.format.PageOrientation;
30 import jxl.format.PaperSize;
31
32 /**
33  * Stores the options and measurements from the Page Setup dialog box
34  */

35 class SetupRecord extends WritableRecordData
36 {
37   /**
38    * The logger
39    */

40   Logger logger = Logger.getLogger(SetupRecord.class);
41
42   /**
43    * The binary data for output to file
44    */

45   private byte[] data;
46
47   /**
48    * The header margin
49    */

50   private double headerMargin;
51
52   /**
53    * The footer margin
54    */

55   private double footerMargin;
56
57   /**
58    * The page orientation
59    */

60   private PageOrientation orientation;
61
62   /**
63    * The paper size
64    */

65   private int paperSize;
66
67   /**
68    * The scale factor
69    */

70   private int scaleFactor;
71
72   /**
73    * The page start
74    */

75   private int pageStart;
76
77   /**
78    * The fit width
79    */

80   private int fitWidth;
81
82   /**
83    * The fit height
84    */

85   private int fitHeight;
86
87   /**
88    * The horizontal print resolution
89    */

90   private int horizontalPrintResolution;
91
92   /**
93    * The vertical print resolution
94    */

95   private int verticalPrintResolution;
96
97   /**
98    * The number of copies
99    */

100   private int copies;
101
102   /**
103    * Constructor
104    *
105    * @deprecated in favour of the sheet settings constructor
106    */

107   public SetupRecord()
108   {
109     super(Type.SETUP);
110
111     orientation = PageOrientation.PORTRAIT;
112     headerMargin = 0.5;
113     footerMargin = 0.5;
114     paperSize = PaperSize.A4.getValue();
115     horizontalPrintResolution = 0x12c;
116     verticalPrintResolution = 0x12c;
117     copies = 1;
118   }
119
120   /**
121    * Constructor, taking the sheet settings. This object just
122    * takes the various fields from the bean in which it is interested
123    *
124    * @param the sheet settings
125    */

126   public SetupRecord(SheetSettings s)
127   {
128     super(Type.SETUP);
129
130     orientation = s.getOrientation();
131     headerMargin = s.getHeaderMargin();
132     footerMargin = s.getFooterMargin();
133     paperSize = s.getPaperSize().getValue();
134     horizontalPrintResolution = s.getHorizontalPrintResolution();
135     verticalPrintResolution = s.getVerticalPrintResolution();
136     fitWidth = s.getFitWidth();
137     fitHeight = s.getFitHeight();
138     pageStart = s.getPageStart();
139     scaleFactor = s.getScaleFactor();
140     copies = s.getCopies();
141   }
142
143   /**
144    * Constructor - used when copying sheets
145    * @deprecated in favour of the SheetSettings constructor
146    */

147   public SetupRecord(jxl.read.biff.SetupRecord sr)
148   {
149     super(Type.SETUP);
150
151     orientation = sr.isPortrait() ?
152                   PageOrientation.PORTRAIT : PageOrientation.LANDSCAPE;
153
154     paperSize = sr.getPaperSize();
155     headerMargin = sr.getHeaderMargin();
156     footerMargin = sr.getFooterMargin();
157     scaleFactor = sr.getScaleFactor();
158     pageStart = sr.getPageStart();
159     fitWidth = sr.getFitWidth();
160     fitHeight = sr.getFitHeight();
161     horizontalPrintResolution = sr.getHorizontalPrintResolution();
162     verticalPrintResolution = sr.getVerticalPrintResolution();
163     copies = sr.getCopies();
164   }
165
166   /**
167    * Sets the orientation
168    *
169    * @param o the orientation
170    */

171   public void setOrientation(PageOrientation o)
172   {
173     orientation = o;
174   }
175
176   /**
177    * Sets the header and footer margins
178    *
179    * @param hm the header margin
180    * @param fm the footer margin
181    */

182   public void setMargins(double hm, double fm)
183   {
184     headerMargin = hm;
185     footerMargin = fm;
186   }
187
188   /**
189    * Sets the paper size
190    *
191    * @param ps the paper size
192    */

193   public void setPaperSize(PaperSize ps)
194   {
195     paperSize = ps.getValue();
196   }
197
198   /**
199    * Gets the binary data for output to file
200    *
201    * @return the binary data
202    */

203   public byte[] getData()
204   {
205     data = new byte[34];
206
207     // Paper size
208
IntegerHelper.getTwoBytes(paperSize, data, 0);
209
210     // Scale factor
211
IntegerHelper.getTwoBytes(scaleFactor, data, 2);
212
213     // Page start
214
IntegerHelper.getTwoBytes(pageStart, data, 4);
215
216     // Fit width
217
IntegerHelper.getTwoBytes(fitWidth, data, 6);
218
219     // Fit height
220
IntegerHelper.getTwoBytes(fitHeight, data, 8);
221
222     // grbit
223
if (orientation == PageOrientation.PORTRAIT)
224     {
225       IntegerHelper.getTwoBytes(2, data, 10);
226     }
227
228     // print resolution
229
IntegerHelper.getTwoBytes(horizontalPrintResolution, data, 12);
230
231     // vertical print resolution
232
IntegerHelper.getTwoBytes(verticalPrintResolution, data, 14);
233     
234     // header margin
235
DoubleHelper.getIEEEBytes(headerMargin, data, 16);
236
237     // footer margin
238
DoubleHelper.getIEEEBytes(footerMargin, data, 24);
239
240     // Number of copies
241
IntegerHelper.getTwoBytes(copies, data, 32);
242
243     return data;
244   }
245 }
246
247
Popular Tags