KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > rtf > graphic > RtfShapePosition


1 package com.lowagie.text.rtf.graphic;
2
3 import java.io.ByteArrayOutputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.OutputStream JavaDoc;
6
7 import com.lowagie.text.rtf.RtfAddableElement;
8
9 /**
10  * The RtfShapePosition stores position and ordering
11  * information for one RtfShape.
12  *
13  * @version $Id: RtfShapePosition.java 2776 2007-05-23 20:01:40Z hallm $
14  * @author Mark Hall (mhall@edu.uni-klu.ac.at)
15  * @author Thomas Bickel (tmb99@inode.at)
16  */

17 public class RtfShapePosition extends RtfAddableElement {
18     /**
19      * Constant for horizontal positioning relative to the page.
20      */

21     public static final int POSITION_X_RELATIVE_PAGE = 0;
22     /**
23      * Constant for horizontal positioning relative to the margin.
24      */

25     public static final int POSITION_X_RELATIVE_MARGIN = 1;
26     /**
27      * Constant for horizontal positioning relative to the column.
28      */

29     public static final int POSITION_X_RELATIVE_COLUMN = 2;
30     /**
31      * Constant for vertical positioning relative to the page.
32      */

33     public static final int POSITION_Y_RELATIVE_PAGE = 0;
34     /**
35      * Constant for vertical positioning relative to the margin.
36      */

37     public static final int POSITION_Y_RELATIVE_MARGIN = 1;
38     /**
39      * Constant for vertical positioning relative to the paragraph.
40      */

41     public static final int POSITION_Y_RELATIVE_PARAGRAPH = 2;
42     
43     /**
44      * The top coordinate of this RtfShapePosition.
45      */

46     private int top = 0;
47     /**
48      * The left coordinate of this RtfShapePosition.
49      */

50     private int left = 0;
51     /**
52      * The right coordinate of this RtfShapePosition.
53      */

54     private int right = 0;
55     /**
56      * The bottom coordinate of this RtfShapePosition.
57      */

58     private int bottom = 0;
59     /**
60      * The z order of this RtfShapePosition.
61      */

62     private int zOrder = 0;
63     /**
64      * The horizontal relative position.
65      */

66     private int xRelativePos = POSITION_X_RELATIVE_PAGE;
67     /**
68      * The vertical relative position.
69      */

70     private int yRelativePos = POSITION_Y_RELATIVE_PAGE;
71     /**
72      * Whether to ignore the horizontal relative position.
73      */

74     private boolean ignoreXRelative = false;
75     /**
76      * Whether to ignore the vertical relative position.
77      */

78     private boolean ignoreYRelative = false;
79     /**
80      * Whether the shape is below the text.
81      */

82     private boolean shapeBelowText = false;
83
84     /**
85      * Constructs a new RtfShapePosition with the four bounding coordinates.
86      *
87      * @param top The top coordinate.
88      * @param left The left coordinate.
89      * @param right The right coordinate.
90      * @param bottom The bottom coordinate.
91      */

92     public RtfShapePosition(int top, int left, int right, int bottom) {
93         this.top = top;
94         this.left = left;
95         this.right = right;
96         this.bottom = bottom;
97     }
98     
99     /**
100      * Gets whether the shape is below the text.
101      *
102      * @return <code>True</code> if the shape is below, <code>false</code> if the text is below.
103      */

104     public boolean isShapeBelowText() {
105         return shapeBelowText;
106     }
107
108     /**
109      * Sets whether the shape is below the text.
110      *
111      * @param shapeBelowText <code>True</code> if the shape is below, <code>false</code> if the text is below.
112      */

113     public void setShapeBelowText(boolean shapeBelowText) {
114         this.shapeBelowText = shapeBelowText;
115     }
116
117     /**
118      * Sets the relative horizontal position. Use one of the constants
119      * provided in this class.
120      *
121      * @param relativePos The relative horizontal position to use.
122      */

123     public void setXRelativePos(int relativePos) {
124         xRelativePos = relativePos;
125     }
126
127     /**
128      * Sets the relative vertical position. Use one of the constants
129      * provides in this class.
130      *
131      * @param relativePos The relative vertical position to use.
132      */

133     public void setYRelativePos(int relativePos) {
134         yRelativePos = relativePos;
135     }
136
137     /**
138      * Sets the z order to use.
139      *
140      * @param order The z order to use.
141      */

142     public void setZOrder(int order) {
143         zOrder = order;
144     }
145
146     /**
147      * Set whether to ignore the horizontal relative position.
148      *
149      * @param ignoreXRelative <code>True</code> to ignore the horizontal relative position, <code>false</code> otherwise.
150      */

151     protected void setIgnoreXRelative(boolean ignoreXRelative) {
152         this.ignoreXRelative = ignoreXRelative;
153     }
154
155     /**
156      * Set whether to ignore the vertical relative position.
157      *
158      * @param ignoreYRelative <code>True</code> to ignore the vertical relative position, <code>false</code> otherwise.
159      */

160     protected void setIgnoreYRelative(boolean ignoreYRelative) {
161         this.ignoreYRelative = ignoreYRelative;
162     }
163
164     /**
165      * Write this RtfShapePosition.
166      * @deprecated replaced by {@link #writeContent(OutputStream)}
167      */

168     public byte[] write()
169     {
170         ByteArrayOutputStream JavaDoc result = new ByteArrayOutputStream JavaDoc();
171         try {
172             writeContent(result);
173         } catch(IOException JavaDoc ioe) {
174             ioe.printStackTrace();
175         }
176         return result.toByteArray();
177     }
178     /**
179      * Write this RtfShapePosition.
180      */

181     public void writeContent(final OutputStream JavaDoc result) throws IOException JavaDoc
182     {
183         result.write("\\shpleft".getBytes());
184         result.write(intToByteArray(this.left));
185         result.write("\\shptop".getBytes());
186         result.write(intToByteArray(this.top));
187         result.write("\\shpright".getBytes());
188         result.write(intToByteArray(this.right));
189         result.write("\\shpbottom".getBytes());
190         result.write(intToByteArray(this.bottom));
191         result.write("\\shpz".getBytes());
192         result.write(intToByteArray(this.zOrder));
193         switch(this.xRelativePos) {
194         case POSITION_X_RELATIVE_PAGE: result.write("\\shpbxpage".getBytes()); break;
195         case POSITION_X_RELATIVE_MARGIN: result.write("\\shpbxmargin".getBytes()); break;
196         case POSITION_X_RELATIVE_COLUMN: result.write("\\shpbxcolumn".getBytes()); break;
197         }
198         if(this.ignoreXRelative) {
199             result.write("\\shpbxignore".getBytes());
200         }
201         switch(this.yRelativePos) {
202         case POSITION_Y_RELATIVE_PAGE: result.write("\\shpbypage".getBytes()); break;
203         case POSITION_Y_RELATIVE_MARGIN: result.write("\\shpbymargin".getBytes()); break;
204         case POSITION_Y_RELATIVE_PARAGRAPH: result.write("\\shpbypara".getBytes()); break;
205         }
206         if(this.ignoreYRelative) {
207             result.write("\\shpbyignore".getBytes());
208         }
209         if(this.shapeBelowText) {
210             result.write("\\shpfblwtxt1".getBytes());
211         } else {
212             result.write("\\shpfblwtxt0".getBytes());
213         }
214     }
215
216 }
217
Popular Tags