KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > write > WritableFont


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;
21
22 import jxl.write.biff.WritableFontRecord;
23
24 import jxl.format.Font;
25 import jxl.format.Colour;
26 import jxl.format.UnderlineStyle;
27 import jxl.format.ScriptStyle;
28
29 /**
30  * A class which is instantiated when the user application wishes to specify
31  * the font for a particular cell
32  */

33 public class WritableFont extends WritableFontRecord
34 {
35   /**
36    * Static inner class used for classifying the font names
37    */

38   public static class FontName
39   {
40     /**
41      * The name
42      */

43     String JavaDoc name;
44
45     /**
46      * Constructor
47      *
48      * @param s the font name
49      */

50     FontName(String JavaDoc s)
51     {
52       name = s;
53     }
54   }
55
56   /**
57    * Static inner class used for the boldness of the fonts
58    */

59   /*private*/ static class BoldStyle
60   {
61     /**
62      * The value
63      */

64     public int value;
65
66     /**
67      * Constructor
68      *
69      * @param val the value
70      */

71     BoldStyle(int val)
72     {
73       value = val;
74     }
75   }
76
77   /**
78    * Objects created with this font name will be rendered within Excel as ARIAL
79    * fonts
80    */

81   public static final FontName ARIAL = new FontName("Arial");
82   /**
83    * Objects created with this font name will be rendered within Excel as TIMES
84    * fonts
85    */

86   public static final FontName TIMES = new FontName("Times New Roman");
87   /**
88    * Objects created with this font name will be rendered within Excel as
89    * COURIER fonts
90    */

91   public static final FontName COURIER = new FontName("Courier New");
92   /**
93    * Objects created with this font name will be rendered within Excel as
94    * TAHOMA fonts
95    */

96   public static final FontName TAHOMA = new FontName("Tahoma");
97
98   // The bold styles
99

100   /**
101    * Indicates that this font should not be presented as bold
102    */

103   public static final BoldStyle NO_BOLD = new BoldStyle(0x190);
104   /**
105    * Indicates that this font should be presented in a BOLD style
106    */

107   public static final BoldStyle BOLD = new BoldStyle(0x2bc);
108
109   /**
110    * The default point size for all Fonts
111    */

112   public static final int DEFAULT_POINT_SIZE = 10;
113
114   /**
115    * Creates a default font, vanilla font of the specified face and with
116    * default point size.
117    *
118    * @param fn the font name
119    */

120   public WritableFont(FontName fn)
121   {
122     this(fn,
123          DEFAULT_POINT_SIZE,
124          NO_BOLD,
125          false,
126          UnderlineStyle.NO_UNDERLINE,
127          Colour.BLACK,
128          ScriptStyle.NORMAL_SCRIPT);
129   }
130
131   /**
132    * Publicly available copy constructor
133    *
134    * @param f the font to copy
135    */

136   public WritableFont(Font f)
137   {
138     super(f);
139   }
140
141   /**
142    * Constructs of font of the specified face and of size given by the
143    * specified point size
144    *
145    * @param ps the point size
146    * @param fn the font name
147    */

148   public WritableFont(FontName fn, int ps)
149   {
150     this(fn, ps, NO_BOLD, false,
151          UnderlineStyle.NO_UNDERLINE,
152          Colour.BLACK,
153          ScriptStyle.NORMAL_SCRIPT);
154   }
155
156   /**
157    * Creates a font of the specified face, point size and bold style
158    *
159    * @param ps the point size
160    * @param bs the bold style
161    * @param fn the font name
162    */

163   public WritableFont(FontName fn, int ps, BoldStyle bs)
164   {
165     this(fn, ps, bs, false,
166          UnderlineStyle.NO_UNDERLINE,
167          Colour.BLACK,
168          ScriptStyle.NORMAL_SCRIPT);
169   }
170
171   /**
172    * Creates a font of the specified face, point size, bold weight and
173    * italicised option.
174    *
175    * @param ps the point size
176    * @param bs the bold style
177    * @param italic italic flag
178    * @param fn the font name
179    */

180   public WritableFont(FontName fn, int ps, BoldStyle bs, boolean italic)
181   {
182     this(fn, ps, bs, italic,
183          UnderlineStyle.NO_UNDERLINE,
184          Colour.BLACK,
185          ScriptStyle.NORMAL_SCRIPT);
186   }
187
188   /**
189    * Creates a font of the specified face, point size, bold weight,
190    * italicisation and underline style
191    *
192    * @param ps the point size
193    * @param bs the bold style
194    * @param us the underline style
195    * @param fn the font name
196    * @param it italic flag
197    */

198   public WritableFont(FontName fn,
199                       int ps,
200                       BoldStyle bs,
201                       boolean it,
202                       UnderlineStyle us)
203   {
204     this(fn, ps, bs, it, us, Colour.BLACK, ScriptStyle.NORMAL_SCRIPT);
205   }
206
207
208   /**
209    * Creates a font of the specified face, point size, bold style,
210    * italicisation, underline style and colour
211    *
212    * @param ps the point size
213    * @param bs the bold style
214    * @param us the underline style
215    * @param fn the font name
216    * @param it italic flag
217    * @param c the colour
218    */

219   public WritableFont(FontName fn,
220                       int ps,
221                       BoldStyle bs,
222                       boolean it,
223                       UnderlineStyle us,
224                       Colour c)
225   {
226     this(fn, ps, bs, it, us, c, ScriptStyle.NORMAL_SCRIPT);
227   }
228
229
230   /**
231    * Creates a font of the specified face, point size, bold style,
232    * italicisation, underline style, colour, and script
233    * style (superscript/subscript)
234    *
235    * @param ps the point size
236    * @param bs the bold style
237    * @param us the underline style
238    * @param fn the font name
239    * @param it the italic flag
240    * @param c the colour
241    * @param ss the script style
242    */

243   public WritableFont(FontName fn,
244                       int ps,
245                       BoldStyle bs,
246                       boolean it,
247                       UnderlineStyle us,
248                       Colour c,
249                       ScriptStyle ss)
250   {
251     super(fn.name, ps, bs.value, it,
252           us.getValue(),
253           c.getValue(), ss.getValue());
254   }
255
256   /**
257    * Sets the point size for this font, if the font hasn't been initialized
258    *
259    * @param pointSize the point size
260    * @exception WriteException, if this font is already in use elsewhere
261    */

262   public void setPointSize(int pointSize) throws WriteException
263   {
264     super.setPointSize(pointSize);
265   }
266
267   /**
268    * Sets the bold style for this font, if the font hasn't been initialized
269    *
270    * @param boldStyle the bold style
271    * @exception WriteException, if this font is already in use elsewhere
272    */

273   public void setBoldStyle(BoldStyle boldStyle) throws WriteException
274   {
275     super.setBoldStyle(boldStyle.value);
276   }
277
278   /**
279    * Sets the italic indicator for this font, if the font hasn't been
280    * initialized
281    *
282    * @param italic the italic flag
283    * @exception WriteException, if this font is already in use elsewhere
284    */

285   public void setItalic(boolean italic) throws WriteException
286   {
287     super.setItalic(italic);
288   }
289
290   /**
291    * Sets the underline style for this font, if the font hasn't been
292    * initialized
293    *
294    * @param us the underline style
295    * @exception WriteException, if this font is already in use elsewhere
296    */

297   public void setUnderlineStyle(UnderlineStyle us) throws WriteException
298   {
299     super.setUnderlineStyle(us.getValue());
300   }
301
302   /**
303    * Sets the colour for this font, if the font hasn't been
304    * initialized
305    *
306    * @param colour the colour
307    * @exception WriteException, if this font is already in use elsewhere
308    */

309   public void setColour(Colour colour) throws WriteException
310   {
311     super.setColour(colour.getValue());
312   }
313
314   /**
315    * Sets the script style (eg. superscript, subscript) for this font,
316    * if the font hasn't been initialized
317    *
318    * @param scriptStyle the colour
319    * @exception WriteException, if this font is already in use elsewhere
320    */

321   public void setScriptStyle(ScriptStyle scriptStyle) throws WriteException
322   {
323     super.setScriptStyle(scriptStyle.getValue());
324   }
325
326   /**
327    * Factory method which creates the specified font name. This method
328    * should be used with care, since the string used to create the font
329    * name must be recognized by Excel's internal processing
330    *
331    * @param fontName the name of the Excel font
332    * @return the font name
333    */

334   public static FontName createFont(String JavaDoc fontName)
335   {
336     return new FontName(fontName);
337   }
338
339 }
340
341
Popular Tags