1 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 33 public class ObjRecord extends WritableRecordData 34 { 35 38 private final static Logger logger = Logger.getLogger(ObjRecord.class); 39 40 43 private ObjType type; 44 45 48 private boolean read; 49 50 53 private int objectId; 54 55 58 private static final class ObjType 59 { 60 public int value; 61 public String desc; 62 63 private static ObjType[] types = new ObjType[0]; 64 65 ObjType(int v, String 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 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 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 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 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 148 ObjRecord(int objId, ObjType t) 149 { 150 super(Type.OBJ); 151 objectId = objId; 152 type = t; 153 } 154 155 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 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 IntegerHelper.getTwoBytes(0x15, data, pos); 198 199 IntegerHelper.getTwoBytes(COMMON_DATA_LENGTH-4, data, pos+2); 201 202 IntegerHelper.getTwoBytes(type.value, data, pos+4); 204 205 IntegerHelper.getTwoBytes(objectId, data, pos+6); 207 208 IntegerHelper.getTwoBytes(0x6011, data, pos+8); 210 pos += COMMON_DATA_LENGTH; 211 212 IntegerHelper.getTwoBytes(0x7, data, pos); 215 216 IntegerHelper.getTwoBytes(CLIPBOARD_FORMAT_LENGTH-4, data, pos+2); 218 219 IntegerHelper.getTwoBytes(0xffff, data, pos+4); 221 pos += CLIPBOARD_FORMAT_LENGTH; 222 223 IntegerHelper.getTwoBytes(0x8, data, pos); 226 227 IntegerHelper.getTwoBytes(PICTURE_OPTION_LENGTH-4, data, pos+2); 229 230 IntegerHelper.getTwoBytes(0x1, data, pos+4); 232 pos += CLIPBOARD_FORMAT_LENGTH; 233 234 IntegerHelper.getTwoBytes(0x0, data, pos); 237 238 IntegerHelper.getTwoBytes(END_LENGTH-4, data, pos+2); 240 241 pos += END_LENGTH; 243 244 return data; 245 } 246 247 248 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 IntegerHelper.getTwoBytes(0x15, data, pos); 262 263 IntegerHelper.getTwoBytes(COMMON_DATA_LENGTH-4, data, pos+2); 265 266 IntegerHelper.getTwoBytes(type.value, data, pos+4); 268 269 IntegerHelper.getTwoBytes(objectId, data, pos+6); 271 272 IntegerHelper.getTwoBytes(0x4011, data, pos+8); 274 pos += COMMON_DATA_LENGTH; 275 276 IntegerHelper.getTwoBytes(0xd, data, pos); 279 280 IntegerHelper.getTwoBytes(NOTE_STRUCTURE_LENGTH-4, data, pos+2); 282 283 pos += NOTE_STRUCTURE_LENGTH; 285 286 IntegerHelper.getTwoBytes(0x0, data, pos); 289 290 IntegerHelper.getTwoBytes(END_LENGTH-4, data, pos+2); 292 293 pos += END_LENGTH; 295 296 return data; 297 } 298 299 304 public Record getRecord() 305 { 306 return super.getRecord(); 307 } 308 309 314 public ObjType getType() 315 { 316 return type; 317 } 318 319 322 int getObjectId() 323 { 324 return objectId; 325 } 326 } 327 328 329 330 331 | Popular Tags |