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    * The legend record specifies the location of legend on a chart and it's overall size.
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 LegendRecord
74       extends Record
75   {
76       public final static short      sid                             = 0x1015;
77       private  int        field_1_xPosition;
78       private  int        field_2_yPosition;
79       private  int        field_3_xSize;
80       private  int        field_4_ySize;
81       private  byte       field_5_type;
82       public final static byte        TYPE_BOTTOM                    = 0;
83       public final static byte        TYPE_CORNER                    = 1;
84       public final static byte        TYPE_TOP                       = 2;
85       public final static byte        TYPE_RIGHT                     = 3;
86       public final static byte        TYPE_LEFT                      = 4;
87       public final static byte        TYPE_NOT_DOCKED                = 7;
88       private  byte       field_6_spacing;
89       public final static byte        SPACING_CLOSE                  = 0;
90       public final static byte        SPACING_MEDIUM                 = 1;
91       public final static byte        SPACING_OPEN                   = 2;
92       private  short      field_7_options;
93       private BitField   autoPosition                               = new BitField(0x1);
94       private BitField   autoSeries                                 = new BitField(0x2);
95       private BitField   autoPosX                                   = new BitField(0x4);
96       private BitField   autoPosY                                   = new BitField(0x8);
97       private BitField   vert                                       = new BitField(0x10);
98       private BitField   containsDataTable                          = new BitField(0x20);
99   
100  
101      public LegendRecord()
102      {
103  
104      }
105  
106      /**
107       * Constructs a Legend record and sets its fields appropriately.
108       *
109       * @param id    id must be 0x1015 or an exception
110       *              will be throw upon validation
111       * @param size  size the size of the data area of the record
112       * @param data  data of the record (should not contain sid/len)
113       */
114  
115      public LegendRecord(short id, short size, byte [] data)
116      {
117          super(id, size, data);
118      }
119  
120      /**
121       * Constructs a Legend record and sets its fields appropriately.
122       *
123       * @param id    id must be 0x1015 or an exception
124       *              will be throw upon validation
125       * @param size  size the size of the data area of the record
126       * @param data  data of the record (should not contain sid/len)
127       * @param offset of the record's data
128       */
129  
130      public LegendRecord(short id, short size, byte [] data, int offset)
131      {
132          super(id, size, data, offset);
133      }
134  
135      /**
136       * Checks the sid matches the expected side for this record
137       *
138       * @param id   the expected sid.
139       */
140      protected void validateSid(short id)
141      {
142          if (id != sid)
143          {
144              throw new RecordFormatException("Not a Legend record");
145          }
146      }
147  
148      protected void fillFields(byte [] data, short size, int offset)
149      {
150          field_1_xPosition               = LittleEndian.getInt(data, 0x0 + offset);
151          field_2_yPosition               = LittleEndian.getInt(data, 0x4 + offset);
152          field_3_xSize                   = LittleEndian.getInt(data, 0x8 + offset);
153          field_4_ySize                   = LittleEndian.getInt(data, 0xc + offset);
154          field_5_type                    = data[ 0x10 + offset ];
155          field_6_spacing                 = data[ 0x11 + offset ];
156          field_7_options                 = LittleEndian.getShort(data, 0x12 + offset);
157  
158      }
159  
160      public String toString()
161      {
162          StringBuffer buffer = new StringBuffer();
163  
164          buffer.append("[Legend]\n");
165  
166          buffer.append("    .xPosition            = ")
167              .append("0x")
168              .append(HexDump.toHex((int)getXPosition()))
169              .append(" (").append(getXPosition()).append(" )\n");
170  
171          buffer.append("    .yPosition            = ")
172              .append("0x")
173              .append(HexDump.toHex((int)getYPosition()))
174              .append(" (").append(getYPosition()).append(" )\n");
175  
176          buffer.append("    .xSize                = ")
177              .append("0x")
178              .append(HexDump.toHex((int)getXSize()))
179              .append(" (").append(getXSize()).append(" )\n");
180  
181          buffer.append("    .ySize                = ")
182              .append("0x")
183              .append(HexDump.toHex((int)getYSize()))
184              .append(" (").append(getYSize()).append(" )\n");
185  
186          buffer.append("    .type                 = ")
187              .append("0x")
188              .append(HexDump.toHex((byte)getType()))
189              .append(" (").append(getType()).append(" )\n");
190  
191          buffer.append("    .spacing              = ")
192              .append("0x")
193              .append(HexDump.toHex((byte)getSpacing()))
194              .append(" (").append(getSpacing()).append(" )\n");
195  
196          buffer.append("    .options              = ")
197              .append("0x")
198              .append(HexDump.toHex((short)getOptions()))
199              .append(" (").append(getOptions()).append(" )\n");
200          buffer.append("         .autoPosition             = ").append(isAutoPosition        ()).append('\n');
201          buffer.append("         .autoSeries               = ").append(isAutoSeries          ()).append('\n');
202          buffer.append("         .autoPosX                 = ").append(isAutoPosX            ()).append('\n');
203          buffer.append("         .autoPosY                 = ").append(isAutoPosY            ()).append('\n');
204          buffer.append("         .vert                     = ").append(isVert                ()).append('\n');
205          buffer.append("         .containsDataTable        = ").append(isContainsDataTable   ()).append('\n');
206  
207          buffer.append("[/Legend]\n");
208          return buffer.toString();
209      }
210  
211      public int serialize(int offset, byte[] data)
212      {
213          LittleEndian.putShort(data, 0 + offset, sid);
214          LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
215  
216          LittleEndian.putInt(data, 4 + offset, field_1_xPosition);
217          LittleEndian.putInt(data, 8 + offset, field_2_yPosition);
218          LittleEndian.putInt(data, 12 + offset, field_3_xSize);
219          LittleEndian.putInt(data, 16 + offset, field_4_ySize);
220          data[ 20 + offset ] = field_5_type;
221          data[ 21 + offset ] = field_6_spacing;
222          LittleEndian.putShort(data, 22 + offset, field_7_options);
223  
224          return getRecordSize();
225      }
226  
227      /**
228       * Size of record (exluding 4 byte header)
229       */
230      public int getRecordSize()
231      {
232          return 4 + 4 + 4 + 4 + 4 + 1 + 1 + 2;
233      }
234  
235      public short getSid()
236      {
237          return this.sid;
238      }
239  
240  
241      /**
242       * Get the x position field for the Legend record.
243       */
244      public int getXPosition()
245      {
246          return field_1_xPosition;
247      }
248  
249      /**
250       * Set the x position field for the Legend record.
251       */
252      public void setXPosition(int field_1_xPosition)
253      {
254          this.field_1_xPosition = field_1_xPosition;
255      }
256  
257      /**
258       * Get the y position field for the Legend record.
259       */
260      public int getYPosition()
261      {
262          return field_2_yPosition;
263      }
264  
265      /**
266       * Set the y position field for the Legend record.
267       */
268      public void setYPosition(int field_2_yPosition)
269      {
270          this.field_2_yPosition = field_2_yPosition;
271      }
272  
273      /**
274       * Get the x size field for the Legend record.
275       */
276      public int getXSize()
277      {
278          return field_3_xSize;
279      }
280  
281      /**
282       * Set the x size field for the Legend record.
283       */
284      public void setXSize(int field_3_xSize)
285      {
286          this.field_3_xSize = field_3_xSize;
287      }
288  
289      /**
290       * Get the y size field for the Legend record.
291       */
292      public int getYSize()
293      {
294          return field_4_ySize;
295      }
296  
297      /**
298       * Set the y size field for the Legend record.
299       */
300      public void setYSize(int field_4_ySize)
301      {
302          this.field_4_ySize = field_4_ySize;
303      }
304  
305      /**
306       * Get the type field for the Legend record.
307       *
308       * @return  One of 
309       *        TYPE_BOTTOM
310       *        TYPE_CORNER
311       *        TYPE_TOP
312       *        TYPE_RIGHT
313       *        TYPE_LEFT
314       *        TYPE_NOT_DOCKED
315       */
316      public byte getType()
317      {
318          return field_5_type;
319      }
320  
321      /**
322       * Set the type field for the Legend record.
323       *
324       * @param field_5_type
325       *        One of 
326       *        TYPE_BOTTOM
327       *        TYPE_CORNER
328       *        TYPE_TOP
329       *        TYPE_RIGHT
330       *        TYPE_LEFT
331       *        TYPE_NOT_DOCKED
332       */
333      public void setType(byte field_5_type)
334      {
335          this.field_5_type = field_5_type;
336      }
337  
338      /**
339       * Get the spacing field for the Legend record.
340       *
341       * @return  One of 
342       *        SPACING_CLOSE
343       *        SPACING_MEDIUM
344       *        SPACING_OPEN
345       */
346      public byte getSpacing()
347      {
348          return field_6_spacing;
349      }
350  
351      /**
352       * Set the spacing field for the Legend record.
353       *
354       * @param field_6_spacing
355       *        One of 
356       *        SPACING_CLOSE
357       *        SPACING_MEDIUM
358       *        SPACING_OPEN
359       */
360      public void setSpacing(byte field_6_spacing)
361      {
362          this.field_6_spacing = field_6_spacing;
363      }
364  
365      /**
366       * Get the options field for the Legend record.
367       */
368      public short getOptions()
369      {
370          return field_7_options;
371      }
372  
373      /**
374       * Set the options field for the Legend record.
375       */
376      public void setOptions(short field_7_options)
377      {
378          this.field_7_options = field_7_options;
379      }
380  
381      /**
382       * Sets the auto position field value.
383       * set to true if legend is docked
384       */
385      public void setAutoPosition(boolean value)
386      {
387          field_7_options = autoPosition.setShortBoolean(field_7_options, value);
388      }
389  
390      /**
391       * set to true if legend is docked
392       * @return  the auto position field value.
393       */
394      public boolean isAutoPosition()
395      {
396          return autoPosition.isSet(field_7_options);
397      }
398  
399      /**
400       * Sets the auto series field value.
401       * automatic series distribution
402       */
403      public void setAutoSeries(boolean value)
404      {
405          field_7_options = autoSeries.setShortBoolean(field_7_options, value);
406      }
407  
408      /**
409       * automatic series distribution
410       * @return  the auto series field value.
411       */
412      public boolean isAutoSeries()
413      {
414          return autoSeries.isSet(field_7_options);
415      }
416  
417      /**
418       * Sets the auto pos x field value.
419       * x positioning is done automatically
420       */
421      public void setAutoPosX(boolean value)
422      {
423          field_7_options = autoPosX.setShortBoolean(field_7_options, value);
424      }
425  
426      /**
427       * x positioning is done automatically
428       * @return  the auto pos x field value.
429       */
430      public boolean isAutoPosX()
431      {
432          return autoPosX.isSet(field_7_options);
433      }
434  
435      /**
436       * Sets the auto pos y field value.
437       * y positioning is done automatically
438       */
439      public void setAutoPosY(boolean value)
440      {
441          field_7_options = autoPosY.setShortBoolean(field_7_options, value);
442      }
443  
444      /**
445       * y positioning is done automatically
446       * @return  the auto pos y field value.
447       */
448      public boolean isAutoPosY()
449      {
450          return autoPosY.isSet(field_7_options);
451      }
452  
453      /**
454       * Sets the vert field value.
455       * if true legend is vertical (otherwise it's horizonal)
456       */
457      public void setVert(boolean value)
458      {
459          field_7_options = vert.setShortBoolean(field_7_options, value);
460      }
461  
462      /**
463       * if true legend is vertical (otherwise it's horizonal)
464       * @return  the vert field value.
465       */
466      public boolean isVert()
467      {
468          return vert.isSet(field_7_options);
469      }
470  
471      /**
472       * Sets the contains data table field value.
473       * true if the chart contains the data table
474       */
475      public void setContainsDataTable(boolean value)
476      {
477          field_7_options = containsDataTable.setShortBoolean(field_7_options, value);
478      }
479  
480      /**
481       * true if the chart contains the data table
482       * @return  the contains data table field value.
483       */
484      public boolean isContainsDataTable()
485      {
486          return containsDataTable.isSet(field_7_options);
487      }
488  
489  
490  }  // END OF CLASS
491  
492  
493  
494  
495