1 /
55
56
57 package org.apache.poi.hssf.record;
58
59
60
61 import org.apache.poi.util.BitField;
62 import org.apache.poi.util.LittleEndian;
63 import org.apache.poi.util.StringUtil;
64 import org.apache.poi.util.HexDump;
65
66
73 public class LineFormatRecord
74 extends Record
75 {
76 public final static short sid = 0x1007;
77 private int field_1_lineColor;
78 private short field_2_linePattern;
79 public final static short LINE_PATTERN_SOLID = 0;
80 public final static short LINE_PATTERN_DASH = 1;
81 public final static short LINE_PATTERN_DOT = 2;
82 public final static short LINE_PATTERN_DASH_DOT = 3;
83 public final static short LINE_PATTERN_DASH_DOT_DOT = 4;
84 public final static short LINE_PATTERN_NONE = 5;
85 public final static short LINE_PATTERN_DARK_GRAY_PATTERN = 6;
86 public final static short LINE_PATTERN_MEDIUM_GRAY_PATTERN = 7;
87 public final static short LINE_PATTERN_LIGHT_GRAY_PATTERN = 8;
88 private short field_3_weight;
89 public final static short WEIGHT_HAIRLINE = -1;
90 public final static short WEIGHT_NARROW = 0;
91 public final static short WEIGHT_MEDIUM = 1;
92 public final static short WEIGHT_WIDE = 2;
93 private short field_4_format;
94 private BitField auto = new BitField(0x1);
95 private BitField drawTicks = new BitField(0x4);
96 private BitField unknown = new BitField(0x4);
97 private short field_5_colourPaletteIndex;
98
99
100 public LineFormatRecord()
101 {
102
103 }
104
105
113
114 public LineFormatRecord(short id, short size, byte [] data)
115 {
116 super(id, size, data);
117 }
118
119
128
129 public LineFormatRecord(short id, short size, byte [] data, int offset)
130 {
131 super(id, size, data, offset);
132 }
133
134
139 protected void validateSid(short id)
140 {
141 if (id != sid)
142 {
143 throw new RecordFormatException("Not a LineFormat record");
144 }
145 }
146
147 protected void fillFields(byte [] data, short size, int offset)
148 {
149 field_1_lineColor = LittleEndian.getInt(data, 0x0 + offset);
150 field_2_linePattern = LittleEndian.getShort(data, 0x4 + offset);
151 field_3_weight = LittleEndian.getShort(data, 0x6 + offset);
152 field_4_format = LittleEndian.getShort(data, 0x8 + offset);
153 field_5_colourPaletteIndex = LittleEndian.getShort(data, 0xa + offset);
154
155 }
156
157 public String toString()
158 {
159 StringBuffer buffer = new StringBuffer();
160
161 buffer.append("[LineFormat]\n");
162
163 buffer.append(" .lineColor = ")
164 .append("0x")
165 .append(HexDump.toHex((int)getLineColor()))
166 .append(" (").append(getLineColor()).append(" )\n");
167
168 buffer.append(" .linePattern = ")
169 .append("0x")
170 .append(HexDump.toHex((short)getLinePattern()))
171 .append(" (").append(getLinePattern()).append(" )\n");
172
173 buffer.append(" .weight = ")
174 .append("0x")
175 .append(HexDump.toHex((short)getWeight()))
176 .append(" (").append(getWeight()).append(" )\n");
177
178 buffer.append(" .format = ")
179 .append("0x")
180 .append(HexDump.toHex((short)getFormat()))
181 .append(" (").append(getFormat()).append(" )\n");
182 buffer.append(" .auto = ").append(isAuto ()).append('\n');
183 buffer.append(" .drawTicks = ").append(isDrawTicks ()).append('\n');
184 buffer.append(" .unknown = ").append(isUnknown ()).append('\n');
185
186 buffer.append(" .colourPaletteIndex = ")
187 .append("0x")
188 .append(HexDump.toHex((short)getColourPaletteIndex()))
189 .append(" (").append(getColourPaletteIndex()).append(" )\n");
190
191 buffer.append("[/LineFormat]\n");
192 return buffer.toString();
193 }
194
195 public int serialize(int offset, byte[] data)
196 {
197 LittleEndian.putShort(data, 0 + offset, sid);
198 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
199
200 LittleEndian.putInt(data, 4 + offset, field_1_lineColor);
201 LittleEndian.putShort(data, 8 + offset, field_2_linePattern);
202 LittleEndian.putShort(data, 10 + offset, field_3_weight);
203 LittleEndian.putShort(data, 12 + offset, field_4_format);
204 LittleEndian.putShort(data, 14 + offset, field_5_colourPaletteIndex);
205
206 return getRecordSize();
207 }
208
209
212 public int getRecordSize()
213 {
214 return 4 + 4 + 2 + 2 + 2 + 2;
215 }
216
217 public short getSid()
218 {
219 return this.sid;
220 }
221
222
223
226 public int getLineColor()
227 {
228 return field_1_lineColor;
229 }
230
231
234 public void setLineColor(int field_1_lineColor)
235 {
236 this.field_1_lineColor = field_1_lineColor;
237 }
238
239
253 public short getLinePattern()
254 {
255 return field_2_linePattern;
256 }
257
258
273 public void setLinePattern(short field_2_linePattern)
274 {
275 this.field_2_linePattern = field_2_linePattern;
276 }
277
278
287 public short getWeight()
288 {
289 return field_3_weight;
290 }
291
292
302 public void setWeight(short field_3_weight)
303 {
304 this.field_3_weight = field_3_weight;
305 }
306
307
310 public short getFormat()
311 {
312 return field_4_format;
313 }
314
315
318 public void setFormat(short field_4_format)
319 {
320 this.field_4_format = field_4_format;
321 }
322
323
326 public short getColourPaletteIndex()
327 {
328 return field_5_colourPaletteIndex;
329 }
330
331
334 public void setColourPaletteIndex(short field_5_colourPaletteIndex)
335 {
336 this.field_5_colourPaletteIndex = field_5_colourPaletteIndex;
337 }
338
339
343 public void setAuto(boolean value)
344 {
345 field_4_format = auto.setShortBoolean(field_4_format, value);
346 }
347
348
352 public boolean isAuto()
353 {
354 return auto.isSet(field_4_format);
355 }
356
357
361 public void setDrawTicks(boolean value)
362 {
363 field_4_format = drawTicks.setShortBoolean(field_4_format, value);
364 }
365
366
370 public boolean isDrawTicks()
371 {
372 return drawTicks.isSet(field_4_format);
373 }
374
375
379 public void setUnknown(boolean value)
380 {
381 field_4_format = unknown.setShortBoolean(field_4_format, value);
382 }
383
384
388 public boolean isUnknown()
389 {
390 return unknown.isSet(field_4_format);
391 }
392
393
394 }
395
396
397
398
399