KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.HashMap JavaDoc;
26
27 import common.Assert;
28 import jxl.biff.FormatRecord;
29 import jxl.biff.Fonts;
30 import jxl.biff.XFRecord;
31 import jxl.biff.FormattingRecords;
32 import jxl.biff.NumFormatRecordsException;
33 import jxl.format.CellFormat;
34 import jxl.format.Alignment;
35 import jxl.format.VerticalAlignment;
36 import jxl.write.WritableCellFormat;
37 import jxl.write.WritableWorkbook;
38 import jxl.write.NumberFormats;
39
40 /**
41  * Handles the Format and XF record indexing. The writable subclass
42  * instantiates the predetermined list of XF records and formats
43  * present in every Excel Workbook
44  */

45 public class WritableFormattingRecords extends FormattingRecords
46 {
47   /**
48    * The statically defined normal style
49    */

50   public static WritableCellFormat normalStyle;
51
52   /**
53    * Constructor. Instantiates the prerequisite list of formats and
54    * styles required by all Excel workbooks
55    *
56    * @param f the list of Fonts
57    * @param styles the list of style clones
58    */

59   public WritableFormattingRecords(Fonts f, Styles styles)
60   {
61     super(f);
62
63     try
64     {
65       // Hard code all the styles
66
StyleXFRecord sxf = new StyleXFRecord
67         (styles.getArial10Pt(),NumberFormats.DEFAULT);
68       sxf.setLocked(true);
69       addStyle(sxf);
70
71       sxf = new StyleXFRecord(getFonts().getFont(1),NumberFormats.DEFAULT);
72       sxf.setLocked(true);
73       sxf.setCellOptions(0xf400);
74       addStyle(sxf);
75
76       sxf = new StyleXFRecord(getFonts().getFont(1),NumberFormats.DEFAULT);
77       sxf.setLocked(true);
78       sxf.setCellOptions(0xf400);
79       addStyle(sxf);
80
81       sxf = new StyleXFRecord(getFonts().getFont(1),NumberFormats.DEFAULT);
82       sxf.setLocked(true);
83       sxf.setCellOptions(0xf400);
84       addStyle(sxf);
85
86       sxf = new StyleXFRecord(getFonts().getFont(2),NumberFormats.DEFAULT);
87       sxf.setLocked(true);
88       sxf.setCellOptions(0xf400);
89       addStyle(sxf);
90
91       sxf = new StyleXFRecord(getFonts().getFont(3),NumberFormats.DEFAULT);
92       sxf.setLocked(true);
93       sxf.setCellOptions(0xf400);
94       addStyle(sxf);
95
96       sxf = new StyleXFRecord(styles.getArial10Pt(),
97                               NumberFormats.DEFAULT);
98       sxf.setLocked(true);
99       sxf.setCellOptions(0xf400);
100       addStyle(sxf);
101
102       sxf = new StyleXFRecord(styles.getArial10Pt(),
103                               NumberFormats.DEFAULT);
104       sxf.setLocked(true);
105       sxf.setCellOptions(0xf400);
106       addStyle(sxf);
107
108       sxf = new StyleXFRecord(styles.getArial10Pt(),
109                               NumberFormats.DEFAULT);
110       sxf.setLocked(true);
111       sxf.setCellOptions(0xf400);
112       addStyle(sxf);
113
114       sxf = new StyleXFRecord(styles.getArial10Pt(),
115                               NumberFormats.DEFAULT);
116       sxf.setLocked(true);
117       sxf.setCellOptions(0xf400);
118       addStyle(sxf);
119
120       sxf = new StyleXFRecord(styles.getArial10Pt(),
121                               NumberFormats.DEFAULT);
122       sxf.setLocked(true);
123       sxf.setCellOptions(0xf400);
124       addStyle(sxf);
125
126       sxf = new StyleXFRecord(styles.getArial10Pt(),
127                               NumberFormats.DEFAULT);
128       sxf.setLocked(true);
129       sxf.setCellOptions(0xf400);
130       addStyle(sxf);
131
132       sxf = new StyleXFRecord(styles.getArial10Pt(),
133                               NumberFormats.DEFAULT);
134       sxf.setLocked(true);
135       sxf.setCellOptions(0xf400);
136       addStyle(sxf);
137
138       sxf = new StyleXFRecord(styles.getArial10Pt(),
139                               NumberFormats.DEFAULT);
140       sxf.setLocked(true);
141       sxf.setCellOptions(0xf400);
142       addStyle(sxf);
143
144       sxf = new StyleXFRecord(styles.getArial10Pt(),
145                               NumberFormats.DEFAULT);
146       sxf.setLocked(true);
147       sxf.setCellOptions(0xf400);
148       addStyle(sxf);
149
150       // That's the end of the built ins. Write the normal style
151
// cell XF here
152
addStyle(styles.getNormalStyle());
153
154       // Continue with "user defined" styles
155
sxf = new StyleXFRecord(getFonts().getFont(1),
156                               NumberFormats.FORMAT7);
157       sxf.setLocked(true);
158       sxf.setCellOptions(0xf800);
159       addStyle(sxf);
160
161       sxf = new StyleXFRecord(getFonts().getFont(1),
162                               NumberFormats.FORMAT5);
163       sxf.setLocked(true);
164       sxf.setCellOptions(0xf800);
165       addStyle(sxf);
166
167       sxf = new StyleXFRecord(getFonts().getFont(1),
168                               NumberFormats.FORMAT8);
169       sxf.setLocked(true);
170       sxf.setCellOptions(0xf800);
171       addStyle(sxf);
172
173       sxf = new StyleXFRecord(getFonts().getFont(1),
174                               NumberFormats.FORMAT6);
175       sxf.setLocked(true);
176       sxf.setCellOptions(0xf800);
177       addStyle(sxf);
178
179       sxf = new StyleXFRecord(getFonts().getFont(1),
180                               NumberFormats.PERCENT_INTEGER);
181       sxf.setLocked(true);
182       sxf.setCellOptions(0xf800);
183       addStyle(sxf);
184
185       // Hard code in the pre-defined number formats for now
186
/*
187         FormatRecord fr = new FormatRecord
188         ("\"$\"#,##0_);\\(\"$\"#,##0\\)",5);
189         addFormat(fr);
190
191         fr = new FormatRecord
192         ("\"$\"#,##0_);[Red]\\(\"$\"#,##0\\)", 6);
193         addFormat(fr);
194
195         fr = new FormatRecord
196         ("\"$\"#,##0.00_);\\(\"$\"#,##0.00\\)", 7);
197         addFormat(fr);
198
199         fr = new FormatRecord
200         ("\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)", 8);
201         addFormat(fr);
202
203         fr = new FormatRecord
204         ("_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)",
205         0x2a);
206         // outputFile.write(fr);
207
208         fr = new FormatRecord
209         ("_(* #,##0_);_(* \\(#,##0\\);_(* \"-\"_);_(@_)",
210         0x2e);
211         // outputFile.write(fr);
212
213         fr = new FormatRecord
214         ("_(\"$\"* #,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)",
215         0x2c);
216         // outputFile.write(fr);
217
218         fr = new FormatRecord
219         ("_(* #,##0.00_);_(* \\(#,##0.00\\);_(* \"-\"??_);_(@_)",
220         0x2b);
221         // outputFile.write(fr);
222         */

223     }
224     catch (NumFormatRecordsException e)
225     {
226       // This should not happen yet, since we are just creating the file.
227
// Bomb out
228
Assert.verify(false, e.getMessage());
229     }
230   }
231 }
232
233
234
235
236
237
238
239
240
241
Popular Tags