KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > interactive > annotation > PDAnnotationLine


1 /**
2  * Copyright (c) 2003, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.interactive.annotation;
32
33 import org.pdfbox.cos.COSArray;
34 import org.pdfbox.cos.COSDictionary;
35 import org.pdfbox.cos.COSName;
36 import org.pdfbox.pdmodel.graphics.color.PDGamma;
37
38 /**
39  * This is the class that represents a line annotation.
40  * Introduced in PDF 1.3 specification
41  *
42  * @author Paul King
43  * @version $Revision: 1.1 $
44  */

45 public class PDAnnotationLine extends PDAnnotationMarkup
46 {
47     
48
49     /*
50      * The various values for intent (get/setIT, see the PDF 1.6 reference Table
51      * 8.22
52      */

53
54     /**
55      * Constant for annotation intent of Arrow.
56      */

57     public static final String JavaDoc IT_LINE_ARROW = "LineArrow";
58
59     /**
60      * Constant for annotation intent of a dimension line.
61      */

62     public static final String JavaDoc IT_LINE_DIMENSION = "LineDimension";
63
64     /*
65      * The various values for line ending styles, see the PDF 1.6 reference
66      * Table 8.23
67      */

68
69     /**
70      * Constant for a square line ending.
71      */

72     public static final String JavaDoc LE_SQUARE = "Square";
73
74     /**
75      * Constant for a circle line ending.
76      */

77     public static final String JavaDoc LE_CIRCLE = "Circle";
78
79     /**
80      * Constant for a diamond line ending.
81      */

82     public static final String JavaDoc LE_DIAMOND = "Diamond";
83
84     /**
85      * Constant for a open arrow line ending.
86      */

87     public static final String JavaDoc LE_OPEN_ARROW = "OpenArrow";
88
89     /**
90      * Constant for a closed arrow line ending.
91      */

92     public static final String JavaDoc LE_CLOSED_ARROW = "ClosedArrow";
93
94     /**
95      * Constant for no line ending.
96      */

97     public static final String JavaDoc LE_NONE = "None";
98
99     /**
100      * Constant for a butt line ending.
101      */

102     public static final String JavaDoc LE_BUTT = "Butt";
103
104     /**
105      * Constant for a reversed open arrow line ending.
106      */

107     public static final String JavaDoc LE_R_OPEN_ARROW = "ROpenArrow";
108
109     /**
110      * Constant for a revered closed arrow line ending.
111      */

112     public static final String JavaDoc LE_R_CLOSED_ARROW = "RClosedArrow";
113
114     /**
115      * Constant for a slash line ending.
116      */

117     public static final String JavaDoc LE_SLASH = "Slash";
118
119     /**
120      * The type of annotation.
121      */

122     public static final String JavaDoc SUB_TYPE = "Line";
123
124     /**
125      * Constructor.
126      */

127     public PDAnnotationLine()
128     {
129         super();
130         getDictionary().setItem( COSName.SUBTYPE, COSName.getPDFName( SUB_TYPE ) );
131         // Dictionary value L is mandatory, fill in with arbitary value
132
setLine( new float[] { 0, 0, 0, 0 } );
133
134     }
135
136     /**
137      * Creates a Line annotation from a COSDictionary, expected to be a correct
138      * object definition.
139      *
140      * @param field
141      * the PDF objet to represent as a field.
142      */

143     public PDAnnotationLine( COSDictionary field )
144     {
145         super( field );
146     }
147
148     /**
149      * This will set start and end coordinates of the line (or leader line if LL
150      * entry is set).
151      *
152      * @param l
153      * array of 4 floats [x1, y1, x2, y2] line start and end points
154      * in default user space.
155      */

156     public void setLine( float[] l )
157     {
158         COSArray newL = new COSArray();
159         newL.setFloatArray( l );
160         getDictionary().setItem( "L", newL );
161     }
162
163     /**
164      * This will retrieve the start and end coordinates of the line (or leader
165      * line if LL entry is set).
166      *
167      * @return array of floats [x1, y1, x2, y2] line start and end points in
168      * default user space.
169      */

170     public float[] getLine()
171     {
172         COSArray l = (COSArray) getDictionary().getDictionaryObject( "L" );
173         return l.toFloatArray();
174     }
175     
176     /**
177      * This will set the line ending style for the start point,
178      * see the LE_ constants for the possible values.
179      *
180      * @param style The new style.
181      */

182     public void setStartPointEndingStyle( String JavaDoc style )
183     {
184         if( style == null )
185         {
186             style = LE_NONE;
187         }
188         COSArray array = (COSArray)getDictionary().getDictionaryObject( "LE" );
189         if( array == null )
190         {
191             array = new COSArray();
192             array.add( COSName.getPDFName( style ) );
193             array.add( COSName.getPDFName( LE_NONE ) );
194             getDictionary().setItem( "LE", array );
195         }
196         else
197         {
198             array.setName( 0, style );
199         }
200     }
201     
202     /**
203      * This will retrieve the line ending style for the start point,
204      * possible values shown in the LE_ constants section.
205      *
206      * @return The ending style for the start point.
207      */

208     public String JavaDoc getStartPointEndingStyle()
209     {
210         String JavaDoc retval = LE_NONE;
211         COSArray array = (COSArray)getDictionary().getDictionaryObject( "LE" );
212         if( array != null )
213         {
214             retval = array.getName( 0 );
215         }
216         
217         return retval;
218     }
219     
220     /**
221      * This will set the line ending style for the end point,
222      * see the LE_ constants for the possible values.
223      *
224      * @param style The new style.
225      */

226     public void setEndPointEndingStyle( String JavaDoc style )
227     {
228         if( style == null )
229         {
230             style = LE_NONE;
231         }
232         COSArray array = (COSArray)getDictionary().getDictionaryObject( "LE" );
233         if( array == null )
234         {
235             array = new COSArray();
236             array.add( COSName.getPDFName( LE_NONE ) );
237             array.add( COSName.getPDFName( style ) );
238             getDictionary().setItem( "LE", array );
239         }
240         else
241         {
242             array.setName( 1, style );
243         }
244     }
245     
246     /**
247      * This will retrieve the line ending style for the end point,
248      * possible values shown in the LE_ constants section.
249      *
250      * @return The ending style for the end point.
251      */

252     public String JavaDoc getEndPointEndingStyle()
253     {
254         String JavaDoc retval = LE_NONE;
255         COSArray array = (COSArray)getDictionary().getDictionaryObject( "LE" );
256         if( array != null )
257         {
258             retval = array.getName( 1 );
259         }
260         
261         return retval;
262     }
263
264     /**
265      * This will set interior colour of the line endings defined in the LE
266      * entry. Colour is in DeviceRGB colourspace.
267      *
268      * @param ic
269      * colour in the DeviceRGB colourspace.
270      *
271      */

272     public void setInteriorColour( PDGamma ic )
273     {
274         getDictionary().setItem( "IC", ic );
275     }
276
277     /**
278      * This will retrieve the interior colour of the line endings defined in the
279      * LE entry. Colour is in DeviceRGB colourspace.
280      *
281      *
282      * @return PDGamma object representing the colour.
283      *
284      */

285     public PDGamma getInteriorColour()
286     {
287
288         COSArray ic = (COSArray) getDictionary().getDictionaryObject( "IC" );
289         if (ic != null)
290         {
291             return new PDGamma( ic );
292         }
293         else
294         {
295             return null;
296         }
297     }
298
299     /**
300      * This will set if the contents are shown as a caption to the line.
301      *
302      * @param cap
303      * Boolean value.
304      */

305     public void setCaption( boolean cap )
306     {
307         getDictionary().setBoolean( "Cap", cap );
308     }
309
310     /**
311      * This will retrieve if the contents are shown as a caption or not.
312      *
313      * @return boolean if the content is shown as a caption.
314      */

315     public boolean getCaption()
316     {
317         return getDictionary().getBoolean( "Cap", false );
318     }
319
320 }
Popular Tags