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      /**
118       * Constructs a LineFormat record and sets its fields appropriately.
119       *
120       * @param id    id must be 0x1007 or an exception
121       *              will be throw upon validation
122       * @param size  size the size of the data area of the record
123       * @param data  data of the record (should not contain sid/len)
124       * @param offset of the record's data
125       */
126  
127      public LineFormatRecord(short id, short size, byte [] data, int offset)
128      {
129          super(id, size, data, offset);
130      
131      }
132  
133      /**
134       * Checks the sid matches the expected side for this record
135       *
136       * @param id   the expected sid.
137       */
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      /**
208       * Size of record (exluding 4 byte header)
209       */
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      /**
235       * Get the line color field for the LineFormat record.
236       */
237      public int getLineColor()
238      {
239          return field_1_lineColor;
240      }
241  
242      /**
243       * Set the line color field for the LineFormat record.
244       */
245      public void setLineColor(int field_1_lineColor)
246      {
247          this.field_1_lineColor = field_1_lineColor;
248      }
249  
250      /**
251       * Get the line pattern field for the LineFormat record.
252       *
253       * @return  One of 
254       *        LINE_PATTERN_SOLID
255       *        LINE_PATTERN_DASH
256       *        LINE_PATTERN_DOT
257       *        LINE_PATTERN_DASH_DOT
258       *        LINE_PATTERN_DASH_DOT_DOT
259       *        LINE_PATTERN_NONE
260       *        LINE_PATTERN_DARK_GRAY_PATTERN
261       *        LINE_PATTERN_MEDIUM_GRAY_PATTERN
262       *        LINE_PATTERN_LIGHT_GRAY_PATTERN
263       */
264      public short getLinePattern()
265      {
266          return field_2_linePattern;
267      }
268  
269      /**
270       * Set the line pattern field for the LineFormat record.
271       *
272       * @param field_2_linePattern
273       *        One of 
274       *        LINE_PATTERN_SOLID
275       *        LINE_PATTERN_DASH
276       *        LINE_PATTERN_DOT
277       *        LINE_PATTERN_DASH_DOT
278       *        LINE_PATTERN_DASH_DOT_DOT
279       *        LINE_PATTERN_NONE
280       *        LINE_PATTERN_DARK_GRAY_PATTERN
281       *        LINE_PATTERN_MEDIUM_GRAY_PATTERN
282       *        LINE_PATTERN_LIGHT_GRAY_PATTERN
283       */
284      public void setLinePattern(short field_2_linePattern)
285      {
286          this.field_2_linePattern = field_2_linePattern;
287      }
288  
289      /**
290       * Get the weight field for the LineFormat record.
291       *
292       * @return  One of 
293       *        WEIGHT_HAIRLINE
294       *        WEIGHT_NARROW
295       *        WEIGHT_MEDIUM
296       *        WEIGHT_WIDE
297       */
298      public short getWeight()
299      {
300          return field_3_weight;
301      }
302  
303      /**
304       * Set the weight field for the LineFormat record.
305       *
306       * @param field_3_weight
307       *        One of 
308       *        WEIGHT_HAIRLINE
309       *        WEIGHT_NARROW
310       *        WEIGHT_MEDIUM
311       *        WEIGHT_WIDE
312       */
313      public void setWeight(short field_3_weight)
314      {
315          this.field_3_weight = field_3_weight;
316      }
317  
318      /**
319       * Get the format field for the LineFormat record.
320       */
321      public short getFormat()
322      {
323          return field_4_format;
324      }
325  
326      /**
327       * Set the format field for the LineFormat record.
328       */
329      public void setFormat(short field_4_format)
330      {
331          this.field_4_format = field_4_format;
332      }
333  
334      /**
335       * Get the colour palette index field for the LineFormat record.
336       */
337      public short getColourPaletteIndex()
338      {
339          return field_5_colourPaletteIndex;
340      }
341  
342      /**
343       * Set the colour palette index field for the LineFormat record.
344       */
345      public void setColourPaletteIndex(short field_5_colourPaletteIndex)
346      {
347          this.field_5_colourPaletteIndex = field_5_colourPaletteIndex;
348      }
349  
350      /**
351       * Sets the auto field value.
352       * automatic format
353       */
354      public void setAuto(boolean value)
355      {
356          field_4_format = auto.setShortBoolean(field_4_format, value);
357      }
358  
359      /**
360       * automatic format
361       * @return  the auto field value.
362       */
363      public boolean isAuto()
364      {
365          return auto.isSet(field_4_format);
366      }
367  
368      /**
369       * Sets the draw ticks field value.
370       * draw tick marks
371       */
372      public void setDrawTicks(boolean value)
373      {
374          field_4_format = drawTicks.setShortBoolean(field_4_format, value);
375      }
376  
377      /**
378       * draw tick marks
379       * @return  the draw ticks field value.
380       */
381      public boolean isDrawTicks()
382      {
383          return drawTicks.isSet(field_4_format);
384      }
385  
386      /**
387       * Sets the unknown field value.
388       * book marks this as reserved = 0 but it seems to do something
389       */
390      public void setUnknown(boolean value)
391      {
392          field_4_format = unknown.setShortBoolean(field_4_format, value);
393      }
394  
395      /**
396       * book marks this as reserved = 0 but it seems to do something
397       * @return  the unknown field value.
398       */
399      public boolean isUnknown()
400      {
401          return unknown.isSet(field_4_format);
402      }
403  
404  
405  }  // END OF CLASS
406  
407  
408  
409  
410