KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > interactive > documentnavigation > destination > PDPageDestination


1 /**
2  * Copyright (c) 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.documentnavigation.destination;
32
33 import org.pdfbox.cos.COSArray;
34 import org.pdfbox.cos.COSBase;
35 import org.pdfbox.cos.COSDictionary;
36 import org.pdfbox.cos.COSNumber;
37
38 import org.pdfbox.pdmodel.PDPage;
39
40 /**
41  * This represents a destination to a page, see subclasses for specific parameters.
42  *
43  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
44  * @version $Revision: 1.2 $
45  */

46 public abstract class PDPageDestination extends PDDestination
47 {
48     /**
49      * Storage for the page destination.
50      */

51     protected COSArray array;
52     
53     /**
54      * Constructor to create empty page destination.
55      *
56      */

57     protected PDPageDestination()
58     {
59         array = new COSArray();
60     }
61     
62     /**
63      * Constructor to create empty page destination.
64      *
65      * @param arr A page destination array.
66      */

67     protected PDPageDestination( COSArray arr )
68     {
69         array = arr;
70     }
71     
72     /**
73      * This will get the page for this destination. A page destination
74      * can either reference a page or a page number(when doing a remote destination to
75      * another PDF). If this object is referencing by page number then this method will
76      * return null and getPageNumber should be used.
77      *
78      * @return The page for this destination.
79      */

80     public PDPage getPage()
81     {
82         PDPage retval = null;
83         if( array.size() > 0 )
84         {
85             COSBase page = array.getObject( 0 );
86             if( page instanceof COSDictionary )
87             {
88                 retval = new PDPage( (COSDictionary)page );
89             }
90         }
91         return retval;
92     }
93     
94     /**
95      * Set the page for this destination.
96      *
97      * @param page The page for the destination.
98      */

99     public void setPage( PDPage page )
100     {
101         array.set( 0, page );
102     }
103     
104     /**
105      * This will get the page number for this destination. A page destination
106      * can either reference a page or a page number(when doing a remote destination to
107      * another PDF). If this object is referencing by page number then this method will
108      * return that number, otherwise -1 will be returned.
109      *
110      * @return The page number for this destination.
111      */

112     public int getPageNumber()
113     {
114         int retval = -1;
115         if( array.size() > 0 )
116         {
117             COSBase page = array.getObject( 0 );
118             if( page instanceof COSNumber )
119             {
120                 retval = ((COSNumber)page).intValue();
121             }
122         }
123         return retval;
124     }
125     
126     /**
127      * Set the page number for this destination.
128      *
129      * @param pageNumber The page for the destination.
130      */

131     public void setPageNumber( int pageNumber )
132     {
133         array.set( 0, pageNumber );
134     }
135     
136     /**
137      * Convert this standard java object to a COS object.
138      *
139      * @return The cos object that matches this Java object.
140      */

141     public COSBase getCOSObject()
142     {
143         return array;
144     }
145     
146     /**
147      * Convert this standard java object to a COS object.
148      *
149      * @return The cos object that matches this Java object.
150      */

151     public COSArray getCOSArray()
152     {
153         return array;
154     }
155 }
156
Popular Tags