001: /**
002: * Copyright (c) 2003-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 org.pdfbox.cos.COSDictionary;
033:
034: import org.pdfbox.pdmodel.common.PDTextStream;
035: import org.pdfbox.cos.COSBase;
036:
037: import java.io.IOException;
038:
039: import java.util.Calendar;
040:
041: /**
042: * This class represents the additonal fields of a Markup type Annotation.
043: *
044: *
045: * @author Paul King
046: * @version $Revision: 1.1 $
047: */
048: public abstract class PDAnnotationMarkup extends PDAnnotation {
049:
050: /*
051: * The various values of the reply type as defined in the PDF 1.6 reference
052: * Table 8.17
053: */
054:
055: /**
056: * Constant for an annotation reply type.
057: */
058: public static final String RT_REPLY = "R";
059:
060: /**
061: * Constant for an annotation reply type.
062: */
063: public static final String RT_GROUP = "Group";
064:
065: /**
066: * Constructor.
067: */
068: public PDAnnotationMarkup() {
069: super ();
070: }
071:
072: /**
073: * Constructor.
074: *
075: * @param dict
076: * The annotations dictionary.
077: */
078: public PDAnnotationMarkup(COSDictionary dict) {
079: super (dict);
080: }
081:
082: /**
083: * Retrieve the string used as the title of the popup window shown when open
084: * and active (by convention this identifies who added the annotation).
085: *
086: * @return The title of the popup.
087: */
088: public String getTitlePopup() {
089: return getDictionary().getString("T");
090: }
091:
092: /**
093: * Set the string used as the title of the popup window shown when open and
094: * active (by convention this identifies who added the annotation).
095: *
096: * @param t
097: * The title of the popup.
098: */
099: public void setTitlePopup(String t) {
100: getDictionary().setString("T", t);
101: }
102:
103: /**
104: * This will retrieve the popup annotation used for entering/editing the
105: * text for this annotation.
106: *
107: * @return the popup annotation.
108: */
109: public PDAnnotationPopup getPopup() {
110: COSDictionary popup = (COSDictionary) getDictionary()
111: .getDictionaryObject("Popup");
112: if (popup != null) {
113: return new PDAnnotationPopup(popup);
114: } else {
115: return null;
116: }
117: }
118:
119: /**
120: * This will set the popup annotation used for entering/editing the text for
121: * this annotation.
122: *
123: * @param popup
124: * the popup annotation.
125: */
126: public void setPopup(PDAnnotationPopup popup) {
127: getDictionary().setItem("Popup", popup);
128: }
129:
130: /**
131: * This will retrieve the constant opacity value used when rendering the
132: * annotation (excluing any popup).
133: *
134: * @return the constant opacity value.
135: */
136: public float getConstantOpacity() {
137: return getDictionary().getFloat("CA", 1);
138: }
139:
140: /**
141: * This will set the constant opacity value used when rendering the
142: * annotation (excluing any popup).
143: *
144: * @param ca
145: * the constant opacity value.
146: */
147: public void setConstantOpacity(float ca) {
148: getDictionary().setFloat("CA", ca);
149: }
150:
151: /**
152: * This will retrieve the rich text stream which is displayed in the popup
153: * window.
154: *
155: * @return the rich text stream.
156: */
157: public PDTextStream getRichContents() {
158: COSBase rc = getDictionary().getDictionaryObject("RC");
159: if (rc != null) {
160: return PDTextStream.createTextStream(rc);
161: } else {
162: return null;
163: }
164: }
165:
166: /**
167: * This will set the rich text stream which is displayed in the popup window.
168: *
169: * @param rc
170: * the rich text stream.
171: */
172: public void setRichContents(PDTextStream rc) {
173: getDictionary().setItem("RC", rc);
174: }
175:
176: /**
177: * This will retrieve the date and time the annotation was created.
178: *
179: * @return the creation date/time.
180: * @throws IOException
181: * if there is a format problem when converting the date.
182: */
183: public Calendar getCreationDate() throws IOException {
184: return getDictionary().getDate("CreationDate");
185: }
186:
187: /**
188: * This will set the the date and time the annotation was created.
189: *
190: * @param creationDate
191: * the date and time the annotation was created.
192: */
193: public void setCreationDate(Calendar creationDate) {
194: getDictionary().setDate("CreationDate", creationDate);
195: }
196:
197: /**
198: * This will retrieve the annotation to which this one is "In Reply To" the
199: * actual relationship is specified by the RT entry.
200: *
201: * @return the other annotation.
202: * @throws IOException
203: * if there is an error with the annotation.
204: */
205: public PDAnnotation getInReplyTo() throws IOException {
206: COSBase irt = getDictionary().getDictionaryObject("IRT");
207: return PDAnnotation.createAnnotation(irt);
208: }
209:
210: /**
211: * This will set the annotation to which this one is "In Reply To" the
212: * actual relationship is specified by the RT entry.
213: *
214: * @param irt
215: * the annotation this one is "In Reply To".
216: */
217: public void setInReplyTo(PDAnnotation irt) {
218: getDictionary().setItem("IRT", irt);
219: }
220:
221: /**
222: * This will retrieve the short description of the subject of the annotation.
223: *
224: * @return the subject.
225: */
226: public String getSubject() {
227: return getDictionary().getString("Subj");
228: }
229:
230: /**
231: * This will set the short description of the subject of the annotation.
232: *
233: * @param subj
234: * short description of the subject.
235: */
236: public void setSubject(String subj) {
237: getDictionary().setString("Subj", subj);
238: }
239:
240: /**
241: * This will retrieve the Reply Type (relationship) with the annotation in
242: * the IRT entry See the RT_* constants for the available values.
243: *
244: * @return the relationship.
245: */
246: public String getReplyType() {
247: return getDictionary().getNameAsString("RT", RT_REPLY);
248: }
249:
250: /**
251: * This will set the Reply Type (relationship) with the annotation in the
252: * IRT entry See the RT_* constants for the available values.
253: *
254: * @param rt
255: * the reply type.
256: */
257: public void setReplyType(String rt) {
258: getDictionary().setName("RT", rt);
259: }
260:
261: /**
262: * This will retrieve the intent of the annotation The values and meanings
263: * are specific to the actual annotation See the IT_* constants for the
264: * annotation classes.
265: *
266: * @return the intent
267: */
268: public String getIntent() {
269: return getDictionary().getNameAsString("IT");
270: }
271:
272: /**
273: * This will set the intent of the annotation The values and meanings are
274: * specific to the actual annotation See the IT_* constants for the
275: * annotation classes.
276: *
277: * @param it
278: * the intent
279: */
280: public void setIntent(String it) {
281: getDictionary().setName("IT", it);
282: }
283:
284: }
|