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