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    * Defines a legend for a chart.
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 Andrew C. Oliver (acoliver at apache.org)
69    */
70   public class LegendRecord
71       extends Record
72   {
73       public final static short      sid                             = 0x1015;
74       private  int        field_1_xAxisUpperLeft;
75       private  int        field_2_yAxisUpperLeft;
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_UNDOCKED                  = 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   autoXPositioning                            = new BitField(0x4);
93       private  BitField   autoYPositioning                            = new BitField(0x8);
94       private  BitField   vertical                                    = new BitField(0x10);
95       private  BitField   dataTable                                   = 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      /**
119       * Constructs a Legend record and sets its fields appropriately.
120       *
121       * @param id    id must be 0x1015 or an exception
122       *              will be throw upon validation
123       * @param size  size the size of the data area of the record
124       * @param data  data of the record (should not contain sid/len)
125       * @param offset of the record's data
126       */
127  
128      public LegendRecord(short id, short size, byte [] data, int offset)
129      {
130          super(id, size, data, offset);
131      
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 Legend record");
144          }
145      }
146  
147      protected void fillFields(byte [] data, short size, int offset)
148      {
149  
150          int pos = 0;
151          field_1_xAxisUpperLeft         = LittleEndian.getInt(data, pos + 0x0 + offset);
152          field_2_yAxisUpperLeft         = LittleEndian.getInt(data, pos + 0x4 + offset);
153          field_3_xSize                  = LittleEndian.getInt(data, pos + 0x8 + offset);
154          field_4_ySize                  = LittleEndian.getInt(data, pos + 0xc + offset);
155          field_5_type                   = data[ pos + 0x10 + offset ];
156          field_6_spacing                = data[ pos + 0x11 + offset ];
157          field_7_options                = LittleEndian.getShort(data, pos + 0x12 + offset);
158  
159      }
160  
161      public String toString()
162      {
163          StringBuffer buffer = new StringBuffer();
164  
165          buffer.append("[LEGEND]\n");
166          buffer.append("    .xAxisUpperLeft       = ")
167              .append("0x").append(HexDump.toHex(  getXAxisUpperLeft ()))
168              .append(" (").append( getXAxisUpperLeft() ).append(" )");
169          buffer.append(System.getProperty("line.separator")); 
170          buffer.append("    .yAxisUpperLeft       = ")
171              .append("0x").append(HexDump.toHex(  getYAxisUpperLeft ()))
172              .append(" (").append( getYAxisUpperLeft() ).append(" )");
173          buffer.append(System.getProperty("line.separator")); 
174          buffer.append("    .xSize                = ")
175              .append("0x").append(HexDump.toHex(  getXSize ()))
176              .append(" (").append( getXSize() ).append(" )");
177          buffer.append(System.getProperty("line.separator")); 
178          buffer.append("    .ySize                = ")
179              .append("0x").append(HexDump.toHex(  getYSize ()))
180              .append(" (").append( getYSize() ).append(" )");
181          buffer.append(System.getProperty("line.separator")); 
182          buffer.append("    .type                 = ")
183              .append("0x").append(HexDump.toHex(  getType ()))
184              .append(" (").append( getType() ).append(" )");
185          buffer.append(System.getProperty("line.separator")); 
186          buffer.append("    .spacing              = ")
187              .append("0x").append(HexDump.toHex(  getSpacing ()))
188              .append(" (").append( getSpacing() ).append(" )");
189          buffer.append(System.getProperty("line.separator")); 
190          buffer.append("    .options              = ")
191              .append("0x").append(HexDump.toHex(  getOptions ()))
192              .append(" (").append( getOptions() ).append(" )");
193          buffer.append(System.getProperty("line.separator")); 
194          buffer.append("         .autoPosition             = ").append(isAutoPosition()).append('\n'); 
195          buffer.append("         .autoSeries               = ").append(isAutoSeries()).append('\n'); 
196          buffer.append("         .autoXPositioning         = ").append(isAutoXPositioning()).append('\n'); 
197          buffer.append("         .autoYPositioning         = ").append(isAutoYPositioning()).append('\n'); 
198          buffer.append("         .vertical                 = ").append(isVertical()).append('\n'); 
199          buffer.append("         .dataTable                = ").append(isDataTable()).append('\n'); 
200  
201          buffer.append("[/LEGEND]\n");
202          return buffer.toString();
203      }
204  
205      public int serialize(int offset, byte[] data)
206      {
207          int pos = 0;
208  
209          LittleEndian.putShort(data, 0 + offset, sid);
210          LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
211  
212          LittleEndian.putInt(data, 4 + offset + pos, field_1_xAxisUpperLeft);
213          LittleEndian.putInt(data, 8 + offset + pos, field_2_yAxisUpperLeft);
214          LittleEndian.putInt(data, 12 + offset + pos, field_3_xSize);
215          LittleEndian.putInt(data, 16 + offset + pos, field_4_ySize);
216          data[ 20 + offset + pos ] = field_5_type;
217          data[ 21 + offset + pos ] = field_6_spacing;
218          LittleEndian.putShort(data, 22 + offset + pos, field_7_options);
219  
220          return getRecordSize();
221      }
222  
223      /**
224       * Size of record (exluding 4 byte header)
225       */
226      public int getRecordSize()
227      {
228          return 4  + 4 + 4 + 4 + 4 + 1 + 1 + 2;
229      }
230  
231      public short getSid()
232      {
233          return this.sid;
234      }
235  
236      public Object clone() {
237          LegendRecord rec = new LegendRecord();
238      
239          rec.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft;
240          rec.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft;
241          rec.field_3_xSize = field_3_xSize;
242          rec.field_4_ySize = field_4_ySize;
243          rec.field_5_type = field_5_type;
244          rec.field_6_spacing = field_6_spacing;
245          rec.field_7_options = field_7_options;
246          return rec;
247      }
248  
249  
250  
251  
252      /**
253       * Get the x axis upper left field for the Legend record.
254       */
255      public int getXAxisUpperLeft()
256      {
257          return field_1_xAxisUpperLeft;
258      }
259  
260      /**
261       * Set the x axis upper left field for the Legend record.
262       */
263      public void setXAxisUpperLeft(int field_1_xAxisUpperLeft)
264      {
265          this.field_1_xAxisUpperLeft = field_1_xAxisUpperLeft;
266      }
267  
268      /**
269       * Get the y axis upper left field for the Legend record.
270       */
271      public int getYAxisUpperLeft()
272      {
273          return field_2_yAxisUpperLeft;
274      }
275  
276      /**
277       * Set the y axis upper left field for the Legend record.
278       */
279      public void setYAxisUpperLeft(int field_2_yAxisUpperLeft)
280      {
281          this.field_2_yAxisUpperLeft = field_2_yAxisUpperLeft;
282      }
283  
284      /**
285       * Get the x size field for the Legend record.
286       */
287      public int getXSize()
288      {
289          return field_3_xSize;
290      }
291  
292      /**
293       * Set the x size field for the Legend record.
294       */
295      public void setXSize(int field_3_xSize)
296      {
297          this.field_3_xSize = field_3_xSize;
298      }
299  
300      /**
301       * Get the y size field for the Legend record.
302       */
303      public int getYSize()
304      {
305          return field_4_ySize;
306      }
307  
308      /**
309       * Set the y size field for the Legend record.
310       */
311      public void setYSize(int field_4_ySize)
312      {
313          this.field_4_ySize = field_4_ySize;
314      }
315  
316      /**
317       * Get the type field for the Legend record.
318       *
319       * @return  One of 
320       *        TYPE_BOTTOM
321       *        TYPE_CORNER
322       *        TYPE_TOP
323       *        TYPE_RIGHT
324       *        TYPE_LEFT
325       *        TYPE_UNDOCKED
326       */
327      public byte getType()
328      {
329          return field_5_type;
330      }
331  
332      /**
333       * Set the type field for the Legend record.
334       *
335       * @param field_5_type
336       *        One of 
337       *        TYPE_BOTTOM
338       *        TYPE_CORNER
339       *        TYPE_TOP
340       *        TYPE_RIGHT
341       *        TYPE_LEFT
342       *        TYPE_UNDOCKED
343       */
344      public void setType(byte field_5_type)
345      {
346          this.field_5_type = field_5_type;
347      }
348  
349      /**
350       * Get the spacing field for the Legend record.
351       *
352       * @return  One of 
353       *        SPACING_CLOSE
354       *        SPACING_MEDIUM
355       *        SPACING_OPEN
356       */
357      public byte getSpacing()
358      {
359          return field_6_spacing;
360      }
361  
362      /**
363       * Set the spacing field for the Legend record.
364       *
365       * @param field_6_spacing
366       *        One of 
367       *        SPACING_CLOSE
368       *        SPACING_MEDIUM
369       *        SPACING_OPEN
370       */
371      public void setSpacing(byte field_6_spacing)
372      {
373          this.field_6_spacing = field_6_spacing;
374      }
375  
376      /**
377       * Get the options field for the Legend record.
378       */
379      public short getOptions()
380      {
381          return field_7_options;
382      }
383  
384      /**
385       * Set the options field for the Legend record.
386       */
387      public void setOptions(short field_7_options)
388      {
389          this.field_7_options = field_7_options;
390      }
391  
392      /**
393       * Sets the auto position field value.
394       * automatic positioning (1=docked)
395       */
396      public void setAutoPosition(boolean value)
397      {
398          field_7_options = autoPosition.setShortBoolean(field_7_options, value);
399      }
400  
401      /**
402       * automatic positioning (1=docked)
403       * @return  the auto position field value.
404       */
405      public boolean isAutoPosition()
406      {
407          return autoPosition.isSet(field_7_options);
408      }
409  
410      /**
411       * Sets the auto series field value.
412       * excel 5 only (true)
413       */
414      public void setAutoSeries(boolean value)
415      {
416          field_7_options = autoSeries.setShortBoolean(field_7_options, value);
417      }
418  
419      /**
420       * excel 5 only (true)
421       * @return  the auto series field value.
422       */
423      public boolean isAutoSeries()
424      {
425          return autoSeries.isSet(field_7_options);
426      }
427  
428      /**
429       * Sets the auto x positioning field value.
430       * position of legend on the x axis is automatic
431       */
432      public void setAutoXPositioning(boolean value)
433      {
434          field_7_options = autoXPositioning.setShortBoolean(field_7_options, value);
435      }
436  
437      /**
438       * position of legend on the x axis is automatic
439       * @return  the auto x positioning field value.
440       */
441      public boolean isAutoXPositioning()
442      {
443          return autoXPositioning.isSet(field_7_options);
444      }
445  
446      /**
447       * Sets the auto y positioning field value.
448       * position of legend on the y axis is automatic
449       */
450      public void setAutoYPositioning(boolean value)
451      {
452          field_7_options = autoYPositioning.setShortBoolean(field_7_options, value);
453      }
454  
455      /**
456       * position of legend on the y axis is automatic
457       * @return  the auto y positioning field value.
458       */
459      public boolean isAutoYPositioning()
460      {
461          return autoYPositioning.isSet(field_7_options);
462      }
463  
464      /**
465       * Sets the vertical field value.
466       * vertical or horizontal legend (1 or 0 respectively).  Always 0 if not automatic.
467       */
468      public void setVertical(boolean value)
469      {
470          field_7_options = vertical.setShortBoolean(field_7_options, value);
471      }
472  
473      /**
474       * vertical or horizontal legend (1 or 0 respectively).  Always 0 if not automatic.
475       * @return  the vertical field value.
476       */
477      public boolean isVertical()
478      {
479          return vertical.isSet(field_7_options);
480      }
481  
482      /**
483       * Sets the data table field value.
484       * 1 if chart contains data table
485       */
486      public void setDataTable(boolean value)
487      {
488          field_7_options = dataTable.setShortBoolean(field_7_options, value);
489      }
490  
491      /**
492       * 1 if chart contains data table
493       * @return  the data table field value.
494       */
495      public boolean isDataTable()
496      {
497          return dataTable.isSet(field_7_options);
498      }
499  
500  
501  }  // END OF CLASS
502  
503  
504  
505  
506