001: /**
002: * Copyright (c) 2005, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.interactive.annotation;
031:
032: import java.io.IOException;
033:
034: import org.pdfbox.cos.COSDictionary;
035: import org.pdfbox.cos.COSName;
036: import org.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
037:
038: /**
039: * This is the class that represents a file attachement.
040: *
041: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
042: * @version $Revision: 1.2 $
043: */
044: public class PDAnnotationFileAttachment extends PDAnnotation {
045: /**
046: * See get/setAttachmentName.
047: */
048: public static final String ATTACHMENT_NAME_PUSH_PIN = "PushPin";
049: /**
050: * See get/setAttachmentName.
051: */
052: public static final String ATTACHMENT_NAME_GRAPH = "Graph";
053: /**
054: * See get/setAttachmentName.
055: */
056: public static final String ATTACHMENT_NAME_PAPERCLIP = "Paperclip";
057: /**
058: * See get/setAttachmentName.
059: */
060: public static final String ATTACHMENT_NAME_TAG = "Tag";
061:
062: /**
063: * The type of annotation.
064: */
065: public static final String SUB_TYPE = "FileAttachment";
066:
067: /**
068: * Constructor.
069: */
070: public PDAnnotationFileAttachment() {
071: super ();
072: getDictionary().setItem(COSName.SUBTYPE,
073: COSName.getPDFName(SUB_TYPE));
074: }
075:
076: /**
077: * Creates a Link annotation from a COSDictionary, expected to be
078: * a correct object definition.
079: *
080: * @param field the PDF objet to represent as a field.
081: */
082: public PDAnnotationFileAttachment(COSDictionary field) {
083: super (field);
084: }
085:
086: /**
087: * Return the attached file.
088: *
089: * @return The attached file.
090: *
091: * @throws IOException If there is an error creating the file spec.
092: */
093: public PDFileSpecification getFile() throws IOException {
094: return PDFileSpecification.createFS(getDictionary()
095: .getDictionaryObject("FS"));
096: }
097:
098: /**
099: * Set the attached file.
100: *
101: * @param file The file that is attached.
102: */
103: public void setFile(PDFileSpecification file) {
104: getDictionary().setItem("FS", file);
105: }
106:
107: /**
108: * This is the name used to draw the type of attachment.
109: * See the ATTACHMENT_NAME_XXX constants.
110: *
111: * @return The name that describes the visual cue for the attachment.
112: */
113: public String getAttachmentName() {
114: return getDictionary().getNameAsString("Name",
115: ATTACHMENT_NAME_PUSH_PIN);
116: }
117:
118: /**
119: * Set the name used to draw the attachement icon.
120: * See the ATTACHMENT_NAME_XXX constants.
121: *
122: * @param name The name of the visual icon to draw.
123: */
124: public void setAttachementName(String name) {
125: getDictionary().setName("Name", name);
126: }
127: }
|