KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright (c) 2003-2006, 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
38 /**
39  * This is the class that represents a popup annotation.
40  * Introduced in PDF 1.3 specification
41  *
42  * @author Paul King
43  * @version $Revision: 1.2 $
44  */

45 public class PDAnnotationPopup extends PDAnnotation
46 {
47
48     /**
49      * The type of annotation.
50      */

51     public static final String JavaDoc SUB_TYPE = "Popup";
52
53     /**
54      * Constructor.
55      */

56     public PDAnnotationPopup()
57     {
58         super();
59         getDictionary()
60                 .setItem( COSName.SUBTYPE, COSName.getPDFName( SUB_TYPE ) );
61     }
62
63     /**
64      * Creates a popup annotation from a COSDictionary, expected to be a correct
65      * object definition.
66      *
67      * @param field
68      * the PDF objet to represent as a field.
69      */

70     public PDAnnotationPopup( COSDictionary field )
71     {
72         super( field );
73     }
74
75     /**
76      * This will set inital state of the annotation, open or closed.
77      *
78      * @param open
79      * Boolean value, true = open false = closed.
80      */

81     public void setOpen( boolean open )
82     {
83         getDictionary().setBoolean( "Open" , open );
84     }
85
86     /**
87      * This will retrieve the initial state of the annotation, open Or closed
88      * (default closed).
89      *
90      * @return The initial state, true = open false = closed.
91      */

92     public boolean getOpen()
93     {
94         return getDictionary().getBoolean( "Open" , false );
95     }
96
97     /**
98      * This will set the markup annotation which this popup relates to.
99      *
100      * @param annot
101      * the markup annotation.
102      */

103     public void setParent( PDAnnotationMarkup annot )
104     {
105         getDictionary().setItem( COSName.PARENT, annot.getDictionary() );
106     }
107
108     /**
109      * This will retrieve the markup annotation which this popup relates to.
110      *
111      * @return The parent markup annotation.
112      */

113     public PDAnnotationMarkup getParent()
114     {
115         PDAnnotationMarkup am = null;
116         try
117         {
118             am = (PDAnnotationMarkup)
119                 PDAnnotation.createAnnotation( getDictionary().getDictionaryObject( "Parent", "P" ) );
120         }
121         catch (IOException JavaDoc ioe)
122         {
123             // Couldn't construct the annotation, so return null i.e. do nothing
124
}
125         return am;
126     }
127
128 }
Popular Tags