KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > drawing > ObjRecord


1 /*********************************************************************
2 *
3 * Copyright (C) 2001 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.drawing;
21
22 import common.Logger;
23 import common.Assert;
24 import jxl.biff.WritableRecordData;
25 import jxl.biff.IntegerHelper;
26 import jxl.biff.Type;
27 import jxl.read.biff.Record;
28
29 /**
30  * A record which merely holds the OBJ data. Used when copying files which
31  * contain images
32  */

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

38   private final static Logger logger = Logger.getLogger(ObjRecord.class);
39
40   /**
41    * The object type
42    */

43   private ObjType type;
44
45   /**
46    * Indicates whether this record was read in
47    */

48   private boolean read;
49
50   /**
51    * The object id
52    */

53   private int objectId;
54
55   /**
56    * Object type enumeration
57    */

58   private static final class ObjType
59   {
60     public int value;
61     public String JavaDoc desc;
62
63     private static ObjType[] types = new ObjType[0];
64
65     ObjType(int v, String JavaDoc d)
66     {
67       value = v;
68       desc = d;
69
70       ObjType[] oldtypes = types;
71       types = new ObjType[types.length+1];
72       System.arraycopy(oldtypes, 0, types, 0, oldtypes.length);
73       types[oldtypes.length] = this;
74     }
75
76     public String JavaDoc toString()
77     {
78       return desc;
79     }
80
81     public static ObjType getType(int val)
82     {
83       ObjType retval = UNKNOWN;
84       for (int i = 0; i < types.length && retval == UNKNOWN ; i++)
85       {
86         if (types[i].value == val)
87         {
88           retval = types[i];
89         }
90       }
91       return retval;
92     }
93   }
94   
95   // The object types
96
public static final ObjType TBD2 = new ObjType(0x01, "TBD2");
97   public static final ObjType TBD = new ObjType(0x02, "TBD");
98   public static final ObjType CHART = new ObjType(0x05, "Chart");
99   public static final ObjType TEXT = new ObjType(0x06, "Text");
100   public static final ObjType BUTTON = new ObjType(0x07, "Button");
101   public static final ObjType PICTURE = new ObjType(0x08, "Picture");
102   public static final ObjType CHECKBOX = new ObjType(0x0e, "Checkbox");
103   public static final ObjType OPTION = new ObjType(0x0c, "Option");
104   public static final ObjType EDITBOX = new ObjType(0x0d, "Edit Box");
105   public static final ObjType LABEL = new ObjType(0x0e, "Label");
106   public static final ObjType DIALOGUEBOX = new ObjType(0x0f, "Dialogue Box");
107   public static final ObjType LISTBOX = new ObjType(0x12, "List Box");
108   public static final ObjType GROUPBOX = new ObjType(0x13, "Group Box");
109   public static final ObjType COMBOBOX = new ObjType(0x14, "Combo Box");
110   public static final ObjType MSOFFICEDRAWING = new ObjType
111     (0x1e, "MS Office Drawing");
112   public static final ObjType FORMCONTROL =
113     new ObjType (0x14,"Form Combo Box");
114   public static final ObjType EXCELNOTE =
115     new ObjType (0x19,"Excel Note");
116
117   public static final ObjType UNKNOWN = new ObjType(0xff, "Unknown");
118
119   // Field sub records
120
private static final int COMMON_DATA_LENGTH=22;
121   private static final int CLIPBOARD_FORMAT_LENGTH=6;
122   private static final int PICTURE_OPTION_LENGTH=6;
123   private static final int NOTE_STRUCTURE_LENGTH=26;
124   private static final int END_LENGTH=4;
125
126   /**
127    * Constructs this object from the raw data
128    *
129    * @param t the raw data
130    */

131   public ObjRecord(Record t)
132   {
133     super(t);
134     byte[] data = t.getData();
135     int objtype = IntegerHelper.getInt(data[4], data[5]);
136     read = true;
137     type = ObjType.getType(objtype);
138
139     objectId = IntegerHelper.getInt(data[6], data[7]);
140   }
141
142   /**
143    * Constructor
144    *
145    * @param objId the object id
146    * @param t the object type
147    */

148   ObjRecord(int objId, ObjType t)
149   {
150     super(Type.OBJ);
151     objectId = objId;
152     type = t;
153   }
154
155   /**
156    * Expose the protected function to the SheetImpl in this package
157    *
158    * @return the raw record data
159    */

