aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/org/apache/poi/hssf/record/TickRecord.java486
-rw-r--r--src/records/definitions/tick_record.xml23
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestTickRecord.java149
3 files changed, 658 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/hssf/record/TickRecord.java b/src/java/org/apache/poi/hssf/record/TickRecord.java
new file mode 100644
index 0000000000..efead73f80
--- /dev/null
+++ b/src/java/org/apache/poi/hssf/record/TickRecord.java
@@ -0,0 +1,486 @@
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache POI" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache POI", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+
+package org.apache.poi.hssf.record;
+
+
+
+import org.apache.poi.util.*;
+
+/**
+ * The Tick record defines how tick marks and label positioning/formatting
+ * NOTE: This source is automatically generated please do not modify this file. Either subclass or
+ * remove the record in src/records/definitions.
+
+ * @author Andrew C. Oliver(acoliver at apache.org)
+ */
+public class TickRecord
+ extends Record
+{
+ public final static short sid = 0x101e;
+ private byte field_1_majorTickType;
+ private byte field_2_minorTickType;
+ private byte field_3_labelPosition;
+ private byte field_4_background;
+ private int field_5_labelColorRgb;
+ private short field_6_zero1;
+ private short field_7_zero2;
+ private short field_8_options;
+ private BitField autoTextColor = new BitField(0x1);
+ private BitField autoTextBackground = new BitField(0x2);
+ private BitField rotation = new BitField(0x1c);
+ private BitField autorotate = new BitField(0x20);
+ private short field_9_tickColor;
+ private short field_10_zero3;
+
+
+ public TickRecord()
+ {
+
+ }
+
+ /**
+ * Constructs a Tick record and sets its fields appropriately.
+ *
+ * @param id id must be 0x101e or an exception
+ * will be throw upon validation
+ * @param size size the size of the data area of the record
+ * @param data data of the record (should not contain sid/len)
+ */
+
+ public TickRecord(short id, short size, byte [] data)
+ {
+ super(id, size, data);
+ }
+
+ /**
+ * Constructs a Tick record and sets its fields appropriately.
+ *
+ * @param id id must be 0x101e or an exception
+ * will be throw upon validation
+ * @param size size the size of the data area of the record
+ * @param data data of the record (should not contain sid/len)
+ * @param offset of the record's data
+ */
+
+ public TickRecord(short id, short size, byte [] data, int offset)
+ {
+ super(id, size, data, offset);
+ }
+
+ /**
+ * Checks the sid matches the expected side for this record
+ *
+ * @param id the expected sid.
+ */
+ protected void validateSid(short id)
+ {
+ if (id != sid)
+ {
+ throw new RecordFormatException("Not a Tick record");
+ }
+ }
+
+ protected void fillFields(byte [] data, short size, int offset)
+ {
+ field_1_majorTickType = data[ 0x0 + offset ];
+ field_2_minorTickType = data[ 0x1 + offset ];
+ field_3_labelPosition = data[ 0x2 + offset ];
+ field_4_background = data[ 0x3 + offset ];
+ field_5_labelColorRgb = LittleEndian.getInt(data, 0x4 + offset);
+ field_6_zero1 = LittleEndian.getShort(data, 0x8 + offset);
+ field_7_zero2 = LittleEndian.getShort(data, 0x10 + offset);
+ field_8_options = LittleEndian.getShort(data, 0x18 + offset);
+ field_9_tickColor = LittleEndian.getShort(data, 0x1a + offset);
+ field_10_zero3 = LittleEndian.getShort(data, 0x1c + offset);
+
+ }
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append("[Tick]\n");
+
+ buffer.append(" .majorTickType = ")
+ .append("0x")
+ .append(HexDump.toHex((byte)getMajorTickType()))
+ .append(" (").append(getMajorTickType()).append(" )\n");
+
+ buffer.append(" .minorTickType = ")
+ .append("0x")
+ .append(HexDump.toHex((byte)getMinorTickType()))
+ .append(" (").append(getMinorTickType()).append(" )\n");
+
+ buffer.append(" .labelPosition = ")
+ .append("0x")
+ .append(HexDump.toHex((byte)getLabelPosition()))
+ .append(" (").append(getLabelPosition()).append(" )\n");
+
+ buffer.append(" .background = ")
+ .append("0x")
+ .append(HexDump.toHex((byte)getBackground()))
+ .append(" (").append(getBackground()).append(" )\n");
+
+ buffer.append(" .labelColorRgb = ")
+ .append("0x")
+ .append(HexDump.toHex((int)getLabelColorRgb()))
+ .append(" (").append(getLabelColorRgb()).append(" )\n");
+
+ buffer.append(" .zero1 = ")
+ .append("0x")
+ .append(HexDump.toHex((short)getZero1()))
+ .append(" (").append(getZero1()).append(" )\n");
+
+ buffer.append(" .zero2 = ")
+ .append("0x")
+ .append(HexDump.toHex((short)getZero2()))
+ .append(" (").append(getZero2()).append(" )\n");
+
+ buffer.append(" .options = ")
+ .append("0x")
+ .append(HexDump.toHex((short)getOptions()))
+ .append(" (").append(getOptions()).append(" )\n");
+ buffer.append(" .autoTextColor = ").append(isAutoTextColor ()).append('\n');
+ buffer.append(" .autoTextBackground = ").append(isAutoTextBackground ()).append('\n');
+ buffer.append(" .rotation = ").append(getRotation ()).append('\n');
+ buffer.append(" .autorotate = ").append(isAutorotate ()).append('\n');
+
+ buffer.append(" .tickColor = ")
+ .append("0x")
+ .append(HexDump.toHex((short)getTickColor()))
+ .append(" (").append(getTickColor()).append(" )\n");
+
+ buffer.append(" .zero3 = ")
+ .append("0x")
+ .append(HexDump.toHex((short)getZero3()))
+ .append(" (").append(getZero3()).append(" )\n");
+
+ buffer.append("[/Tick]\n");
+ return buffer.toString();
+ }
+
+ public int serialize(int offset, byte[] data)
+ {
+ LittleEndian.putShort(data, 0 + offset, sid);
+ LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
+
+ data[ 4 + offset ] = field_1_majorTickType;
+ data[ 5 + offset ] = field_2_minorTickType;
+ data[ 6 + offset ] = field_3_labelPosition;
+ data[ 7 + offset ] = field_4_background;
+ LittleEndian.putInt(data, 8 + offset, field_5_labelColorRgb);
+ LittleEndian.putShort(data, 12 + offset, field_6_zero1);
+ LittleEndian.putShort(data, 20 + offset, field_7_zero2);
+ LittleEndian.putShort(data, 28 + offset, field_8_options);
+ LittleEndian.putShort(data, 30 + offset, field_9_tickColor);
+ LittleEndian.putShort(data, 32 + offset, field_10_zero3);
+
+ return getRecordSize();
+ }
+
+ /**
+ * Size of record (exluding 4 byte header)
+ */
+ public int getRecordSize()
+ {
+ return 4 + 1 + 1 + 1 + 1 + 4 + 8 + 8 + 2 + 2 + 2;
+ }
+
+ public short getSid()
+ {
+ return this.sid;
+ }
+
+
+ /**
+ * Get the major tick type field for the Tick record.
+ */
+ public byte getMajorTickType()
+ {
+ return field_1_majorTickType;
+ }
+
+ /**
+ * Set the major tick type field for the Tick record.
+ */
+ public void setMajorTickType(byte field_1_majorTickType)
+ {
+ this.field_1_majorTickType = field_1_majorTickType;
+ }
+
+ /**
+ * Get the minor tick type field for the Tick record.
+ */
+ public byte getMinorTickType()
+ {
+ return field_2_minorTickType;
+ }
+
+ /**
+ * Set the minor tick type field for the Tick record.
+ */
+ public void setMinorTickType(byte field_2_minorTickType)
+ {
+ this.field_2_minorTickType = field_2_minorTickType;
+ }
+
+ /**
+ * Get the label position field for the Tick record.
+ */
+ public byte getLabelPosition()
+ {
+ return field_3_labelPosition;
+ }
+
+ /**
+ * Set the label position field for the Tick record.
+ */
+ public void setLabelPosition(byte field_3_labelPosition)
+ {
+ this.field_3_labelPosition = field_3_labelPosition;
+ }
+
+ /**
+ * Get the background field for the Tick record.
+ */
+ public byte getBackground()
+ {
+ return field_4_background;
+ }
+
+ /**
+ * Set the background field for the Tick record.
+ */
+ public void setBackground(byte field_4_background)
+ {
+ this.field_4_background = field_4_background;
+ }
+
+ /**
+ * Get the label color rgb field for the Tick record.
+ */
+ public int getLabelColorRgb()
+ {
+ return field_5_labelColorRgb;
+ }
+
+ /**
+ * Set the label color rgb field for the Tick record.
+ */
+ public void setLabelColorRgb(int field_5_labelColorRgb)
+ {
+ this.field_5_labelColorRgb = field_5_labelColorRgb;
+ }
+
+ /**
+ * Get the zero 1 field for the Tick record.
+ */
+ public short getZero1()
+ {
+ return field_6_zero1;
+ }
+
+ /**
+ * Set the zero 1 field for the Tick record.
+ */
+ public void setZero1(short field_6_zero1)
+ {
+ this.field_6_zero1 = field_6_zero1;
+ }
+
+ /**
+ * Get the zero 2 field for the Tick record.
+ */
+ public short getZero2()
+ {
+ return field_7_zero2;
+ }
+
+ /**
+ * Set the zero 2 field for the Tick record.
+ */
+ public void setZero2(short field_7_zero2)
+ {
+ this.field_7_zero2 = field_7_zero2;
+ }
+
+ /**
+ * Get the options field for the Tick record.
+ */
+ public short getOptions()
+ {
+ return field_8_options;
+ }
+
+ /**
+ * Set the options field for the Tick record.
+ */
+ public void setOptions(short field_8_options)
+ {
+ this.field_8_options = field_8_options;
+ }
+
+ /**
+ * Get the tick color field for the Tick record.
+ */
+ public short getTickColor()
+ {
+ return field_9_tickColor;
+ }
+
+ /**
+ * Set the tick color field for the Tick record.
+ */
+ public void setTickColor(short field_9_tickColor)
+ {
+ this.field_9_tickColor = field_9_tickColor;
+ }
+
+ /**
+ * Get the zero 3 field for the Tick record.
+ */
+ public short getZero3()
+ {
+ return field_10_zero3;
+ }
+
+ /**
+ * Set the zero 3 field for the Tick record.
+ */
+ public void setZero3(short field_10_zero3)
+ {
+ this.field_10_zero3 = field_10_zero3;
+ }
+
+ /**
+ * Sets the auto text color field value.
+ * use the quote unquote automatic color for text
+ */
+ public void setAutoTextColor(boolean value)
+ {
+ field_8_options = autoTextColor.setShortBoolean(field_8_options, value);
+ }
+
+ /**
+ * use the quote unquote automatic color for text
+ * @return the auto text color field value.
+ */
+ public boolean isAutoTextColor()
+ {
+ return autoTextColor.isSet(field_8_options);
+ }
+
+ /**
+ * Sets the auto text background field value.
+ * use the quote unquote automatic color for text background
+ */
+ public void setAutoTextBackground(boolean value)
+ {
+ field_8_options = autoTextBackground.setShortBoolean(field_8_options, value);
+ }
+
+ /**
+ * use the quote unquote automatic color for text background
+ * @return the auto text background field value.
+ */
+ public boolean isAutoTextBackground()
+ {
+ return autoTextBackground.isSet(field_8_options);
+ }
+
+ /**
+ * Sets the rotation field value.
+ * rotate text (0=none, 1=normal, 2=90 degrees counterclockwise, 3=90 degrees clockwise)
+ */
+ public void setRotation(short value)
+ {
+ field_8_options = rotation.setShortValue(field_8_options, value);
+ }
+
+ /**
+ * rotate text (0=none, 1=normal, 2=90 degrees counterclockwise, 3=90 degrees clockwise)
+ * @return the rotation field value.
+ */
+ public short getRotation()
+ {
+ return rotation.getShortValue(field_8_options);
+ }
+
+ /**
+ * Sets the autorotate field value.
+ * automatically rotate the text
+ */
+ public void setAutorotate(boolean value)
+ {
+ field_8_options = autorotate.setShortBoolean(field_8_options, value);
+ }
+
+ /**
+ * automatically rotate the text
+ * @return the autorotate field value.
+ */
+ public boolean isAutorotate()
+ {
+ return autorotate.isSet(field_8_options);
+ }
+
+
+} // END OF CLASS
+
+
+
+
diff --git a/src/records/definitions/tick_record.xml b/src/records/definitions/tick_record.xml
new file mode 100644
index 0000000000..5a69e019ae
--- /dev/null
+++ b/src/records/definitions/tick_record.xml
@@ -0,0 +1,23 @@
+<record id="0x101e" name="Tick" package="org.apache.poi.hssf.record">
+ <suffix>Record</suffix>
+ <extends>Record</extends>
+ <description>The Tick record defines how tick marks and label positioning/formatting</description>
+ <author>Andrew C. Oliver(acoliver at apache.org)</author>
+ <fields>
+ <field type="int" size="1" name="major tick type" description="type of major tick mark 0 (none),1 (inside axis line), 2 (outside axis line), 3 (cross axis line)"/>
+ <field type="int" size="1" name="minor tick type" description="type of minor tick mark 0 (none),1 (inside axis line), 2 (outside axis line), 3 (cross axis line)"/>
+ <field type="int" size="1" name="label position" decription="label position relative to the axis line 0=invisible, 1=low end,2=high end, 3=next to axis"/>
+ <field type="int" size="1" name="background" description="1=transparent, 2=opaque"/>
+ <field type="int" size="4" name="label color rgb" description="an RGB value of the label text where highbyte=0"/>
+ <field type="int" size="8" name="zero 1" description="must be 0"/>
+ <field type="int" size="8" name="zero 2" description="must be 0"/>
+ <field type="int" size="2" name="options">
+ <bit number="0" name="auto text color" description="use the quote unquote automatic color for text"/>
+ <bit number="1" name="auto text background" description="use the quote unquote automatic color for text background"/>
+ <bit mask="0x1c" name="rotation" description="rotate text (0=none, 1=normal, 2=90 degrees counterclockwise, 3=90 degrees clockwise)"/>
+ <bit number="5" name="autorotate" description="automatically rotate the text"/>
+ </field>
+ <field type="int" size="2" name="tick color" description="HSSFColor for tick label"/>
+ <field type="int" size="2" name="zero 3" description="must be 0"/>
+ </fields>
+</record>
diff --git a/src/testcases/org/apache/poi/hssf/record/TestTickRecord.java b/src/testcases/org/apache/poi/hssf/record/TestTickRecord.java
new file mode 100644
index 0000000000..0dcbf1aa5d
--- /dev/null
+++ b/src/testcases/org/apache/poi/hssf/record/TestTickRecord.java
@@ -0,0 +1,149 @@
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache POI" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * "Apache POI", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+
+package org.apache.poi.hssf.record;
+
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the serialization and deserialization of the TickRecord
+ * class works correctly. Test data taken directly from a real
+ * Excel file.
+ *
+
+ * @author Andrew C. Oliver(acoliver at apache.org)
+ */
+public class TestTickRecord
+ extends TestCase
+{
+ byte[] data = new byte[] {
+ (byte)0x02, (byte)0x00, (byte)0x03, (byte)0x01,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x23, (byte)0x00,
+ (byte)0x4D, (byte)0x00, (byte)0x00, (byte)0x00
+ };
+
+ public TestTickRecord(String name)
+ {
+ super(name);
+ }
+
+ public void testLoad()
+ throws Exception
+ {
+ TickRecord record = new TickRecord((short)0x101e, (short)data.length, data);
+ assertEquals( (byte)2, record.getMajorTickType());
+ assertEquals( (byte)0, record.getMinorTickType());
+ assertEquals( (byte)3, record.getLabelPosition());
+ assertEquals( (short)1, record.getBackground());
+ assertEquals( 0, record.getLabelColorRgb());
+ assertEquals( (short)0, record.getZero1());
+ assertEquals( (short)0, record.getZero2());
+ assertEquals( (short)35, record.getOptions());
+ assertEquals( true, record.isAutoTextColor() );
+ assertEquals( true, record.isAutoTextBackground() );
+ assertEquals( (short)0x0, record.getRotation() );
+ assertEquals( true, record.isAutorotate() );
+ assertEquals( (short)77, record.getTickColor());
+ assertEquals( (short)0x0, record.getZero3());
+
+
+ assertEquals( 34, record.getRecordSize() );
+
+ record.validateSid((short)0x101e);
+ }
+
+ public void testStore()
+ {
+ TickRecord record = new TickRecord();
+ record.setMajorTickType( (byte)2 );
+ record.setMinorTickType( (byte)0 );
+ record.setLabelPosition( (byte)3 );
+ record.setBackground( (byte)1 );
+ record.setLabelColorRgb( 0 );
+ record.setZero1( (short)0 );
+ record.setZero2( (short)0 );
+ record.setOptions( (short)35 );
+ record.setAutoTextColor( true );
+ record.setAutoTextBackground( true );
+ record.setRotation( (short)0 );
+ record.setAutorotate( true );
+ record.setTickColor( (short)77 );
+ record.setZero3( (short)0 );
+
+
+ byte [] recordBytes = record.serialize();
+ assertEquals(recordBytes.length - 4, data.length);
+ for (int i = 0; i < data.length; i++)
+ assertEquals("At offset " + i, data[i], recordBytes[i+4]);
+ }
+
+
+ /**
+ * The main program for the TestTickRecord class
+ *
+ *@param args The command line arguments
+ */
+ public static void main(String[] args) {
+ System.out.println("Testing org.apache.poi.hssf.record.TickRecord");
+ junit.textui.TestRunner.run(TestTickRecord.class);
+ }
+
+}