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      public Object clone() {
249        TickRecord rec = new TickRecord();
250        
251        rec.field_1_majorTickType = field_1_majorTickType;
252        rec.field_2_minorTickType = field_2_minorTickType;
253        rec.field_3_labelPosition = field_3_labelPosition;
254        rec.field_4_background = field_4_background;
255        rec.field_5_labelColorRgb = field_5_labelColorRgb;
256        rec.field_6_zero1 = field_6_zero1;
257        rec.field_7_zero2 = field_7_zero2;
258        rec.field_8_options = field_8_options;
259        rec.field_9_tickColor = field_9_tickColor;
260        rec.field_10_zero3 = field_10_zero3;
261  
262        return rec;
263      }
264  
265  
266      /**
267       * Get the major tick type field for the Tick record.
268       */
269      public byte getMajorTickType()
270      {
271          return field_1_majorTickType;
272      }
273  
274      /**
275       * Set the major tick type field for the Tick record.
276       */
277      public void setMajorTickType(byte field_1_majorTickType)
278      {
279          this.field_1_majorTickType = field_1_majorTickType;
280      }
281  
282      /**
283       * Get the minor tick type field for the Tick record.
284       */
285      public byte getMinorTickType()
286      {
287          return field_2_minorTickType;
288      }
289  
290      /**
291       * Set the minor tick type field for the Tick record.
292       */
293      public void setMinorTickType(byte field_2_minorTickType)
294      {
295          this.field_2_minorTickType = field_2_minorTickType;
296      }
297  
298      /**
299       * Get the label position field for the Tick record.
300       */
301      public byte getLabelPosition()
302      {
303          return field_3_labelPosition;
304      }
305  
306      /**
307       * Set the label position field for the Tick record.
308       */
309      public void setLabelPosition(byte field_3_labelPosition)
310      {
311          this.field_3_labelPosition = field_3_labelPosition;
312      }
313  
314      /**
315       * Get the background field for the Tick record.
316       */
317      public byte getBackground()
318      {
319          return field_4_background;
320      }
321  
322      /**
323       * Set the background field for the Tick record.
324       */
325      public void setBackground(byte field_4_background)
326      {
327          this.field_4_background = field_4_background;
328      }
329  
330      /**
331       * Get the label color rgb field for the Tick record.
332       */
333      public int getLabelColorRgb()
334      {
335          return field_5_labelColorRgb;
336      }
337  
338      /**
339       * Set the label color rgb field for the Tick record.
340       */
341      public void setLabelColorRgb(int field_5_labelColorRgb)
342      {
343          this.field_5_labelColorRgb = field_5_labelColorRgb;
344      }
345  
346      /**
347       * Get the zero 1 field for the Tick record.
348       */
349      public short getZero1()
350      {
351          return field_6_zero1;
352      }
353  
354      /**
355       * Set the zero 1 field for the Tick record.
356       */
357      public void setZero1(short field_6_zero1)
358      {
359          this.field_6_zero1 = field_6_zero1;
360      }
361  
362      /**
363       * Get the zero 2 field for the Tick record.
364       */
365      public short getZero2()
366      {
367          return field_7_zero2;
368      }
369  
370      /**
371       * Set the zero 2 field for the Tick record.
372       */
373      public void setZero2(short field_7_zero2)
374      {
375          this.field_7_zero2 = field_7_zero2;
376      }
377  
378      /**
379       * Get the options field for the Tick record.
380       */
381      public short getOptions()
382      {
383          return field_8_options;
384      }
385  
386      /**
387       * Set the options field for the Tick record.
388       */
389      public void setOptions(short field_8_options)
390      {
391          this.field_8_options = field_8_options;
392      }
393  
394      /**
395       * Get the tick color field for the Tick record.
396       */
397      public short getTickColor()
398      {
399          return field_9_tickColor;
400      }
401  
402      /**
403       * Set the tick color field for the Tick record.
404       */
405      public void setTickColor(short field_9_tickColor)
406      {
407          this.field_9_tickColor = field_9_tickColor;
408      }
409  
410      /**
411       * Get the zero 3 field for the Tick record.
412       */
413      public short getZero3()
414      {
415          return field_10_zero3;
416      }
417  
418      /**
419       * Set the zero 3 field for the Tick record.
420       */
421      public void setZero3(short field_10_zero3)
422      {
423          this.field_10_zero3 = field_10_zero3;
424      }
425  
426      /**
427       * Sets the auto text color field value.
428       * use the quote unquote automatic color for text
429       */
430      public void setAutoTextColor(boolean value)
431      {
432          field_8_options = autoTextColor.setShortBoolean(field_8_options, value);
433      }
434  
435      /**
436       * use the quote unquote automatic color for text
437       * @return  the auto text color field value.
438       */
439      public boolean isAutoTextColor()
440      {
441          return autoTextColor.isSet(field_8_options);
442      }
443  
444      /**
445       * Sets the auto text background field value.
446       * use the quote unquote automatic color for text background
447       */
448      public void setAutoTextBackground(boolean value)
449      {
450          field_8_options = autoTextBackground.setShortBoolean(field_8_options, value);
451      }
452  
453      /**
454       * use the quote unquote automatic color for text background
455       * @return  the auto text background field value.
456       */
457      public boolean isAutoTextBackground()
458      {
459          return autoTextBackground.isSet(field_8_options);
460      }
461  
462      /**
463       * Sets the rotation field value.
464       * rotate text (0=none, 1=normal, 2=90 degrees counterclockwise, 3=90 degrees clockwise)
465       */
466      public void setRotation(short value)
467      {
468          field_8_options = rotation.setShortValue(field_8_options, value);
469      }
470  
471      /**
472       * rotate text (0=none, 1=normal, 2=90 degrees counterclockwise, 3=90 degrees clockwise)
473       * @return  the rotation field value.
474       */
475      public short getRotation()
476      {
477          return rotation.getShortValue(field_8_options);
478      }
479  
480      /**
481       * Sets the autorotate field value.
482       * automatically rotate the text
483       */
484      public void setAutorotate(boolean value)
485      {
486          field_8_options = autorotate.setShortBoolean(field_8_options, value);
487      }
488  
489      /**
490       * automatically rotate the text
491       * @return  the autorotate field value.
492       */
493      public boolean isAutorotate()
494      {
495          return autorotate.isSet(field_8_options);
496      }
497  
498  
499  }  // END OF CLASS
500  
501  
502  
503  
504