KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright (c) 2005, 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 java.io.IOException JavaDoc;
34
35 import org.pdfbox.cos.COSArray;
36 import org.pdfbox.cos.COSBase;
37 import org.pdfbox.cos.COSDictionary;
38 import org.pdfbox.cos.COSName;
39 import org.pdfbox.pdmodel.interactive.action.type.PDActionURI;
40 import org.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
41
42 /**
43  * This is the class that represents a link annotation.
44  *
45  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
46  * @author Paul King
47  * @version $Revision: 1.3 $
48  */

49 public class PDAnnotationLink extends PDAnnotation
50 {
51
52     
53     /**
54      * Constant values of the Text as defined in the PDF 1.6 reference Table 8.19.
55      */

56     public static final String JavaDoc HIGHLIGHT_MODE_NONE = "N";
57     /**
58      * Constant values of the Text as defined in the PDF 1.6 reference Table 8.19.
59      */

60     public static final String JavaDoc HIGHLIGHT_MODE_INVERT = "I";
61     /**
62      * Constant values of the Text as defined in the PDF 1.6 reference Table 8.19.
63      */

64     public static final String JavaDoc HIGHLIGHT_MODE_OUTLINE = "O";
65     /**
66      * Constant values of the Text as defined in the PDF 1.6 reference Table 8.19.
67      */

68     public static final String JavaDoc HIGHLIGHT_MODE_PUSH = "P";
69     
70     
71     /**
72      * The type of annotation.
73      */

74     public static final String JavaDoc SUB_TYPE = "Link";
75     
76     /**
77      * Constructor.
78      */

79     public PDAnnotationLink()
80     {
81         super();
82         getDictionary().setItem( COSName.SUBTYPE, COSName.getPDFName( SUB_TYPE ) );
83     }
84
85     /**
86      * Creates a Link annotation from a COSDictionary, expected to be
87      * a correct object definition.
88      *
89      * @param field the PDF objet to represent as a field.
90      */

91     public PDAnnotationLink(COSDictionary field)
92     {
93         super( field );
94     }
95
96     /**
97      * Get the destination to be displayed when the annotation is activated. Either
98      * this or the A should be set but not both.
99      *
100      * @return The destination for this annotation.
101      *
102      * @throws IOException If there is an error creating the destination.
103      */

104     public PDDestination getDestination() throws IOException JavaDoc
105     {
106         COSBase base = getDictionary().getDictionaryObject( COSName.DEST );
107         PDDestination retval = PDDestination.create( base );
108             
109         return retval;
110     }
111     
112     /**
113      * The new destination value.
114      *
115      * @param dest The updated destination.
116      */

117     public void setDestination( PDDestination dest )
118     {
119         getDictionary().setItem( COSName.DEST, dest );
120     }
121     
122     /**
123      * Set the highlight mode for when the mouse is depressed.
124      * See the HIGHLIGHT_MODE_XXX constants.
125      *
126      * @return The string representation of the highlight mode.
127      */

128     public String JavaDoc getHighlightMode()
129     {
130         return getDictionary().getNameAsString( COSName.H, HIGHLIGHT_MODE_INVERT );
131     }
132     
133     /**
134      * Set the highlight mode. See the HIGHLIGHT_MODE_XXX constants.
135      *
136      * @param mode The new highlight mode.
137      */

138     public void setHighlightMode( String JavaDoc mode )
139     {
140         getDictionary().setName( COSName.H, mode );
141     }
142     
143     /**
144      * This will set the previous URI action, in case it
145      * needs to be retrieved at later date.
146      *
147      * @param pa The previous URI.
148      */

149     public void setPreviousURI( PDActionURI pa )
150     {
151         getDictionary().setItem( "PA", pa );
152     }
153
154     /**
155      * This will set the previous URI action, in case it's
156      * needed.
157      *
158      * @return The previous URI.
159      */

160     public PDActionURI getPreviousURI()
161     {
162         COSDictionary pa = (COSDictionary) getDictionary().getDictionaryObject("PA");
163         if ( pa != null )
164         {
165             return new PDActionURI( pa );
166         }
167         else
168         {
169             return null;
170         }
171     }
172     
173     /**
174      * This will set the set of quadpoints which encompass the areas of this
175      * annotation which will activate.
176      *
177      * @param quadPoints
178      * an array representing the set of area covered.
179      */

180     public void setQuadPoints( float[] quadPoints )
181     {
182         COSArray newQuadPoints = new COSArray();
183         newQuadPoints.setFloatArray( quadPoints );
184         getDictionary().setItem( "QuadPoints", newQuadPoints );
185     }
186
187     /**
188      * This will retrieve the set of quadpoints which encompass the areas of
189      * this annotation which will activate.
190      *
191      * @return An array of floats representing the quad points.
192      */

193     public float[] getQuadPoints()
194     {
195         COSArray quadPoints = (COSArray) getDictionary().getDictionaryObject( "QuadPoints" );
196         if (quadPoints != null)
197         {
198             return quadPoints.toFloatArray();
199         }
200         else
201         {
202             return null; // Should never happen as this is a required item
203
}
204     }
205 }
Popular Tags