KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > afp > modca > ObjectEnvironmentGroup


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 /* $Id: ObjectEnvironmentGroup.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.modca;
21 import java.io.IOException JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.io.UnsupportedEncodingException JavaDoc;
24
25
26 /**
27  * An Object Environment Group (OEG) may be associated with an object and is contained
28  * within the object's begin-end envelope.
29  * The object environment group defines the object's origin and orientation on the page,
30  * and can contain font and color attribute table information. The scope of an object
31  * environment group is the scope of its containing object.
32  *
33  * An application that creates a data-stream document may omit some of the parameters
34  * normally contained in the object environment group, or it may specify that one or
35  * more default values are to be used.
36  */

37 public final class ObjectEnvironmentGroup extends AbstractNamedAFPObject {
38
39     /**
40      * Default name for the object environment group
41      */

42     private static final String JavaDoc DEFAULT_NAME = "OEG00001";
43
44     /**
45      * The ObjectAreaDescriptor for the object environment group
46      */

47     private ObjectAreaDescriptor _objectAreaDescriptor = null;
48
49     /**
50      * The ObjectAreaPosition for the object environment group
51      */

52     private ObjectAreaPosition _objectAreaPosition = null;
53
54     /**
55      * The ImageDataDescriptor for the object environment group
56      */

57     private ImageDataDescriptor _imageDataDescriptor = null;
58
59     /**
60      * Default constructor for the ObjectEnvironmentGroup.
61      */

62     public ObjectEnvironmentGroup() {
63
64         this(DEFAULT_NAME);
65
66     }
67
68     /**
69      * Constructor for the ObjectEnvironmentGroup, this takes a
70      * name parameter which must be 8 characters long.
71      * @param name the object environment group name
72      */

73     public ObjectEnvironmentGroup(String JavaDoc name) {
74
75         super(name);
76
77     }
78
79     /**
80      * Sets the object area parameters.
81      * @param x the x position of the object
82      * @param y the y position of the object
83      * @param width the object width
84      * @param height the object height
85      * @param rotation the object orientation
86      */

87     public void setObjectArea(int x, int y, int width, int height, int rotation) {
88
89         _objectAreaDescriptor = new ObjectAreaDescriptor(width, height);
90         _objectAreaPosition = new ObjectAreaPosition(x, y, rotation);
91
92     }
93
94     /**
95      * Set the dimensions of the image.
96      * @param xresol the x resolution of the image
97      * @param yresol the y resolution of the image
98      * @param width the image width
99      * @param height the image height
100      */

101     public void setImageData(int xresol, int yresol, int width, int height) {
102         _imageDataDescriptor = new ImageDataDescriptor(xresol, yresol, width, height);
103     }
104
105     /**
106      * Accessor method to obtain write the AFP datastream for
107      * the object environment group.
108      * @param os The stream to write to
109      * @throws java.io.IOException
110      */

111     public void writeDataStream(OutputStream JavaDoc os)
112         throws IOException JavaDoc {
113
114
115         writeStart(os);
116
117         _objectAreaDescriptor.writeDataStream(os);
118
119         _objectAreaPosition.writeDataStream(os);
120
121         if (_imageDataDescriptor != null) {
122             _imageDataDescriptor.writeDataStream(os);
123         }
124
125         writeEnd(os);
126
127     }
128
129     /**
130      * Helper method to write the start of the object environment group.
131      * @param os The stream to write to
132      */

133     private void writeStart(OutputStream JavaDoc os)
134         throws IOException JavaDoc {
135
136         byte[] data = new byte[] {
137             0x5A, // Structured field identifier
138
0x00, // Length byte 1
139
0x10, // Length byte 2
140
(byte) 0xD3, // Structured field id byte 1
141
(byte) 0xA8, // Structured field id byte 2
142
(byte) 0xC7, // Structured field id byte 3
143
0x00, // Flags
144
0x00, // Reserved
145
0x00, // Reserved
146
0x00, // Name
147
0x00, //
148
0x00, //
149
0x00, //
150
0x00, //
151
0x00, //
152
0x00, //
153
0x00, //
154
};
155
156         for (int i = 0; i < _nameBytes.length; i++) {
157
158             data[9 + i] = _nameBytes[i];
159
160         }
161
162         os.write(data);
163
164     }
165
166     /**
167      * Helper method to write the end of the object environment group.
168      * @param os The stream to write to
169      */

170     private void writeEnd(OutputStream JavaDoc os)
171         throws IOException JavaDoc {
172
173         byte[] data = new byte[17];
174
175         data[0] = 0x5A; // Structured field identifier
176
data[1] = 0x00; // Length byte 1
177
data[2] = 0x10; // Length byte 2
178
data[3] = (byte) 0xD3; // Structured field id byte 1
179
data[4] = (byte) 0xA9; // Structured field id byte 2
180
data[5] = (byte) 0xC7; // Structured field id byte 3
181
data[6] = 0x00; // Flags
182
data[7] = 0x00; // Reserved
183
data[8] = 0x00; // Reserved
184

185         for (int i = 0; i < _nameBytes.length; i++) {
186
187             data[9 + i] = _nameBytes[i];
188
189         }
190
191         os.write(data);
192
193     }
194
195 }
Popular Tags