KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright (c) 2003-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 org.pdfbox.cos.COSDictionary;
34
35 import org.pdfbox.pdmodel.common.PDTextStream;
36 import org.pdfbox.cos.COSBase;
37
38 import java.io.IOException JavaDoc;
39
40 import java.util.Calendar JavaDoc;
41
42 /**
43  * This class represents the additonal fields of a Markup type Annotation.
44  *
45  *
46  * @author Paul King
47  * @version $Revision: 1.1 $
48  */

49 public abstract class PDAnnotationMarkup extends PDAnnotation
50 {
51
52     /*
53      * The various values of the reply type as defined in the PDF 1.6 reference
54      * Table 8.17
55      */

56
57     /**
58      * Constant for an annotation reply type.
59      */

60     public static final String JavaDoc RT_REPLY = "R";
61
62     /**
63      * Constant for an annotation reply type.
64      */

65     public static final String JavaDoc RT_GROUP = "Group";
66
67     /**
68      * Constructor.
69      */

70     public PDAnnotationMarkup()
71     {
72         super();
73     }
74
75     /**
76      * Constructor.
77      *
78      * @param dict
79      * The annotations dictionary.
80      */

81     public PDAnnotationMarkup( COSDictionary dict )
82     {
83         super( dict );
84     }
85
86     /**
87      * Retrieve the string used as the title of the popup window shown when open
88      * and active (by convention this identifies who added the annotation).
89      *
90      * @return The title of the popup.
91      */

92     public String JavaDoc getTitlePopup()
93     {
94         return getDictionary().getString( "T" );
95     }
96
97     /**
98      * Set the string used as the title of the popup window shown when open and
99      * active (by convention this identifies who added the annotation).
100      *
101      * @param t
102      * The title of the popup.
103      */

104     public void setTitlePopup( String JavaDoc t )
105     {
106         getDictionary().setString( "T", t );
107     }
108
109     /**
110      * This will retrieve the popup annotation used for entering/editing the
111      * text for this annotation.
112      *
113      * @return the popup annotation.
114      */

115     public PDAnnotationPopup getPopup()
116     {
117         COSDictionary popup = (COSDictionary) getDictionary().getDictionaryObject( "Popup" );
118         if (popup != null)
119         {
120             return new PDAnnotationPopup( popup );
121         }
122         else
123         {
124             return null;
125         }
126     }
127
128     /**
129      * This will set the popup annotation used for entering/editing the text for
130      * this annotation.
131      *
132      * @param popup
133      * the popup annotation.
134      */

135     public void setPopup( PDAnnotationPopup popup )
136     {
137         getDictionary().setItem( "Popup", popup );
138     }
139
140     /**
141      * This will retrieve the constant opacity value used when rendering the
142      * annotation (excluing any popup).
143      *
144      * @return the constant opacity value.
145      */

146     public float getConstantOpacity()
147     {
148         return getDictionary().getFloat( "CA", 1 );
149     }
150
151     /**
152      * This will set the constant opacity value used when rendering the
153      * annotation (excluing any popup).
154      *
155      * @param ca
156      * the constant opacity value.
157      */

158     public void setConstantOpacity( float ca )
159     {
160         getDictionary().setFloat( "CA", ca );
161     }
162
163     /**
164      * This will retrieve the rich text stream which is displayed in the popup
165      * window.
166      *
167      * @return the rich text stream.
168      */

169     public PDTextStream getRichContents()
170     {
171         COSBase rc = getDictionary().getDictionaryObject( "RC" );
172         if (rc != null)
173         {
174             return PDTextStream.createTextStream( rc );
175         }
176         else
177         {
178             return null;
179         }
180     }
181
182     /**
183      * This will set the rich text stream which is displayed in the popup window.
184      *
185      * @param rc
186      * the rich text stream.
187      */

188     public void setRichContents( PDTextStream rc )
189     {
190         getDictionary().setItem( "RC", rc);
191     }
192
193     /**
194      * This will retrieve the date and time the annotation was created.
195      *
196      * @return the creation date/time.
197      * @throws IOException
198      * if there is a format problem when converting the date.
199      */

200     public Calendar JavaDoc getCreationDate() throws IOException JavaDoc
201     {
202         return getDictionary().getDate( "CreationDate" );
203     }
204
205     /**
206      * This will set the the date and time the annotation was created.
207      *
208      * @param creationDate
209      * the date and time the annotation was created.
210      */

211     public void setCreationDate( Calendar JavaDoc creationDate )
212     {
213         getDictionary().setDate( "CreationDate", creationDate );
214     }
215
216     /**
217      * This will retrieve the annotation to which this one is "In Reply To" the
218      * actual relationship is specified by the RT entry.
219      *
220      * @return the other annotation.
221      * @throws IOException
222      * if there is an error with the annotation.
223      */

224     public PDAnnotation getInReplyTo() throws IOException JavaDoc
225     {
226         COSBase irt = getDictionary().getDictionaryObject( "IRT" );
227         return PDAnnotation.createAnnotation( irt );
228     }
229
230     /**
231      * This will set the annotation to which this one is "In Reply To" the
232      * actual relationship is specified by the RT entry.
233      *
234      * @param irt
235      * the annotation this one is "In Reply To".
236      */

237     public void setInReplyTo( PDAnnotation irt )
238     {
239         getDictionary().setItem( "IRT", irt );
240     }
241
242     /**
243      * This will retrieve the short description of the subject of the annotation.
244      *
245      * @return the subject.
246      */

247     public String JavaDoc getSubject()
248     {
249         return getDictionary().getString( "Subj" );
250     }
251
252     /**
253      * This will set the short description of the subject of the annotation.
254      *
255      * @param subj
256      * short description of the subject.
257      */

258     public void setSubject( String JavaDoc subj )
259     {
260         getDictionary().setString( "Subj", subj );
261     }
262
263     /**
264      * This will retrieve the Reply Type (relationship) with the annotation in
265      * the IRT entry See the RT_* constants for the available values.
266      *
267      * @return the relationship.
268      */

269     public String JavaDoc getReplyType()
270     {
271         return getDictionary().getNameAsString( "RT", RT_REPLY );
272     }
273
274     /**
275      * This will set the Reply Type (relationship) with the annotation in the
276      * IRT entry See the RT_* constants for the available values.
277      *
278      * @param rt
279      * the reply type.
280      */

281     public void setReplyType( String JavaDoc rt )
282     {
283         getDictionary().setName( "RT", rt );
284     }
285
286     /**
287      * This will retrieve the intent of the annotation The values and meanings
288      * are specific to the actual annotation See the IT_* constants for the
289      * annotation classes.
290      *
291      * @return the intent
292      */

293     public String JavaDoc getIntent()
294     {
295         return getDictionary().getNameAsString( "IT" );
296     }
297
298     /**
299      * This will set the intent of the annotation The values and meanings are
300      * specific to the actual annotation See the IT_* constants for the
301      * annotation classes.
302      *
303      * @param it
304      * the intent
305      */

306     public void setIntent( String JavaDoc it )
307     {
308         getDictionary().setName( "IT", it );
309     }
310
311 }
Popular Tags