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 area format record is used to define the colours and patterns for an area.
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 AreaFormatRecord
74       extends Record
75   {
76       public final static short      sid                             = 0x100a;
77       private  int        field_1_foregroundColor;
78       private  int        field_2_backgroundColor;
79       private  short      field_3_pattern;
80       private  short      field_4_formatFlags;
81       private BitField   automatic                                  = new BitField(0x1);
82       private BitField   invert                                     = new BitField(0x2);
83       private  short      field_5_forecolorIndex;
84       private  short      field_6_backcolorIndex;
85   
86   
87       public AreaFormatRecord()
88       {
89   
90       }
91   
92       /**
93        * Constructs a AreaFormat record and sets its fields appropriately.
94        *
95        * @param id    id must be 0x100a or an exception
96        *              will be throw upon validation
97        * @param size  size the size of the data area of the record
98        * @param data  data of the record (should not contain sid/len)
99        */
100  
101      public AreaFormatRecord(short id, short size, byte [] data)
102      {
103          super(id, size, data);
104      }
105  
106      /**
107       * Constructs a AreaFormat record and sets its fields appropriately.
108       *
109       * @param id    id must be 0x100a 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       * @param offset of the record's data
114       */
115  
116      public AreaFormatRecord(short id, short size, byte [] data, int offset)
117      {
118          super(id, size, data, offset);
119      }
120  
121      /**
122       * Checks the sid matches the expected side for this record
123       *
124       * @param id   the expected sid.
125       */
126      protected void validateSid(short id)
127      {
128          if (id != sid)
129          {
130              throw new RecordFormatException("Not a AreaFormat record");
131          }
132      }
133  
134      protected void fillFields(byte [] data, short size, int offset)
135      {
136          field_1_foregroundColor         = LittleEndian.getInt(data, 0x0 + offset);
137          field_2_backgroundColor         = LittleEndian.getInt(data, 0x4 + offset);
138          field_3_pattern                 = LittleEndian.getShort(data, 0x8 + offset);
139          field_4_formatFlags             = LittleEndian.getShort(data, 0xa + offset);
140          field_5_forecolorIndex          = LittleEndian.getShort(data, 0xc + offset);
141          field_6_backcolorIndex          = LittleEndian.getShort(data, 0xe + offset);
142  
143      }
144  
145      public String toString()
146      {
147          StringBuffer buffer = new StringBuffer();
148  
149          buffer.append("[AreaFormat]\n");
150  
151          buffer.append("    .foregroundColor      = ")
152              .append("0x")
153              .append(HexDump.toHex((int)getForegroundColor()))
154              .append(" (").append(getForegroundColor()).append(" )\n");
155  
156          buffer.append("    .backgroundColor      = ")
157              .append("0x")
158              .append(HexDump.toHex((int)getBackgroundColor()))
159              .append(" (").append(getBackgroundColor()).append(" )\n");
160  
161          buffer.append("    .pattern              = ")
162              .append("0x")
163              .append(HexDump.toHex((short)getPattern()))
164              .append(" (").append(getPattern()).append(" )\n");
165  
166          buffer.append("    .formatFlags          = ")
167              .append("0x")
168              .append(HexDump.toHex((short)getFormatFlags()))
169              .append(" (").append(getFormatFlags()).append(" )\n");
170          buffer.append("         .automatic                = ").append(isAutomatic           ()).append('\n');
171          buffer.append("         .invert                   = ").append(isInvert              ()).append('\n');
172  
173          buffer.append("    .forecolorIndex       = ")
174              .append("0x")
175              .append(HexDump.toHex((short)getForecolorIndex()))
176              .append(" (").append(getForecolorIndex()).append(" )\n");
177  
178          buffer.append("    .backcolorIndex       = ")
179              .append("0x")
180              .append(HexDump.toHex((short)getBackcolorIndex()))
181              .append(" (").append(getBackcolorIndex()).append(" )\n");
182  
183          buffer.append("[/AreaFormat]\n");
184          return buffer.toString();
185      }
186  
187      public int serialize(int offset, byte[] data)
188      {
189          LittleEndian.putShort(data, 0 + offset, sid);
190          LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
191  
192          LittleEndian.putInt(data, 4 + offset, field_1_foregroundColor);
193          LittleEndian.putInt(data, 8 + offset, field_2_backgroundColor);
194          LittleEndian.putShort(data, 12 + offset, field_3_pattern);
195          LittleEndian.putShort(data, 14 + offset, field_4_formatFlags);
196          LittleEndian.putShort(data, 16 + offset, field_5_forecolorIndex);
197          LittleEndian.putShort(data, 18 + offset, field_6_backcolorIndex);
198  
199          return getRecordSize();
200      }
201  
202      /**
203       * Size of record (exluding 4 byte header)
204       */
205      public int getRecordSize()
206      {
207          return 4 + 4 + 4 + 2 + 2 + 2 + 2;
208      }
209  
210      public short getSid()
211      {
212          return this.sid;
213      }
214  
215  
216      /**
217       * Get the foreground color field for the AreaFormat record.
218       */
219      public int getForegroundColor()
220      {
221          return field_1_foregroundColor;
222      }
223  
224      /**
225       * Set the foreground color field for the AreaFormat record.
226       */
227      public void setForegroundColor(int field_1_foregroundColor)
228      {
229          this.field_1_foregroundColor = field_1_foregroundColor;
230      }
231  
232      /**
233       * Get the background color field for the AreaFormat record.
234       */
235      public int getBackgroundColor()
236      {
237          return field_2_backgroundColor;
238      }
239  
240      /**
241       * Set the background color field for the AreaFormat record.
242       */
243      public void setBackgroundColor(int field_2_backgroundColor)
244      {
245          this.field_2_backgroundColor = field_2_backgroundColor;
246      }
247  
248      /**
249       * Get the pattern field for the AreaFormat record.
250       */
251      public short getPattern()
252      {
253          return field_3_pattern;
254      }
255  
256      /**
257       * Set the pattern field for the AreaFormat record.
258       */
259      public void setPattern(short field_3_pattern)
260      {
261          this.field_3_pattern = field_3_pattern;
262      }
263  
264      /**
265       * Get the format flags field for the AreaFormat record.
266       */
267      public short getFormatFlags()
268      {
269          return field_4_formatFlags;
270      }
271  
272      /**
273       * Set the format flags field for the AreaFormat record.
274       */
275      public void setFormatFlags(short field_4_formatFlags)
276      {
277          this.field_4_formatFlags = field_4_formatFlags;
278      }
279  
280      /**
281       * Get the forecolor index field for the AreaFormat record.
282       */
283      public short getForecolorIndex()
284      {
285          return field_5_forecolorIndex;
286      }
287  
288      /**
289       * Set the forecolor index field for the AreaFormat record.
290       */
291      public void setForecolorIndex(short field_5_forecolorIndex)
292      {
293          this.field_5_forecolorIndex = field_5_forecolorIndex;
294      }
295  
296      /**
297       * Get the backcolor index field for the AreaFormat record.
298       */
299      public short getBackcolorIndex()
300      {
301          return field_6_backcolorIndex;
302      }
303  
304      /**
305       * Set the backcolor index field for the AreaFormat record.
306       */
307      public void setBackcolorIndex(short field_6_backcolorIndex)
308      {
309          this.field_6_backcolorIndex = field_6_backcolorIndex;
310      }
311  
312      /**
313       * Sets the automatic field value.
314       * automatic formatting
315       */
316      public void setAutomatic(boolean value)
317      {
318          field_4_formatFlags = automatic.setShortBoolean(field_4_formatFlags, value);
319      }
320  
321      /**
322       * automatic formatting
323       * @return  the automatic field value.
324       */
325      public boolean isAutomatic()
326      {
327          return automatic.isSet(field_4_formatFlags);
328      }
329  
330      /**
331       * Sets the invert field value.
332       * swap foreground and background colours when data is negative
333       */
334      public void setInvert(boolean value)
335      {
336          field_4_formatFlags = invert.setShortBoolean(field_4_formatFlags, value);
337      }
338  
339      /**
340       * swap foreground and background colours when data is negative
341       * @return  the invert field value.
342       */
343      public boolean isInvert()
344      {
345          return invert.isSet(field_4_formatFlags);
346      }
347  
348  
349  }  // END OF CLASS
350  
351  
352  
353  
354