KickJava   Java API By Example, From Geeks To Geeks.

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


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 jxl.biff.IntegerHelper;
23 import jxl.biff.FontRecord;
24 import jxl.biff.FormatRecord;
25 import jxl.biff.XFRecord;
26 import jxl.biff.DisplayFormat;
27 import jxl.format.Alignment;
28 import jxl.format.VerticalAlignment;
29 import jxl.format.BorderLineStyle;
30 import jxl.format.Border;
31 import jxl.format.Colour;
32 import jxl.format.Pattern;
33 import jxl.format.Orientation;
34 import jxl.format.CellFormat;
35 import jxl.write.WriteException;
36
37 /**
38  * A cell XF Record
39  */

40 public class CellXFRecord extends XFRecord
41 {
42   /**
43    * Constructor
44    *
45    * @param fnt the font
46    * @param form the format
47    */

48   protected CellXFRecord(FontRecord fnt, DisplayFormat form )
49   {
50     super(fnt, form);
51     setXFDetails(XFRecord.cell,0);
52   }
53
54   /**
55    * Copy constructor. Invoked when copying formats to handle cell merging
56    *
57    * @param fmt the format to copy
58    */

59   CellXFRecord(XFRecord fmt )
60   {
61     super(fmt);
62     setXFDetails(XFRecord.cell,0);
63   }
64
65   /**
66    * A public copy constructor which can be used for copy formats between
67    * different sheets
68    */

69   protected CellXFRecord(CellFormat format)
70   {
71     super(format);
72   }
73
74   /**
75    * Sets the alignment for the cell
76    *
77    * @exception WriteException
78    * @param a the alignment
79    */

80   public void setAlignment(Alignment a) throws WriteException
81   {
82     if (isInitialized())
83     {
84       throw new JxlWriteException(JxlWriteException.formatInitialized);
85     }
86     super.setXFAlignment(a);
87   }
88
89   /**
90    * Sets the background for the cell
91    *
92    * @exception WriteException
93    * @param c the background colour
94    * @param p the background patter
95    */

96   public void setBackground(Colour c, Pattern p) throws WriteException
97   {
98     if (isInitialized())
99     {
100       throw new JxlWriteException(JxlWriteException.formatInitialized);
101     }
102     super.setXFBackground(c, p);
103     super.setXFCellOptions(0x4000);
104   }
105
106   /**
107    * Sets whether or not this XF record locks the cell
108    *
109    * @param l the locked flag
110    * @exception WriteException
111    */

112   public void setLocked(boolean l) throws WriteException
113   {
114     if (isInitialized())
115     {
116       throw new JxlWriteException(JxlWriteException.formatInitialized);
117     }
118     super.setXFLocked(l);
119     super.setXFCellOptions(0x8000);
120   }
121
122   /**
123    * Sets the indentation of the cell text
124    *
125    * @param i the indentation
126    */

127   public void setIndentation(int i) throws WriteException
128   {
129     if (isInitialized())
130     {
131       throw new JxlWriteException(JxlWriteException.formatInitialized);
132     }
133     super.setXFIndentation(i);
134   }
135
136   /**
137    * Sets the shrink to fit flag
138    *
139    * @param b the shrink to fit flag
140    */

141   public void setShrinkToFit(boolean s) throws WriteException
142   {
143     if (isInitialized())
144     {
145       throw new JxlWriteException(JxlWriteException.formatInitialized);
146     }
147     super.setXFShrinkToFit(s);
148   }
149
150   /**
151    * Sets the vertical alignment for cells with this style
152    *
153    * @exception WriteException
154    * @param va the vertical alignment
155    */

156   public void setVerticalAlignment(VerticalAlignment va)
157     throws WriteException
158   {
159     if (isInitialized())
160     {
161       throw new JxlWriteException(JxlWriteException.formatInitialized);
162     }
163
164     super.setXFVerticalAlignment(va);
165   }
166
167   /**
168    * Sets the text orientation for cells with this style
169    *
170    * @exception WriteException
171    * @param o the orientation
172    */

173   public void setOrientation(Orientation o)
174     throws WriteException
175   {
176     if (isInitialized())
177     {
178       throw new JxlWriteException(JxlWriteException.formatInitialized);
179     }
180
181     super.setXFOrientation(o);
182   }
183
184   /**
185    * Sets the text wrapping for cells with this style. If the parameter is
186    * set to TRUE, then data in this cell will be wrapped around, and the
187    * cell's height adjusted accordingly
188    *
189    * @exception WriteException
190    * @param w the wrap
191    */

192   public void setWrap(boolean w) throws WriteException
193   {
194     if (isInitialized())
195     {
196       throw new JxlWriteException(JxlWriteException.formatInitialized);
197     }
198
199     super.setXFWrap(w);
200   }
201
202   /**
203    * Sets the border style for cells with this format
204    *
205    * @exception WriteException
206    * @param b the border
207    * @param ls the line for the specified border
208    */

209   public void setBorder(Border b, BorderLineStyle ls, Colour c)
210     throws WriteException
211   {
212     if (isInitialized())
213     {
214       throw new JxlWriteException(JxlWriteException.formatInitialized);
215     }
216
217     if (b == Border.ALL)
218     {
219       // Apply to all
220
super.setXFBorder(Border.LEFT, ls, c);
221       super.setXFBorder(Border.RIGHT, ls, c);
222       super.setXFBorder(Border.TOP, ls, c);
223       super.setXFBorder(Border.BOTTOM, ls, c);
224       return;
225     }
226
227     if (b == Border.NONE)
228     {
229       // Apply to all
230
super.setXFBorder(Border.LEFT, BorderLineStyle.NONE, Colour.BLACK);
231       super.setXFBorder(Border.RIGHT, BorderLineStyle.NONE, Colour.BLACK);
232       super.setXFBorder(Border.TOP, BorderLineStyle.NONE, Colour.BLACK);
233       super.setXFBorder(Border.BOTTOM, BorderLineStyle.NONE, Colour.BLACK);
234       return;
235     }
236
237     super.setXFBorder(b, ls, c);
238   }
239 }
240
241
Popular Tags