1 2 /* ==================================================================== 3 * The Apache Software License, Version 1.1 4 * 5 * Copyright (c) 2002 The Apache Software Foundation. All rights 6 * reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The end-user documentation included with the redistribution, 21 * if any, must include the following acknowledgment: 22 * "This product includes software developed by the 23 * Apache Software Foundation (http://www.apache.org/)." 24 * Alternately, this acknowledgment may appear in the software itself, 25 * if and wherever such third-party acknowledgments normally appear. 26 * 27 * 4. The names "Apache" and "Apache Software Foundation" and 28 * "Apache POI" must not be used to endorse or promote products 29 * derived from this software without prior written permission. For 30 * written permission, please contact apache@apache.org. 31 * 32 * 5. Products derived from this software may not be called "Apache", 33 * "Apache POI", nor may "Apache" appear in their name, without 34 * prior written permission of the Apache Software Foundation. 35 * 36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 39 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 43 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 46 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47 * SUCH DAMAGE. 48 * ==================================================================== 49 * 50 * This software consists of voluntary contributions made by many 51 * individuals on behalf of the Apache Software Foundation. For more 52 * information on the Apache Software Foundation, please see 53 * <http://www.apache.org/>. 54 */ 55 56 57 package org.apache.poi.hssf.record; 58 59 60 61 import org.apache.poi.util.*; 62 63 /** 64 * Describes a line format record. The line format record controls how a line on a chart appears. 65 * NOTE: This source is automatically generated please do not modify this file. Either subclass or 66 * remove the record in src/records/definitions. 67 68 * @author Glen Stampoultzis (glens at apache.org) 69 */ 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 /** 103 * Constructs a LineFormat record and sets its fields appropriately. 104 * 105 * @param id id must be 0x1007 or an exception 106 * will be throw upon validation 107 * @param size size the size of the data area of the record 108 * @param data data of the record (should not contain sid/len) 109 */ 110 111 public LineFormatRecord(short id, short size, byte [] data) 112 { 113 super(id, size, data); 114 } 115 116 /** 117 * Constructs a LineFormat record and sets its fields appropriately. 118 * 119 * @param id id must be 0x1007 or an exception 120 * will be throw upon validation 121 * @param size size the size of the data area of the record 122 * @param data data of the record (should not contain sid/len) 123 * @param offset of the record's data 124 */ 125 126 public LineFormatRecord(short id, short size, byte [] data, int offset) 127 { 128 super(id, size, data, offset); 129 } 130 131 /** 132 * Checks the sid matches the expected side for this record 133 * 134 * @param id the expected sid. 135 */ 136 protected void validateSid(short id) 137 { 138 if (id != sid) 139 { 140 throw new RecordFormatException("Not a LineFormat record"); 141 } 142 } 143 144 protected void fillFields(byte [] data, short size, int offset) 145 { 146 field_1_lineColor = LittleEndian.getInt(data, 0x0 + offset); 147 field_2_linePattern = LittleEndian.getShort(data, 0x4 + offset); 148 field_3_weight = LittleEndian.getShort(data, 0x6 + offset); 149 field_4_format = LittleEndian.getShort(data, 0x8 + offset); 150 field_5_colourPaletteIndex = LittleEndian.getShort(data, 0xa + offset); 151 152 } 153 154 public String toString() 155 { 156 StringBuffer buffer = new StringBuffer(); 157 158 buffer.append("[LineFormat]\n"); 159 160 buffer.append(" .lineColor = ") 161 .append("0x") 162 .append(HexDump.toHex((int)getLineColor())) 163 .append(" (").append(getLineColor()).append(" )\n"); 164 165 buffer.append(" .linePattern = ") 166 .append("0x") 167 .append(HexDump.toHex((short)getLinePattern())) 168 .append(" (").append(getLinePattern()).append(" )\n"); 169 170 buffer.append(" .weight = ") 171 .append("0x") 172 .append(HexDump.toHex((short)getWeight())) 173 .append(" (").append(getWeight()).append(" )\n"); 174 175 buffer.append(" .format = ") 176 .append("0x") 177 .append(HexDump.toHex((short)getFormat())) 178 .append(" (").append(getFormat()).append(" )\n"); 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 183 buffer.append(" .colourPaletteIndex = ") 184 .append("0x") 185 .append(HexDump.toHex((short)getColourPaletteIndex())) 186 .append(" (").append(getColourPaletteIndex()).append(" )\n"); 187 188 buffer.append("[/LineFormat]\n"); 189 return buffer.toString(); 190 } 191 192 public int serialize(int offset, byte[] data) 193 { 194 LittleEndian.putShort(data, 0 + offset, sid); 195 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 196 197 LittleEndian.putInt(data, 4 + offset, field_1_lineColor); 198 LittleEndian.putShort(data, 8 + offset, field_2_linePattern); 199 LittleEndian.putShort(data, 10 + offset, field_3_weight); 200 LittleEndian.putShort(data, 12 + offset, field_4_format); 201 LittleEndian.putShort(data, 14 + offset, field_5_colourPaletteIndex); 202 203 return getRecordSize(); 204 } 205 206 /** 207 * Size of record (exluding 4 byte header) 208 */ 209 public int getRecordSize() 210 { 211 return 4 + 4 + 2 + 2 + 2 + 2; 212 } 213 214 public short getSid() 215 { 216 return this.sid; 217 } 218 219 220 /** 221 * Get the line color field for the LineFormat record. 222 */ 223 public int getLineColor() 224 { 225 return field_1_lineColor; 226 } 227 228 /** 229 * Set the line color field for the LineFormat record. 230 */ 231 public void setLineColor(int field_1_lineColor) 232 { 233 this.field_1_lineColor = field_1_lineColor; 234 } 235 236 /** 237 * Get the line pattern field for the LineFormat record. 238 * 239 * @return One of 240 * LINE_PATTERN_SOLID 241 * LINE_PATTERN_DASH 242 * LINE_PATTERN_DOT 243 * LINE_PATTERN_DASH_DOT 244 * LINE_PATTERN_DASH_DOT_DOT 245 * LINE_PATTERN_NONE 246 * LINE_PATTERN_DARK_GRAY_PATTERN 247 * LINE_PATTERN_MEDIUM_GRAY_PATTERN 248 * LINE_PATTERN_LIGHT_GRAY_PATTERN 249 */ 250 public short getLinePattern() 251 { 252 return field_2_linePattern; 253 } 254 255 /** 256 * Set the line pattern field for the LineFormat record. 257 * 258 * @param field_2_linePattern 259 * One of 260 * LINE_PATTERN_SOLID 261 * LINE_PATTERN_DASH 262 * LINE_PATTERN_DOT 263 * LINE_PATTERN_DASH_DOT 264 * LINE_PATTERN_DASH_DOT_DOT 265 * LINE_PATTERN_NONE 266 * LINE_PATTERN_DARK_GRAY_PATTERN 267 * LINE_PATTERN_MEDIUM_GRAY_PATTERN 268 * LINE_PATTERN_LIGHT_GRAY_PATTERN 269 */ 270 public void setLinePattern(short field_2_linePattern) 271 { 272 this.field_2_linePattern = field_2_linePattern; 273 } 274 275 /** 276 * Get the weight field for the LineFormat record. 277 * 278 * @return One of 279 * WEIGHT_HAIRLINE 280 * WEIGHT_NARROW 281 * WEIGHT_MEDIUM 282 * WEIGHT_WIDE 283 */ 284 public short getWeight() 285 { 286 return field_3_weight; 287 } 288 289 /** 290 * Set the weight field for the LineFormat record. 291 * 292 * @param field_3_weight 293 * One of 294 * WEIGHT_HAIRLINE 295 * WEIGHT_NARROW 296 * WEIGHT_MEDIUM 297 * WEIGHT_WIDE 298 */ 299 public void setWeight(short field_3_weight) 300 { 301 this.field_3_weight = field_3_weight; 302 } 303 304 /** 305 * Get the format field for the LineFormat record. 306 */ 307 public short getFormat() 308 { 309 return field_4_format; 310 } 311 312 /** 313 * Set the format field for the LineFormat record. 314 */ 315 public void setFormat(short field_4_format) 316 { 317 this.field_4_format = field_4_format; 318 } 319 320 /** 321 * Get the colour palette index field for the LineFormat record. 322 */ 323 public short getColourPaletteIndex() 324 { 325 return field_5_colourPaletteIndex; 326 } 327 328 /** 329 * Set the colour palette index field for the LineFormat record. 330 */ 331 public void setColourPaletteIndex(short field_5_colourPaletteIndex) 332 { 333 this.field_5_colourPaletteIndex = field_5_colourPaletteIndex; 334 } 335 336 /** 337 * Sets the auto field value. 338 * automatic format 339 */ 340 public void setAuto(boolean value) 341 { 342 field_4_format = auto.setShortBoolean(field_4_format, value); 343 } 344 345 /** 346 * automatic format 347 * @return the auto field value. 348 */ 349 public boolean isAuto() 350 { 351 return auto.isSet(field_4_format); 352 } 353 354 /** 355 * Sets the draw ticks field value. 356 * draw tick marks 357 */ 358 public void setDrawTicks(boolean value) 359 { 360 field_4_format = drawTicks.setShortBoolean(field_4_format, value); 361 } 362 363 /** 364 * draw tick marks 365 * @return the draw ticks field value. 366 */ 367 public boolean isDrawTicks() 368 { 369 return drawTicks.isSet(field_4_format); 370 } 371 372 /** 373 * Sets the unknown field value. 374 * book marks this as reserved = 0 but it seems to do something 375 */ 376 public void setUnknown(boolean value) 377 { 378 field_4_format = unknown.setShortBoolean(field_4_format, value); 379 } 380 381 /** 382 * book marks this as reserved = 0 but it seems to do something 383 * @return the unknown field value. 384 */ 385 public boolean isUnknown() 386 { 387 return unknown.isSet(field_4_format); 388 } 389 390 391 } // END OF CLASS 392 393 394 395 396