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.BitField;
62   import org.apache.poi.util.LittleEndian;
63   import org.apache.poi.util.StringUtil;
64   import org.apache.poi.util.HexDump;
65   
66   /**
67    * Describes a line format record.  The line format record controls how a line on a chart appears.
68    * NOTE: This source is automatically generated please do not modify this file.  Either subclass or
69    *       remove the record in src/records/definitions.
70   
71    * @author Glen Stampoultzis (glens at apache.org)
72    */
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      /**
106       * Constructs a LineFormat record and sets its fields appropriately.
107       *
108       * @param id    id must be 0x1007 or an exception
109       *              will be throw upon validation
110       * @param size  size the size of the data area of the record
111       * @param data  data of the record (should not contain sid/len)
112       */
113  
114      public LineFormatRecord(short id, short size, byte [] data)
115      {
116          super(id, size, data);
117      }
118  
119      /**
120       * Constructs a LineFormat record and sets its fields appropriately.
121       *
122       * @param id    id must be 0x1007 or an exception
123       *              will be throw upon validation
124       * @param size  size the size of the data area of the record
125       * @param data  data of the record (should not contain sid/len)
126       * @param offset of the record's data
127       */
128  
129      public LineFormatRecord(short id, short size, byte [] data, int offset)
130      {
131          super(id, size, data, offset);
132      }
133  
134      /**
135       * Checks the sid matches the expected side for this record
136       *
137       * @param id   the expected sid.
138       */
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      /**
210       * Size of record (exluding 4 byte header)
211       */
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      /**
224       * Get the line color field for the LineFormat record.
225       */
226      public int getLineColor()
227      {
228          return field_1_lineColor;
229      }
230  
231      /**
232       * Set the line color field for the LineFormat record.
233       */
234      public void setLineColor(int field_1_lineColor)
235      {
236          this.field_1_lineColor = field_1_lineColor;
237      }
238  
239      /**
240       * Get the line pattern field for the LineFormat record.
241       *
242       * @return  One of 
243       *        LINE_PATTERN_SOLID
244       *        LINE_PATTERN_DASH
245       *        LINE_PATTERN_DOT
246       *        LINE_PATTERN_DASH_DOT
247       *        LINE_PATTERN_DASH_DOT_DOT
248       *        LINE_PATTERN_NONE
249       *        LINE_PATTERN_DARK_GRAY_PATTERN
250       *        LINE_PATTERN_MEDIUM_GRAY_PATTERN
251       *        LINE_PATTERN_LIGHT_GRAY_PATTERN
252       */
253      public short getLinePattern()
254      {
255          return field_2_linePattern;
256      }
257  
258      /**
259       * Set the line pattern field for the LineFormat record.
260       *
261       * @param field_2_linePattern
262       *        One of 
263       *        LINE_PATTERN_SOLID
264       *        LINE_PATTERN_DASH
265       *        LINE_PATTERN_DOT
266       *        LINE_PATTERN_DASH_DOT
267       *        LINE_PATTERN_DASH_DOT_DOT
268       *        LINE_PATTERN_NONE
269       *        LINE_PATTERN_DARK_GRAY_PATTERN
270       *        LINE_PATTERN_MEDIUM_GRAY_PATTERN
271       *        LINE_PATTERN_LIGHT_GRAY_PATTERN
272       */
273      public void setLinePattern(short field_2_linePattern)
274      {
275          this.field_2_linePattern = field_2_linePattern;
276      }
277  
278      /**
279       * Get the weight field for the LineFormat record.
280       *
281       * @return  One of 
282       *        WEIGHT_HAIRLINE
283       *        WEIGHT_NARROW
284       *        WEIGHT_MEDIUM
285       *        WEIGHT_WIDE
286       */
287      public short getWeight()
288      {
289          return field_3_weight;
290      }
291  
292      /**
293       * Set the weight field for the LineFormat record.
294       *
295       * @param field_3_weight
296       *        One of 
297       *        WEIGHT_HAIRLINE
298       *        WEIGHT_NARROW
299       *        WEIGHT_MEDIUM
300       *        WEIGHT_WIDE
301       */
302      public void setWeight(short field_3_weight)
303      {
304          this.field_3_weight = field_3_weight;
305      }
306  
307      /**
308       * Get the format field for the LineFormat record.
309       */
310      public short getFormat()
311      {
312          return field_4_format;
313      }
314  
315      /**
316       * Set the format field for the LineFormat record.
317       */
318      public void setFormat(short field_4_format)
319      {
320          this.field_4_format = field_4_format;
321      }
322  
323      /**
324       * Get the colour palette index field for the LineFormat record.
325       */
326      public short getColourPaletteIndex()
327      {
328          return field_5_colourPaletteIndex;
329      }
330  
331      /**
332       * Set the colour palette index field for the LineFormat record.
333       */
334      public void setColourPaletteIndex(short field_5_colourPaletteIndex)
335      {
336          this.field_5_colourPaletteIndex = field_5_colourPaletteIndex;
337      }
338  
339      /**
340       * Sets the auto field value.
341       * automatic format
342       */
343      public void setAuto(boolean value)
344      {
345          field_4_format = auto.setShortBoolean(field_4_format, value);
346      }
347  
348      /**
349       * automatic format
350       * @return  the auto field value.
351       */
352      public boolean isAuto()
353      {
354          return auto.isSet(field_4_format);
355      }
356  
357      /**
358       * Sets the draw ticks field value.
359       * draw tick marks
360       */
361      public void setDrawTicks(boolean value)
362      {
363          field_4_format = drawTicks.setShortBoolean(field_4_format, value);
364      }
365  
366      /**
367       * draw tick marks
368       * @return  the draw ticks field value.
369       */
370      public boolean isDrawTicks()
371      {
372          return drawTicks.isSet(field_4_format);
373      }
374  
375      /**
376       * Sets the unknown field value.
377       * book marks this as reserved = 0 but it seems to do something
378       */
379      public void setUnknown(boolean value)
380      {
381          field_4_format = unknown.setShortBoolean(field_4_format, value);
382      }
383  
384      /**
385       * book marks this as reserved = 0 but it seems to do something
386       * @return  the unknown field value.
387       */
388      public boolean isUnknown()
389      {
390          return unknown.isSet(field_4_format);
391      }
392  
393  
394  }  // END OF CLASS
395  
396  
397  
398  
399