KickJava   Java API By Example, From Geeks To Geeks.

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


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.COSDictionary;
36 import org.pdfbox.cos.COSName;
37 import org.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
38
39 /**
40  * This is the class that represents a file attachement.
41  *
42  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
43  * @version $Revision: 1.2 $
44  */

45 public class PDAnnotationFileAttachment extends PDAnnotation
46 {
47     /**
48      * See get/setAttachmentName.
49      */

50     public static final String JavaDoc ATTACHMENT_NAME_PUSH_PIN = "PushPin";
51     /**
52      * See get/setAttachmentName.
53      */

54     public static final String JavaDoc ATTACHMENT_NAME_GRAPH = "Graph";
55     /**
56      * See get/setAttachmentName.
57      */

58     public static final String JavaDoc ATTACHMENT_NAME_PAPERCLIP = "Paperclip";
59     /**
60      * See get/setAttachmentName.
61      */

62     public static final String JavaDoc ATTACHMENT_NAME_TAG = "Tag";
63     
64     /**
65      * The type of annotation.
66      */

67     public static final String JavaDoc SUB_TYPE = "FileAttachment";
68     
69     /**
70      * Constructor.
71      */

72     public PDAnnotationFileAttachment()
73     {
74         super();
75         getDictionary().setItem( COSName.SUBTYPE, COSName.getPDFName( SUB_TYPE ) );
76     }
77
78     /**
79      * Creates a Link annotation from a COSDictionary, expected to be
80      * a correct object definition.
81      *
82      * @param field the PDF objet to represent as a field.
83      */

84     public PDAnnotationFileAttachment(COSDictionary field)
85     {
86         super( field );
87     }
88
89     /**
90      * Return the attached file.
91      *
92      * @return The attached file.
93      *
94      * @throws IOException If there is an error creating the file spec.
95      */

96     public PDFileSpecification getFile() throws IOException JavaDoc
97     {
98         return PDFileSpecification.createFS( getDictionary().getDictionaryObject( "FS" ) );
99     }
100     
101     /**
102      * Set the attached file.
103      *
104      * @param file The file that is attached.
105      */

106     public void setFile( PDFileSpecification file )
107     {
108         getDictionary().setItem( "FS", file );
109     }
110     
111     /**
112      * This is the name used to draw the type of attachment.
113      * See the ATTACHMENT_NAME_XXX constants.
114      *
115      * @return The name that describes the visual cue for the attachment.
116      */

117     public String JavaDoc getAttachmentName()
118     {
119         return getDictionary().getNameAsString( "Name", ATTACHMENT_NAME_PUSH_PIN );
120     }
121     
122     /**
123      * Set the name used to draw the attachement icon.
124      * See the ATTACHMENT_NAME_XXX constants.
125      *
126      * @param name The name of the visual icon to draw.
127      */

128     public void setAttachementName( String JavaDoc name )
129     {
130         getDictionary().setName( "Name", name );
131     }
132 }
Popular Tags