1 /
55
56
57 package org.apache.poi.hssf.record;
58
59
60
61 import org.apache.poi.util.*;
62
63
70 public class LineFormatRecord
71 extends Record
72 {
73 public final static short sid = 0x1007;
74 private int field_1_lineColor;
75 private short field_2_linePattern;
76 public final static short LINE_PATTERN_SOLID = 0;
77 public final static short LINE_PATTERN_DASH = 1;
78 public final static short LINE_PATTERN_DOT = 2;
79 public final static short LINE_PATTERN_DASH_DOT = 3;
80 public final static short LINE_PATTERN_DASH_DOT_DOT = 4;
81 public final static short LINE_PATTERN_NONE = 5;
82 public final static short LINE_PATTERN_DARK_GRAY_PATTERN = 6;
83 public final static short LINE_PATTERN_MEDIUM_GRAY_PATTERN = 7;
84 public final static short LINE_PATTERN_LIGHT_GRAY_PATTERN = 8;
85 private short field_3_weight;
86 public final static short WEIGHT_HAIRLINE = -1;
87 public final static short WEIGHT_NARROW = 0;
88 public final static short WEIGHT_MEDIUM = 1;
89 public final static short WEIGHT_WIDE = 2;
90 private short field_4_format;
91 private BitField auto = new BitField(0x1);
92 private BitField drawTicks = new BitField(0x4);
93 private BitField unknown = new BitField(0x4);
94 private short field_5_colourPaletteIndex;
95
96
97 public LineFormatRecord()
98 {
99
100 }
101
102
110
111 public LineFormatRecord(short id, short size, byte [] data)
112 {
113 super(id, size, data);
114
115 }
116
117
126
127 public LineFormatRecord(short id, short size, byte [] data, int offset)
128 {
129 super(id, size, data, offset);
130
131 }
132
133
138 protected void validateSid(short id)
139 {
140 if (id != sid)
141 {
142 throw new RecordFormatException("Not a LineFormat record");
143 }
144 }
145
146 protected void fillFields(byte [] data, short size, int offset)
147 {
148
149 int pos = 0;
150 field_1_lineColor = LittleEndian.getInt(data, pos + 0x0 + offset);
151 field_2_linePattern = LittleEndian.getShort(data, pos + 0x4 + offset);
152 field_3_weight = LittleEndian.getShort(data, pos + 0x6 + offset);
153 field_4_format = LittleEndian.getShort(data, pos + 0x8 + offset);
154 field_5_colourPaletteIndex = LittleEndian.getShort(data, pos + 0xa + offset);
155
156 }
157
158 public String toString()
159 {
160 StringBuffer buffer = new StringBuffer();
161
162 buffer.append("[LINEFORMAT]\n");
163 buffer.append(" .lineColor = ")
164 .append("0x").append(HexDump.toHex( getLineColor ()))
165 .append(" (").append( getLineColor() ).append(" )");
166 buffer.append(System.getProperty("line.separator"));
167 buffer.append(" .linePattern = ")
168 .append("0x").append(HexDump.toHex( getLinePattern ()))
169 .append(" (").append( getLinePattern() ).append(" )");
170 buffer.append(System.getProperty("line.separator"));
171 buffer.append(" .weight = ")
172 .append("0x").append(HexDump.toHex( getWeight ()))
173 .append(" (").append( getWeight() ).append(" )");
174 buffer.append(System.getProperty("line.separator"));
175 buffer.append(" .format = ")
176 .append("0x").append(HexDump.toHex( getFormat ()))
177 .append(" (").append( getFormat() ).append(" )");
178 buffer.append(System.getProperty("line.separator"));
179 buffer.append(" .auto = ").append(isAuto()).append('\n');
180 buffer.append(" .drawTicks = ").append(isDrawTicks()).append('\n');
181 buffer.append(" .unknown = ").append(isUnknown()).append('\n');
182 buffer.append(" .colourPaletteIndex = ")
183 .append("0x").append(HexDump.toHex( getColourPaletteIndex ()))
184 .append(" (").append( getColourPaletteIndex() ).append(" )");
185 buffer.append(System.getProperty("line.separator"));
186
187 buffer.append("[/LINEFORMAT]\n");
188 return buffer.toString();
189 }
190
191 public int serialize(int offset, byte[] data)
192 {
193 int pos = 0;
194
195 LittleEndian.putShort(data, 0 + offset, sid);
196 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
197
198 LittleEndian.putInt(data, 4 + offset + pos, field_1_lineColor);
199 LittleEndian.putShort(data, 8 + offset + pos, field_2_linePattern);
200 LittleEndian.putShort(data, 10 + offset + pos, field_3_weight);
201 LittleEndian.putShort(data, 12 + offset + pos, field_4_format);
202 LittleEndian.putShort(data, 14 + offset + pos, field_5_colourPaletteIndex);
203
204 return getRecordSize();
205 }
206
207
210 public int getRecordSize()
211 {
212 return 4 + 4 + 2 + 2 + 2 + 2;
213 }
214
215 public short getSid()
216 {
217 return this.sid;
218 }
219
220 public Object clone() {
221 LineFormatRecord rec = new LineFormatRecord();
222
223 rec.field_1_lineColor = field_1_lineColor;
224 rec.field_2_linePattern = field_2_linePattern;
225 rec.field_3_weight = field_3_weight;
226 rec.field_4_format = field_4_format;
227 rec.field_5_colourPaletteIndex = field_5_colourPaletteIndex;
228 return rec;
229 }
230
231
232
233
234
237 public int getLineColor()
238 {
239 return field_1_lineColor;
240 }
241
242
245 public void setLineColor(int field_1_lineColor)
246 {
247 this.field_1_lineColor = field_1_lineColor;
248 }
249
250
264 public short getLinePattern()
265 {
266 return field_2_linePattern;
267 }
268
269
284 public void setLinePattern(short field_2_linePattern)
285 {
286 this.field_2_linePattern = field_2_linePattern;
287 }
288
289
298 public short getWeight()
299 {
300 return field_3_weight;
301 }
302
303
313 public void setWeight(short field_3_weight)
314 {
315 this.field_3_weight = field_3_weight;
316 }
317
318
321 public short getFormat()
322 {
323 return field_4_format;
324 }
325
326
329 public void setFormat(short field_4_format)
330 {
331 this.field_4_format = field_4_format;
332 }
333
334
337 public short getColourPaletteIndex()
338 {
339 return field_5_colourPaletteIndex;
340 }
341
342
345 public void setColourPaletteIndex(short field_5_colourPaletteIndex)
346 {
347 this.field_5_colourPaletteIndex = field_5_colourPaletteIndex;
348 }
349
350
354 public void setAuto(boolean value)
355 {
356 field_4_format = auto.setShortBoolean(field_4_format, value);
357 }
358
359
363 public boolean isAuto()
364 {
365 return auto.isSet(field_4_format);
366 }
367
368
372 public void setDrawTicks(boolean value)
373 {
374 field_4_format = drawTicks.setShortBoolean(field_4_format, value);
375 }
376
377
381 public boolean isDrawTicks()
382 {
383 return drawTicks.isSet(field_4_format);
384 }
385
386
390 public void setUnknown(boolean value)
391 {
392 field_4_format = unknown.setShortBoolean(field_4_format, value);
393 }
394
395
399 public boolean isUnknown()
400 {
401 return unknown.isSet(field_4_format);
402 }
403
404
405 }
406
407
408
409
410