KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > DValParser


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.biff;
21
22 import common.Logger;
23 import jxl.WorkbookSettings;
24 import jxl.biff.formula.ExternalSheet;
25 import jxl.biff.formula.FormulaParser;
26 import jxl.biff.formula.FormulaException;
27
28 /**
29  * Class which parses the binary data associated with Data Validity (DVal)
30  * setting
31  */

32 public class DValParser
33 {
34   /**
35    * The logger
36    */

37   private static Logger logger = Logger.getLogger(DValParser.class);
38
39   // The option masks
40
private static int PROMPT_BOX_VISIBLE_MASK = 0x1;
41   private static int PROMPT_BOX_AT_CELL_MASK = 0x2;
42   private static int VALIDITY_DATA_CACHED_MASK = 0x4;
43
44   /**
45    * Prompt box visible
46    */

47   private boolean promptBoxVisible;
48
49   /**
50    * Empty cells allowed
51    */

52   private boolean promptBoxAtCell;
53
54   /**
55    * Cell validity data cached in following DV records
56    */

57   private boolean validityDataCached;
58
59   /**
60    * The number of following DV records
61    */

62   private int numDVRecords;
63
64   /**
65    * Constructor
66    */

67   public DValParser(byte[] data)
68   {
69     int options = IntegerHelper.getInt(data[0], data[1]);
70
71     promptBoxVisible = (options & PROMPT_BOX_VISIBLE_MASK) != 0;
72     promptBoxAtCell = (options & PROMPT_BOX_AT_CELL_MASK) != 0;
73     validityDataCached = (options & VALIDITY_DATA_CACHED_MASK) != 0;
74
75     numDVRecords = IntegerHelper.getInt(data[14], data[15],
76                                         data[16], data[17]);
77   }
78
79   /**
80    * Gets the data
81    */

82   public byte[] getData()
83   {
84     byte[] data = new byte[18];
85
86     int options = 0;
87     
88     if (promptBoxVisible)
89     {
90       options |= PROMPT_BOX_VISIBLE_MASK;
91     }
92
93     if (promptBoxAtCell)
94     {
95       options |= PROMPT_BOX_AT_CELL_MASK;
96     }
97
98     if (validityDataCached)
99     {
100       options |= VALIDITY_DATA_CACHED_MASK;
101     }
102
103     IntegerHelper.getFourBytes(0xffffffff, data, 10);
104
105     IntegerHelper.getFourBytes(numDVRecords, data, 14);
106
107     return data;
108   }
109
110   /**
111    * Called when a remove row or column results in one of DV records being
112    * removed
113    */

114   public void dvRemoved()
115   {
116     numDVRecords--;
117   }
118
119   /**
120    * Accessor for the number of DV records
121    *
122    * @return the number of DV records for this list
123    */

124   public int getNumberOfDVRecords()
125   {
126     return numDVRecords;
127   }
128 }
129
Popular Tags