1 2 17 18 19 20 package org.apache.poi.hssf.record; 21 22 23 24 import org.apache.poi.util.*; 25 26 33 public class ChartRecord 34 extends Record 35 { 36 public final static short sid = 0x1002; 37 private int field_1_x; 38 private int field_2_y; 39 private int field_3_width; 40 private int field_4_height; 41 42 43 public ChartRecord() 44 { 45 46 } 47 48 56 57 public ChartRecord(short id, short size, byte [] data) 58 { 59 super(id, size, data); 60 61 } 62 63 72 73 public ChartRecord(short id, short size, byte [] data, int offset) 74 { 75 super(id, size, data, offset); 76 77 } 78 79 84 protected void validateSid(short id) 85 { 86 if (id != sid) 87 { 88 throw new RecordFormatException("Not a Chart record"); 89 } 90 } 91 92 protected void fillFields(byte [] data, short size, int offset) 93 { 94 95 int pos = 0; 96 field_1_x = LittleEndian.getInt(data, pos + 0x0 + offset); 97 field_2_y = LittleEndian.getInt(data, pos + 0x4 + offset); 98 field_3_width = LittleEndian.getInt(data, pos + 0x8 + offset); 99 field_4_height = LittleEndian.getInt(data, pos + 0xc + offset); 100 101 } 102 103 public String toString() 104 { 105 StringBuffer buffer = new StringBuffer (); 106 107 buffer.append("[CHART]\n"); 108 buffer.append(" .x = ") 109 .append("0x").append(HexDump.toHex( getX ())) 110 .append(" (").append( getX() ).append(" )"); 111 buffer.append(System.getProperty("line.separator")); 112 buffer.append(" .y = ") 113 .append("0x").append(HexDump.toHex( getY ())) 114 .append(" (").append( getY() ).append(" )"); 115 buffer.append(System.getProperty("line.separator")); 116 buffer.append(" .width = ") 117 .append("0x").append(HexDump.toHex( getWidth ())) 118 .append(" (").append( getWidth() ).append(" )"); 119 buffer.append(System.getProperty("line.separator")); 120 buffer.append(" .height = ") 121 .append("0x").append(HexDump.toHex( getHeight ())) 122 .append(" (").append( getHeight() ).append(" )"); 123 buffer.append(System.getProperty("line.separator")); 124 125 buffer.append("[/CHART]\n"); 126 return buffer.toString(); 127 } 128 129 public int serialize(int offset, byte[] data) 130 { 131 int pos = 0; 132 133 LittleEndian.putShort(data, 0 + offset, sid); 134 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 135 136 LittleEndian.putInt(data, 4 + offset + pos, field_1_x); 137 LittleEndian.putInt(data, 8 + offset + pos, field_2_y); 138 LittleEndian.putInt(data, 12 + offset + pos, field_3_width); 139 LittleEndian.putInt(data, 16 + offset + pos, field_4_height); 140 141 return getRecordSize(); 142 } 143 144 147 public int getRecordSize() 148 { 149 return 4 + 4 + 4 + 4 + 4; 150 } 151 152 public short getSid() 153 { 154 return this.sid; 155 } 156 157 public Object clone() { 158 ChartRecord rec = new ChartRecord(); 159 160 rec.field_1_x = field_1_x; 161 rec.field_2_y = field_2_y; 162 rec.field_3_width = field_3_width; 163 rec.field_4_height = field_4_height; 164 return rec; 165 } 166 167 168 169 170 173 public int getX() 174 { 175 return field_1_x; 176 } 177 178 181 public void setX(int field_1_x) 182 { 183 this.field_1_x = field_1_x; 184 } 185 186 189 public int getY() 190 { 191 return field_2_y; 192 } 193 194 197 public void setY(int field_2_y) 198 { 199 this.field_2_y = field_2_y; 200 } 201 202 205 public int getWidth() 206 { 207 return field_3_width; 208 } 209 210 213 public void setWidth(int field_3_width) 214 { 215 this.field_3_width = field_3_width; 216 } 217 218 221 public int getHeight() 222 { 223 return field_4_height; 224 } 225 226 229 public void setHeight(int field_4_height) 230 { 231 this.field_4_height = field_4_height; 232 } 233 234 235 } 237 238 239 240 | Popular Tags |