KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > ddf > EscherChildAnchorRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18 package org.apache.poi.ddf;
19
20 import org.apache.poi.util.HexDump;
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * The escher child achor record is used to specify the position of a shape under an
25  * existing group. The first level of shape records use a EscherClientAnchor record instead.
26  *
27  * @author Glen Stampoultzis
28  * @see EscherChildAnchorRecord
29  */

30 public class EscherChildAnchorRecord
31         extends EscherRecord
32 {
33     public static final short RECORD_ID = (short) 0xF00F;
34     public static final String JavaDoc RECORD_DESCRIPTION = "MsofbtChildAnchor";
35
36     private int field_1_dx1;
37     private int field_2_dy1;
38     private int field_3_dx2;
39     private int field_4_dy2;
40
41     /**
42      * This method deserializes the record from a byte array.
43      *
44      * @param data The byte array containing the escher record information
45      * @param offset The starting offset into <code>data</code>.
46      * @param recordFactory May be null since this is not a container record.
47      * @return The number of bytes read from the byte array.
48      */

49     public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory )
50     {
51         int bytesRemaining = readHeader( data, offset );
52         int pos = offset + 8;
53         int size = 0;
54         field_1_dx1 = LittleEndian.getInt( data, pos + size );size+=4;
55         field_2_dy1 = LittleEndian.getInt( data, pos + size );size+=4;
56         field_3_dx2 = LittleEndian.getInt( data, pos + size );size+=4;
57         field_4_dy2 = LittleEndian.getInt( data, pos + size );size+=4;
58         return 8 + size;
59     }
60
61     /**
62      * This method serializes this escher record into a byte array.
63      *
64      * @param offset The offset into <code>data</code> to start writing the record data to.
65      * @param data The byte array to serialize to.
66      * @param listener A listener to retrieve start and end callbacks. Use a <code>NullEscherSerailizationListener</code> to ignore these events.
67      * @return The number of bytes written.
68      * @see NullEscherSerializationListener
69      */

70     public int serialize( int offset, byte[] data, EscherSerializationListener listener )
71     {
72         listener.beforeRecordSerialize( offset, getRecordId(), this );
73         int pos = offset;
74         LittleEndian.putShort( data, pos, getOptions() ); pos += 2;
75         LittleEndian.putShort( data, pos, getRecordId() ); pos += 2;
76         LittleEndian.putInt( data, pos, getRecordSize()-8 ); pos += 4;
77         LittleEndian.putInt( data, pos, field_1_dx1 ); pos += 4;
78         LittleEndian.putInt( data, pos, field_2_dy1 ); pos += 4;
79         LittleEndian.putInt( data, pos, field_3_dx2 ); pos += 4;
80         LittleEndian.putInt( data, pos, field_4_dy2 ); pos += 4;
81
82         listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this );
83         return pos - offset;
84     }
85
86     /**
87      * Returns the number of bytes that are required to serialize this record.
88      *
89      * @return Number of bytes
90      */

91     public int getRecordSize()
92     {
93         return 8 + 4 * 4;
94     }
95
96     /**
97      * The record id for the EscherChildAnchorRecord.
98      */

99     public short getRecordId()
100     {
101         return RECORD_ID;
102     }
103
104     /**
105      * The short name for this record
106      */

107     public String JavaDoc getRecordName()
108     {
109         return "ChildAnchor";
110     }
111
112     /**
113      * The string representation of this record
114      */

115     public String JavaDoc toString()
116     {
117         String JavaDoc nl = System.getProperty("line.separator");
118
119         return getClass().getName() + ":" + nl +
120                 " RecordId: 0x" + HexDump.toHex(RECORD_ID) + nl +
121                 " Options: 0x" + HexDump.toHex(getOptions()) + nl +
122                 " X1: " + field_1_dx1 + nl +
123                 " Y1: " + field_2_dy1 + nl +
124                 " X2: " + field_3_dx2 + nl +
125                 " Y2: " + field_4_dy2 + nl ;
126
127     }
128
129     /**
130      * Retrieves offset within the parent coordinate space for the top left point.
131      */

132     public int getDx1()
133     {
134         return field_1_dx1;
135     }
136
137     /**
138      * Sets offset within the parent coordinate space for the top left point.
139      */

140     public void setDx1( int field_1_dx1 )
141     {
142         this.field_1_dx1 = field_1_dx1;
143     }
144
145     /**
146      * Gets offset within the parent coordinate space for the top left point.
147      */

148     public int getDy1()
149     {
150         return field_2_dy1;
151     }
152
153     /**
154      * Sets offset within the parent coordinate space for the top left point.
155      */

156     public void setDy1( int field_2_dy1 )
157     {
158         this.field_2_dy1 = field_2_dy1;
159     }
160
161     /**
162      * Retrieves offset within the parent coordinate space for the bottom right point.
163      */

164     public int getDx2()
165     {
166         return field_3_dx2;
167     }
168
169     /**
170      * Sets offset within the parent coordinate space for the bottom right point.
171      */

172     public void setDx2( int field_3_dx2 )
173     {
174         this.field_3_dx2 = field_3_dx2;
175     }
176
177     /**
178      * Gets the offset within the parent coordinate space for the bottom right point.
179      */

180     public int getDy2()
181     {
182         return field_4_dy2;
183     }
184
185     /**
186      * Sets the offset within the parent coordinate space for the bottom right point.
187      */

188     public void setDy2( int field_4_dy2 )
189     {
190         this.field_4_dy2 = field_4_dy2;
191     }
192
193 }
194
Popular Tags