160   public byte[] getData()
161   {
162     if (read)
163     {
164       return getRecord().getData();
165     }
166
167     if (type == PICTURE || type == CHART)
168     {
169       return getPictureData();
170     }
171     else if (type == EXCELNOTE)
172     {
173       return getNoteData();
174     }
175     else
176     {
177       Assert.verify(false);
178     }
179     return null;
180   }
181
182   /**
183    * Gets the ObjRecord subrecords for a picture
184    */

185   private byte[] getPictureData()
186   {
187   
188     int dataLength = COMMON_DATA_LENGTH +
189       CLIPBOARD_FORMAT_LENGTH +
190       PICTURE_OPTION_LENGTH +
191       END_LENGTH;
192     int pos = 0;
193     byte[] data = new byte[dataLength];
194     
195     // The common data
196
// record id
197
IntegerHelper.getTwoBytes(0x15, data, pos);
198
199     // record length
200
IntegerHelper.getTwoBytes(COMMON_DATA_LENGTH-4, data, pos+2);
201     
202     // object type
203
IntegerHelper.getTwoBytes(type.value, data, pos+4);
204
205     // object id
206
IntegerHelper.getTwoBytes(objectId, data, pos+6);
207
208     // the options
209
IntegerHelper.getTwoBytes(0x6011, data, pos+8);
210     pos += COMMON_DATA_LENGTH;
211
212     // The clipboard format
213
// record id
214
IntegerHelper.getTwoBytes(0x7, data, pos);
215
216     // record length
217
IntegerHelper.getTwoBytes(CLIPBOARD_FORMAT_LENGTH-4, data, pos+2);
218     
219     // the data
220
IntegerHelper.getTwoBytes(0xffff, data, pos+4);
221     pos += CLIPBOARD_FORMAT_LENGTH;
222       
223     // Picture option flags
224
// record id
225
IntegerHelper.getTwoBytes(0x8, data, pos);
226     
227     // record length
228
IntegerHelper.getTwoBytes(PICTURE_OPTION_LENGTH-4, data, pos+2);
229     
230     // the data
231
IntegerHelper.getTwoBytes(0x1, data, pos+4);
232     pos += CLIPBOARD_FORMAT_LENGTH;
233
234     // End
235
// record id
236
IntegerHelper.getTwoBytes(0x0, data, pos);
237     
238     // record length
239
IntegerHelper.getTwoBytes(END_LENGTH-4, data, pos+2);
240     
241     // the data
242
pos += END_LENGTH;
243
244     return data;
245   }
246
247
248   /**
249    * Gets the ObjRecord subrecords for a note
250    */

251   private byte[] getNoteData()
252   {
253     int dataLength = COMMON_DATA_LENGTH +
254       NOTE_STRUCTURE_LENGTH +
255       END_LENGTH;
256     int pos = 0;
257     byte[] data = new byte[dataLength];
258     
259     // The common data
260
// record id
261
IntegerHelper.getTwoBytes(0x15, data, pos);
262
263     // record length
264
IntegerHelper.getTwoBytes(COMMON_DATA_LENGTH-4, data, pos+2);
265     
266     // object type
267
IntegerHelper.getTwoBytes(type.value, data, pos+4);
268
269     // object id
270
IntegerHelper.getTwoBytes(objectId, data, pos+6);
271
272     // the options
273
IntegerHelper.getTwoBytes(0x4011, data, pos+8);
274     pos += COMMON_DATA_LENGTH;
275
276     // The note structure
277
// record id
278
IntegerHelper.getTwoBytes(0xd, data, pos);
279
280     // record length
281
IntegerHelper.getTwoBytes(NOTE_STRUCTURE_LENGTH-4, data, pos+2);
282     
283     // the data
284
pos += NOTE_STRUCTURE_LENGTH;
285
286     // End
287
// record id
288
IntegerHelper.getTwoBytes(0x0, data, pos);
289     
290     // record length
291
IntegerHelper.getTwoBytes(END_LENGTH-4, data, pos+2);
292     
293     // the data
294
pos += END_LENGTH;
295
296     return data;
297   }
298
299   /**
300    * Expose the protected function to the SheetImpl in this package
301    *
302    * @return the raw record data
303    */

304   public Record getRecord()
305   {
306     return super.getRecord();
307   }
308
309   /**
310    * Accessor for the object type
311    *
312    * @return the object type
313    */

314   public ObjType getType()
315   {
316     return type;
317   }
318
319   /**
320    * Accessor for the object id
321    */

322   int getObjectId()
323   {
324     return objectId;
325   }
326 }
327
328
329
330
331
Popular Tags