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 Tick record defines how tick marks and label positioning/formatting
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 TickRecord
71       extends Record
72   {
73       public final static short      sid                             = 0x101e;
74       private  byte       field_1_majorTickType;
75       private  byte       field_2_minorTickType;
76       private  byte       field_3_labelPosition;
77       private  byte       field_4_background;
78       private  int        field_5_labelColorRgb;
79       private  short field_6_zero1;
80       private  short field_7_zero2;
81       private  short      field_8_options;
82       private  BitField   autoTextColor                               = new BitField(0x1);
83       private  BitField   autoTextBackground                          = new BitField(0x2);
84       private BitField   rotation                                   = new BitField(0x1c);
85       private  BitField   autorotate                                  = new BitField(0x20);
86       private  short      field_9_tickColor;
87       private  short      field_10_zero3;
88   
89   
90       public TickRecord()
91       {
92   
93       }
94   
95       /**
96        * Constructs a Tick record and sets its fields appropriately.
97        *
98        * @param id    id must be 0x101e or an exception
99        *              will be throw upon validation
100       * @param size  size the size of the data area of the record
101       * @param data  data of the record (should not contain sid/len)
102       */
103  
104      public TickRecord(short id, short size, byte [] data)
105      {
106          super(id, size, data);
107      }
108  
109      /**
110       * Constructs a Tick record and sets its fields appropriately.
111       *
112       * @param id    id must be 0x101e or an exception
113       *              will be throw upon validation
114       * @param size  size the size of the data area of the record
115       * @param data  data of the record (should not contain sid/len)
116       * @param offset of the record's data
117       */
118  
119      public TickRecord(short id, short size, byte [] data, int offset)
120      {
121          super(id, size, data, offset);
122      }
123  
124      /**
125       * Checks the sid matches the expected side for this record
126       *
127       * @param id   the expected sid.
128       */
129      protected void validateSid(short id)
130      {
131          if (id != sid)
132          {
133              throw new RecordFormatException("Not a Tick record");
134          }
135      }
136  
137      protected void fillFields(byte [] data, short size, int offset)
138      {
139          field_1_majorTickType           = data[ 0x0 + offset ];
140          field_2_minorTickType           = data[ 0x1 + offset ];
141          field_3_labelPosition           = data[ 0x2 + offset ];
142          field_4_background              = data[ 0x3 + offset ];
143          field_5_labelColorRgb           = LittleEndian.getInt(data, 0x4 + offset);
144          field_6_zero1                   = LittleEndian.getShort(data, 0x8 + offset);
145          field_7_zero2                   = LittleEndian.getShort(data, 0x10 + offset);
146          field_8_options                 = LittleEndian.getShort(data, 0x18 + offset);
147          field_9_tickColor               = LittleEndian.getShort(data, 0x1a + offset);
148          field_10_zero3                  = LittleEndian.getShort(data, 0x1c + offset);
149  
150      }
151  
152      public String toString()
153      {
154          StringBuffer buffer = new StringBuffer();
155  
156          buffer.append("[Tick]\n");
157  
158          buffer.append("    .majorTickType        = ")
159              .append("0x")
160              .append(HexDump.toHex((byte)getMajorTickType()))
161              .append(" (").append(getMajorTickType()).append(" )\n");
162  
163          buffer.append("    .minorTickType        = ")
164              .append("0x")
165              .append(HexDump.toHex((byte)getMinorTickType()))
166              .append(" (").append(getMinorTickType()).append(" )\n");
167  
168          buffer.append("    .labelPosition        = ")
169              .append("0x")
170              .append(HexDump.toHex((byte)getLabelPosition()))
171              .append(" (").append(getLabelPosition()).append(" )\n");
172  
173          buffer.append("    .background           = ")
174              .append("0x")
175              .append(HexDump.toHex((byte)getBackground()))
176              .append(" (").append(getBackground()).append(" )\n");
177  
178          buffer.append("    .labelColorRgb        = ")
179              .append("0x")
180              .append(HexDump.toHex((int)getLabelColorRgb()))
181              .append(" (").append(getLabelColorRgb()).append(" )\n");
182  
183          buffer.append("    .zero1                = ")
184              .append("0x")
185              .append(HexDump.toHex((short)getZero1()))
186              .append(" (").append(getZero1()).append(" )\n");
187  
188          buffer.append("    .zero2                = ")
189              .append("0x")
190              .append(HexDump.toHex((short)getZero2()))
191              .append(" (").append(getZero2()).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("         .autoTextColor            = ").append(isAutoTextColor       ()).append('\n');
198          buffer.append("         .autoTextBackground       = ").append(isAutoTextBackground  ()).append('\n');
199          buffer.append("         .rotation                 = ").append(getRotation            ()).append('\n');
200          buffer.append("         .autorotate               = ").append(isAutorotate          ()).append('\n');
201  
202          buffer.append("    .tickColor            = ")
203              .append("0x")
204              .append(HexDump.toHex((short)getTickColor()))
205              .append(" (").append(getTickColor()).append(" )\n");
206  
207          buffer.append("    .zero3                = ")
208              .append("0x")
209              .append(HexDump.toHex((short)getZero3()))
210              .append(" (").append(getZero3()).append(" )\n");
211  
212          buffer.append("[/Tick]\n");
213          return buffer.toString();
214      }
215  
216      public int serialize(int offset, byte[] data)
217      {
218          LittleEndian.putShort(data, 0 + offset, sid);
219          LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
220  
221          data[ 4 + offset ] = field_1_majorTickType;
222          data[ 5 + offset ] = field_2_minorTickType;
223          data[ 6 + offset ] = field_3_labelPosition;
224          data[ 7 + offset ] = field_4_background;
225          LittleEndian.putInt(data, 8 + offset, field_5_labelColorRgb);
226          LittleEndian.putShort(data, 12 + offset, field_6_zero1);
227          LittleEndian.putShort(data, 20 + offset, field_7_zero2);
228          LittleEndian.putShort(data, 28 + offset, field_8_options);
229          LittleEndian.putShort(data, 30 + offset, field_9_tickColor);
230          LittleEndian.putShort(data, 32 + offset, field_10_zero3);
231  
232          return getRecordSize();
233      }
234  
235      /**
236       * Size of record (exluding 4 byte header)
237       */
238      public int getRecordSize()
239      {
240          return 4 + 1 + 1 + 1 + 1 + 4 + 8 + 8 + 2 + 2 + 2;
241      }
242  
243      public short getSid()
244      {
245          return this.sid;
246      }
247  
248  
249      /**
250       * Get the major tick type field for the Tick record.
251       */
252      public byte getMajorTickType()
253      {
254          return field_1_majorTickType;
255      }
256  
257      /**
258       * Set the major tick type field for the Tick record.
259       */
260      public void setMajorTickType(byte field_1_majorTickType)
261      {
262          this.field_1_majorTickType = field_1_majorTickType;
263      }
264  
265      /**
266       * Get the minor tick type field for the Tick record.
267       */
268      public byte getMinorTickType()
269      {
270          return field_2_minorTickType;
271      }
272  
273      /**
274       * Set the minor tick type field for the Tick record.
275       */
276      public void setMinorTickType(byte field_2_minorTickType)
277      {
278          this.field_2_minorTickType = field_2_minorTickType;
279      }
280  
281      /**
282       * Get the label position field for the Tick record.
283       */
284      public byte getLabelPosition()
285      {
286          return field_3_labelPosition;
287      }
288  
289      /**
290       * Set the label position field for the Tick record.
291       */
292      public void setLabelPosition(byte field_3_labelPosition)
293      {
294          this.field_3_labelPosition = field_3_labelPosition;
295      }
296  
297      /**
298       * Get the background field for the Tick record.
299       */
300      public byte getBackground()
301      {
302          return field_4_background;
303      }
304  
305      /**
306       * Set the background field for the Tick record.
307       */
308      public void setBackground(byte field_4_background)
309      {
310          this.field_4_background = field_4_background;
311      }
312  
313      /**
314       * Get the label color rgb field for the Tick record.
315       */
316      public int getLabelColorRgb()
317      {
318          return field_5_labelColorRgb;
319      }
320  
321      /**
322       * Set the label color rgb field for the Tick record.
323       */
324      public void setLabelColorRgb(int field_5_labelColorRgb)
325      {
326          this.field_5_labelColorRgb = field_5_labelColorRgb;
327      }
328  
329      /**
330       * Get the zero 1 field for the Tick record.
331       */
332      public short getZero1()
333      {
334          return field_6_zero1;
335      }
336  
337      /**
338       * Set the zero 1 field for the Tick record.
339       */
340      public void setZero1(short field_6_zero1)
341      {
342          this.field_6_zero1 = field_6_zero1;
343      }
344  
345      /**
346       * Get the zero 2 field for the Tick record.
347       */
348      public short getZero2()
349      {
350          return field_7_zero2;
351      }
352  
353      /**
354       * Set the zero 2 field for the Tick record.
355       */
356      public void setZero2(short field_7_zero2)
357      {
358          this.field_7_zero2 = field_7_zero2;
359      }
360  
361      /**
362       * Get the options field for the Tick record.
363       */
364      public short getOptions()
365      {
366          return field_8_options;
367      }
368  
369      /**
370       * Set the options field for the Tick record.
371       */
372      public void setOptions(short field_8_options)
373      {
374          this.field_8_options = field_8_options;
375      }
376  
377      /**
378       * Get the tick color field for the Tick record.
379       */
380      public short getTickColor()
381      {
382          return field_9_tickColor;
383      }
384  
385      /**
386       * Set the tick color field for the Tick record.
387       */
388      public void setTickColor(short field_9_tickColor)
389      {
390          this.field_9_tickColor = field_9_tickColor;
391      }
392  
393      /**
394       * Get the zero 3 field for the Tick record.
395       */
396      public short getZero3()
397      {
398          return field_10_zero3;
399      }
400  
401      /**
402       * Set the zero 3 field for the Tick record.
403       */
404      public void setZero3(short field_10_zero3)
405      {
406          this.field_10_zero3 = field_10_zero3;
407      }
408  
409      /**
410       * Sets the auto text color field value.
411       * use the quote unquote automatic color for text
412       */
413      public void setAutoTextColor(boolean value)
414      {
415          field_8_options = autoTextColor.setShortBoolean(field_8_options, value);
416      }
417  
418      /**
419       * use the quote unquote automatic color for text
420       * @return  the auto text color field value.
421       */
422      public boolean isAutoTextColor()
423      {
424          return autoTextColor.isSet(field_8_options);
425      }
426  
427      /**
428       * Sets the auto text background field value.
429       * use the quote unquote automatic color for text background
430       */
431      public void setAutoTextBackground(boolean value)
432      {
433          field_8_options = autoTextBackground.setShortBoolean(field_8_options, value);
434      }
435  
436      /**
437       * use the quote unquote automatic color for text background
438       * @return  the auto text background field value.
439       */
440      public boolean isAutoTextBackground()
441      {
442          return autoTextBackground.isSet(field_8_options);
443      }
444  
445      /**
446       * Sets the rotation field value.
447       * rotate text (0=none, 1=normal, 2=90 degrees counterclockwise, 3=90 degrees clockwise)
448       */
449      public void setRotation(short value)
450      {
451          field_8_options = rotation.setShortValue(field_8_options, value);
452      }
453  
454      /**
455       * rotate text (0=none, 1=normal, 2=90 degrees counterclockwise, 3=90 degrees clockwise)
456       * @return  the rotation field value.
457       */
458      public short getRotation()
459      {
460          return rotation.getShortValue(field_8_options);
461      }
462  
463      /**
464       * Sets the autorotate field value.
465       * automatically rotate the text
466       */
467      public void setAutorotate(boolean value)
468      {
469          field_8_options = autorotate.setShortBoolean(field_8_options, value);
470      }
471  
472      /**
473       * automatically rotate the text
474       * @return  the autorotate field value.
475       */
476      public boolean isAutorotate()
477      {
478          return autorotate.isSet(field_8_options);
479      }
480  
481  
482  }  // END OF CLASS
483  
484  
485  
486  
487