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.COSArray;
035: import org.pdfbox.cos.COSBase;
036: import org.pdfbox.cos.COSDictionary;
037: import org.pdfbox.cos.COSName;
038: import org.pdfbox.pdmodel.interactive.action.type.PDActionURI;
039: import org.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
040:
041: /**
042: * This is the class that represents a link annotation.
043: *
044: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
045: * @author Paul King
046: * @version $Revision: 1.3 $
047: */
048: public class PDAnnotationLink extends PDAnnotation {
049:
050: /**
051: * Constant values of the Text as defined in the PDF 1.6 reference Table 8.19.
052: */
053: public static final String HIGHLIGHT_MODE_NONE = "N";
054: /**
055: * Constant values of the Text as defined in the PDF 1.6 reference Table 8.19.
056: */
057: public static final String HIGHLIGHT_MODE_INVERT = "I";
058: /**
059: * Constant values of the Text as defined in the PDF 1.6 reference Table 8.19.
060: */
061: public static final String HIGHLIGHT_MODE_OUTLINE = "O";
062: /**
063: * Constant values of the Text as defined in the PDF 1.6 reference Table 8.19.
064: */
065: public static final String HIGHLIGHT_MODE_PUSH = "P";
066:
067: /**
068: * The type of annotation.
069: */
070: public static final String SUB_TYPE = "Link";
071:
072: /**
073: * Constructor.
074: */
075: public PDAnnotationLink() {
076: super ();
077: getDictionary().setItem(COSName.SUBTYPE,
078: COSName.getPDFName(SUB_TYPE));
079: }
080:
081: /**
082: * Creates a Link annotation from a COSDictionary, expected to be
083: * a correct object definition.
084: *
085: * @param field the PDF objet to represent as a field.
086: */
087: public PDAnnotationLink(COSDictionary field) {
088: super (field);
089: }
090:
091: /**
092: * Get the destination to be displayed when the annotation is activated. Either
093: * this or the A should be set but not both.
094: *
095: * @return The destination for this annotation.
096: *
097: * @throws IOException If there is an error creating the destination.
098: */
099: public PDDestination getDestination() throws IOException {
100: COSBase base = getDictionary()
101: .getDictionaryObject(COSName.DEST);
102: PDDestination retval = PDDestination.create(base);
103:
104: return retval;
105: }
106:
107: /**
108: * The new destination value.
109: *
110: * @param dest The updated destination.
111: */
112: public void setDestination(PDDestination dest) {
113: getDictionary().setItem(COSName.DEST, dest);
114: }
115:
116: /**
117: * Set the highlight mode for when the mouse is depressed.
118: * See the HIGHLIGHT_MODE_XXX constants.
119: *
120: * @return The string representation of the highlight mode.
121: */
122: public String getHighlightMode() {
123: return getDictionary().getNameAsString(COSName.H,
124: HIGHLIGHT_MODE_INVERT);
125: }
126:
127: /**
128: * Set the highlight mode. See the HIGHLIGHT_MODE_XXX constants.
129: *
130: * @param mode The new highlight mode.
131: */
132: public void setHighlightMode(String mode) {
133: getDictionary().setName(COSName.H, mode);
134: }
135:
136: /**
137: * This will set the previous URI action, in case it
138: * needs to be retrieved at later date.
139: *
140: * @param pa The previous URI.
141: */
142: public void setPreviousURI(PDActionURI pa) {
143: getDictionary().setItem("PA", pa);
144: }
145:
146: /**
147: * This will set the previous URI action, in case it's
148: * needed.
149: *
150: * @return The previous URI.
151: */
152: public PDActionURI getPreviousURI() {
153: COSDictionary pa = (COSDictionary) getDictionary()
154: .getDictionaryObject("PA");
155: if (pa != null) {
156: return new PDActionURI(pa);
157: } else {
158: return null;
159: }
160: }
161:
162: /**
163: * This will set the set of quadpoints which encompass the areas of this
164: * annotation which will activate.
165: *
166: * @param quadPoints
167: * an array representing the set of area covered.
168: */
169: public void setQuadPoints(float[] quadPoints) {
170: COSArray newQuadPoints = new COSArray();
171: newQuadPoints.setFloatArray(quadPoints);
172: getDictionary().setItem("QuadPoints", newQuadPoints);
173: }
174:
175: /**
176: * This will retrieve the set of quadpoints which encompass the areas of
177: * this annotation which will activate.
178: *
179: * @return An array of floats representing the quad points.
180: */
181: public float[] getQuadPoints() {
182: COSArray quadPoints = (COSArray) getDictionary()
183: .getDictionaryObject("QuadPoints");
184: if (quadPoints != null) {
185: return quadPoints.toFloatArray();
186: } else {
187: return null; // Should never happen as this is a required item
188: }
189: }
190: }
|