KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*********************************************************************
2 *
3 * Copyright (C) 2004 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
24 import jxl.biff.Type;
25 import jxl.biff.WritableRecordData;
26 import jxl.biff.DVParser;
27 import jxl.biff.formula.FormulaException;
28 import jxl.WorkbookSettings;
29
30 /**
31  * Data validity settings
32  */

33 class DataValiditySettingsRecord extends WritableRecordData
34 {
35   /**
36    * The logger
37    */

38   private static final Logger logger =
39     Logger.getLogger(DataValiditySettingsRecord.class);
40
41   /**
42    * The binary data
43    */

44   private byte[] data;
45   
46   /**
47    * The reader
48    */

49   private DVParser dvParser;
50
51   /**
52    * Handle to the workbook
53    */

54   private WritableWorkbookImpl workbook;
55
56   /**
57    * Handle to the workbook settings
58    */

59   private WorkbookSettings workbookSettings;
60
61   /**
62    * Constructor
63    *
64    * @param dvsr the record copied from a read only sheet
65    */

66   DataValiditySettingsRecord(jxl.read.biff.DataValiditySettingsRecord dvsr,
67                              WritableWorkbookImpl w,
68                              WorkbookSettings ws)
69   {
70     super(Type.DV);
71     workbook = w;
72     workbookSettings = ws;
73
74     
75     data = dvsr.getData();
76   }
77
78   /**
79    * Constructor
80    *
81    * @param dvsr the record copied from a writable sheet
82    */

83   DataValiditySettingsRecord(DataValiditySettingsRecord dvsr,
84                              WritableWorkbookImpl w,
85                              WorkbookSettings ws)
86   {
87     super(Type.DV);
88     workbook = w;
89     workbookSettings = ws;
90     
91     data = new byte[dvsr.data.length];
92     System.arraycopy(dvsr.data, 0, data, 0, data.length);
93   }
94
95   /**
96    * Initializes the dvParser
97    */

98   private void initialize()
99   {
100     try
101     {
102       if (dvParser == null)
103       {
104         dvParser = new DVParser(data, workbook, workbook, workbookSettings);
105       }
106     }
107     catch (FormulaException e)
108     {
109       logger.warn("Cannot read drop down range " + e.getMessage());
110       e.printStackTrace();
111     }
112   }
113   /**
114    * Retrieves the data for output to binary file
115    *
116    * @return the data to be written
117    */

118   public byte[] getData()
119   {
120     if (dvParser == null)
121     {
122       return data;
123     }
124
125     return dvParser.getData();
126   }
127
128   /**
129    * Inserts a row
130    *
131    * @param row the row to insert
132    */

133   public void insertRow(int row)
134   {
135     if (dvParser == null)
136     {
137       initialize();
138     }
139
140     dvParser.insertRow(row);
141   }
142
143   /**
144    * Removes a row
145    *
146    * @param row the row to insert
147    */

148   public void removeRow(int row)
149   {
150     if (dvParser == null)
151     {
152       initialize();
153     }
154
155     dvParser.removeRow(row);
156   }
157
158   /**
159    * Inserts a row
160    *
161    * @param col the row to insert
162    */

163   public void insertColumn(int col)
164   {
165     if (dvParser == null)
166     {
167       initialize();
168     }
169
170     dvParser.insertColumn(col);
171   }
172
173   /**
174    * Removes a column
175    *
176    * @param col the row to insert
177    */

178   public void removeColumn(int col)
179   {
180     if (dvParser == null)
181     {
182       initialize();
183     }
184
185     dvParser.removeColumn(col);
186   }
187
188   /**
189    * Accessor for first column
190    *
191    * @return the first column
192    */

193   public int getFirstColumn()
194   {
195     if (dvParser == null)
196     {
197       initialize();
198     }
199
200     return dvParser.getFirstColumn();
201   }
202
203   /**
204    * Accessor for the last column
205    *
206    * @return the last column
207    */

208   public int getLastColumn()
209   {
210     if (dvParser == null)
211     {
212       initialize();
213     }
214
215     return dvParser.getLastColumn();
216   }
217
218   /**
219    * Accessor for first row
220    *
221    * @return the first row
222    */

223   public int getFirstRow()
224   {
225     if (dvParser == null)
226     {
227       initialize();
228     }
229
230     return dvParser.getFirstRow();
231   }
232
233   /**
234    * Accessor for the last row
235    *
236    * @return the last row
237    */

238   public int getLastRow()
239   {
240     if (dvParser == null)
241     {
242       initialize();
243     }
244
245     return dvParser.getLastRow();
246   }
247 }
248
Popular Tags