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      public Object clone() {
220        LineFormatRecord rec = new LineFormatRecord();
221        
222        rec.field_1_lineColor = field_1_lineColor;
223        rec.field_2_linePattern = field_2_linePattern;
224        rec.field_3_weight = field_3_weight;
225        rec.field_4_format = field_4_format;
226        rec.field_5_colourPaletteIndex = field_5_colourPaletteIndex;
227  
228        return rec;
229      }
230  
231  
232      /**
233       * Get the line color field for the LineFormat record.
234       */
235      public int getLineColor()
236      {
237          return field_1_lineColor;
238      }
239  
240      /**
241       * Set the line color field for the LineFormat record.
242       */
243      public void setLineColor(int field_1_lineColor)
244      {
245          this.field_1_lineColor = field_1_lineColor;
246      }
247  
248      /**
249       * Get the line pattern field for the LineFormat record.
250       *
251       * @return  One of 
252       *        LINE_PATTERN_SOLID
253       *        LINE_PATTERN_DASH
254       *        LINE_PATTERN_DOT
255       *        LINE_PATTERN_DASH_DOT
256       *        LINE_PATTERN_DASH_DOT_DOT
257       *        LINE_PATTERN_NONE
258       *        LINE_PATTERN_DARK_GRAY_PATTERN
259       *        LINE_PATTERN_MEDIUM_GRAY_PATTERN
260       *        LINE_PATTERN_LIGHT_GRAY_PATTERN
261       */
262      public short getLinePattern()
263      {
264          return field_2_linePattern;
265      }
266  
267      /**
268       * Set the line pattern field for the LineFormat record.
269       *
270       * @param field_2_linePattern
271       *        One of 
272       *        LINE_PATTERN_SOLID
273       *        LINE_PATTERN_DASH
274       *        LINE_PATTERN_DOT
275       *        LINE_PATTERN_DASH_DOT
276       *        LINE_PATTERN_DASH_DOT_DOT
277       *        LINE_PATTERN_NONE
278       *        LINE_PATTERN_DARK_GRAY_PATTERN
279       *        LINE_PATTERN_MEDIUM_GRAY_PATTERN
280       *        LINE_PATTERN_LIGHT_GRAY_PATTERN
281       */
282      public void setLinePattern(short field_2_linePattern)
283      {
284          this.field_2_linePattern = field_2_linePattern;
285      }
286  
287      /**
288       * Get the weight field for the LineFormat record.
289       *
290       * @return  One of 
291       *        WEIGHT_HAIRLINE
292       *        WEIGHT_NARROW
293       *        WEIGHT_MEDIUM
294       *        WEIGHT_WIDE
295       */
296      public short getWeight()
297      {
298          return field_3_weight;
299      }
300  
301      /**
302       * Set the weight field for the LineFormat record.
303       *
304       * @param field_3_weight
305       *        One of 
306       *        WEIGHT_HAIRLINE
307       *        WEIGHT_NARROW
308       *        WEIGHT_MEDIUM
309       *        WEIGHT_WIDE
310       */
311      public void setWeight(short field_3_weight)
312      {
313          this.field_3_weight = field_3_weight;
314      }
315  
316      /**
317       * Get the format field for the LineFormat record.
318       */
319      public short getFormat()
320      {
321          return field_4_format;
322      }
323  
324      /**
325       * Set the format field for the LineFormat record.
326       */
327      public void setFormat(short field_4_format)
328      {
329          this.field_4_format = field_4_format;
330      }
331  
332      /**
333       * Get the colour palette index field for the LineFormat record.
334       */
335      public short getColourPaletteIndex()
336      {
337          return field_5_colourPaletteIndex;
338      }
339  
340      /**
341       * Set the colour palette index field for the LineFormat record.
342       */
343      public void setColourPaletteIndex(short field_5_colourPaletteIndex)
344      {
345          this.field_5_colourPaletteIndex = field_5_colourPaletteIndex;
346      }
347  
348      /**
349       * Sets the auto field value.
350       * automatic format
351       */
352      public void setAuto(boolean value)
353      {
354          field_4_format = auto.setShortBoolean(field_4_format, value);
355      }
356  
357      /**
358       * automatic format
359       * @return  the auto field value.
360       */
361      public boolean isAuto()
362      {
363          return auto.isSet(field_4_format);
364      }
365  
366      /**
367       * Sets the draw ticks field value.
368       * draw tick marks
369       */
370      public void setDrawTicks(boolean value)
371      {
372          field_4_format = drawTicks.setShortBoolean(field_4_format, value);
373      }
374  
375      /**
376       * draw tick marks
377       * @return  the draw ticks field value.
378       */
379      public boolean isDrawTicks()
380      {
381          return drawTicks.isSet(field_4_format);
382      }
383  
384      /**
385       * Sets the unknown field value.
386       * book marks this as reserved = 0 but it seems to do something
387       */
388      public void setUnknown(boolean value)
389      {
390          field_4_format = unknown.setShortBoolean(field_4_format, value);
391      }
392  
393      /**
394       * book marks this as reserved = 0 but it seems to do something
395       * @return  the unknown field value.
396       */
397      public boolean isUnknown()
398      {
399          return unknown.isSet(field_4_format);
400      }
401  
402  
403  }  // END OF CLASS
404  
405  
406  
407  
408