KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > interactive > action > type > PDActionRemoteGoTo


1 /**
2  * Copyright (c) 2004, 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.action.type;
32
33 import java.io.IOException JavaDoc;
34
35 import org.pdfbox.cos.COSBase;
36 import org.pdfbox.cos.COSDictionary;
37
38 import org.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
39
40 /**
41  * This represents a remote go-to action that can be executed in a PDF document.
42  *
43  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
44  * @author Panagiotis Toumasis (ptoumasis@mail.gr)
45  * @version $Revision: 1.4 $
46  */

47 public class PDActionRemoteGoTo extends PDAction
48 {
49     /**
50      * This type of action this object represents.
51      */

52     public static final String JavaDoc SUB_TYPE = "GoToR";
53
54     /**
55      * Default constructor.
56      */

57     public PDActionRemoteGoTo()
58     {
59         action = new COSDictionary();
60         setSubType( SUB_TYPE );
61     }
62
63     /**
64      * Constructor.
65      *
66      * @param a The action dictionary.
67      */

68     public PDActionRemoteGoTo( COSDictionary a )
69     {
70         super( a );
71     }
72
73     /**
74      * Convert this standard java object to a COS object.
75      *
76      * @return The cos object that matches this Java object.
77      */

78     public COSBase getCOSObject()
79     {
80         return action;
81     }
82
83     /**
84      * Convert this standard java object to a COS object.
85      *
86      * @return The cos object that matches this Java object.
87      */

88     public COSDictionary getCOSDictionary()
89     {
90         return action;
91     }
92
93     /**
94      * This will get the type of action that the actions dictionary describes.
95      * It must be GoToR for a remote go-to action.
96      *
97      * @return The S entry of the specific remote go-to action dictionary.
98      */

99     public String JavaDoc getS()
100     {
101        return action.getNameAsString( "S" );
102     }
103
104     /**
105      * This will set the type of action that the actions dictionary describes.
106      * It must be GoToR for a remote go-to action.
107      *
108      * @param s The remote go-to action.
109      */

110     public void setS( String JavaDoc s )
111     {
112        action.setName( "S", s );
113     }
114
115     /**
116      * This will get the file in which the destination is located.
117      *
118      * @return The F entry of the specific remote go-to action dictionary.
119      *
120      * @throws IOException If there is an error creating the file spec.
121      */

122     public PDFileSpecification getFile() throws IOException JavaDoc
123     {
124         return PDFileSpecification.createFS( action.getDictionaryObject( "F" ) );
125     }
126
127     /**
128      * This will set the file in which the destination is located.
129      *
130      * @param fs The file specification.
131      */

132     public void setFile( PDFileSpecification fs )
133     {
134         action.setItem( "F", fs );
135     }
136
137     /**
138      * This will get the destination to jump to.
139      * If the value is an array defining an explicit destination,
140      * its first element must be a page number within the remote
141      * document rather than an indirect reference to a page object
142      * in the current document. The first page is numbered 0.
143      *
144      * @return The D entry of the specific remote go-to action dictionary.
145      */

146
147     // Array or String.
148
public COSBase getD()
149     {
150         return action.getDictionaryObject( "D" );
151     }
152
153     /**
154      * This will set the destination to jump to.
155      * If the value is an array defining an explicit destination,
156      * its first element must be a page number within the remote
157      * document rather than an indirect reference to a page object
158      * in the current document. The first page is numbered 0.
159      *
160      * @param d The destination.
161      */

162
163     // In case the value is an array.
164
public void setD( COSBase d )
165     {
166         action.setItem( "D", d );
167     }
168
169     /**
170      * This will specify whether to open the destination document in a new window.
171      * If this flag is false, the destination document will replace the current
172      * document in the same window. If this entry is absent, the viewer application
173      * should behave in accordance with the current user preference.
174      *
175      * @return A flag specifying whether to open the destination document in a new window.
176      */

177     public boolean shouldOpenInNewWindow()
178     {
179         return action.getBoolean( "NewWindow", true );
180     }
181
182     /**
183      * This will specify the destination document to open in a new window.
184      *
185      * @param value The flag value.
186      */

187     public void setOpenInNewWindow( boolean value )
188     {
189         action.setBoolean( "NewWindow", value );
190     }
191 }
Popular Tags