KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

68     public PDActionLaunch( COSDictionary a )
69     {
70         super( a );
71     }
72
73     /**
74      * This will get the application to be launched or the document
75      * to be opened or printed. It is required if none of the entries
76      * Win, Mac or Unix is present. If this entry is absent and the
77      * viewer application does not understand any of the alternative
78      * entries it should do nothing.
79      *
80      * @return The F entry of the specific launch action dictionary.
81      *
82      * @throws IOException If there is an error creating the file spec.
83      */

84     public PDFileSpecification getFile() throws IOException JavaDoc
85     {
86         return PDFileSpecification.createFS( getCOSDictionary().getDictionaryObject( "F" ) );
87     }
88
89     /**
90      * This will set the application to be launched or the document
91      * to be opened or printed. It is required if none of the entries
92      * Win, Mac or Unix is present. If this entry is absent and the
93      * viewer application does not understand any of the alternative
94      * entries it should do nothing.
95      *
96      * @param fs The file specification.
97      */

98     public void setFile( PDFileSpecification fs )
99     {
100         getCOSDictionary().setItem( "F", fs );
101     }
102
103     /**
104      * This will get a dictionary containing Windows-specific launch parameters.
105      *
106      * @return The Win entry of of the specific launch action dictionary.
107      */

108     public PDWindowsLaunchParams getWinLaunchParams()
109     {
110         COSDictionary win = (COSDictionary)action.getDictionaryObject( "Win" );
111         PDWindowsLaunchParams retval = null;
112         if( win != null )
113         {
114             retval = new PDWindowsLaunchParams( win );
115         }
116         return retval;
117     }
118
119     /**
120      * This will set a dictionary containing Windows-specific launch parameters.
121      *
122      * @param win The action to be performed.
123      */

124     public void setWinLaunchParams( PDWindowsLaunchParams win )
125     {
126         action.setItem( "Win", win );
127     }
128
129     /**
130      * This will get the file name to be launched or the document to be opened
131      * or printed, in standard Windows pathname format. If the name string includes
132      * a backslash character (\), the backslash must itself be preceded by a backslash.
133      * This value must be a single string; it is not a file specification.
134      *
135      * @return The F entry of the specific Windows launch parameter dictionary.
136      */

137     public String JavaDoc getF()
138     {
139         return action.getString( "F" );
140     }
141
142     /**
143      * This will set the file name to be launched or the document to be opened
144      * or printed, in standard Windows pathname format. If the name string includes
145      * a backslash character (\), the backslash must itself be preceded by a backslash.
146      * This value must be a single string; it is not a file specification.
147      *
148      * @param f The file name to be launched.
149      */

150     public void setF( String JavaDoc f )
151     {
152         action.setString( "F", f );
153     }
154
155     /**
156      * This will get the string specifying the default directory in standard DOS syntax.
157      *
158      * @return The D entry of the specific Windows launch parameter dictionary.
159      */

160     public String JavaDoc getD()
161     {
162         return action.getString( "D" );
163     }
164
165     /**
166      * This will set the string specifying the default directory in standard DOS syntax.
167      *
168      * @param d The default directory.
169      */

170     public void setD( String JavaDoc d )
171     {
172         action.setString( "D", d );
173     }
174
175     /**
176      * This will get the string specifying the operation to perform:
177      * open to open a document
178      * print to print a document
179      * If the F entry designates an application instead of a document, this entry
180      * is ignored and the application is launched. Default value: open.
181      *
182      * @return The O entry of the specific Windows launch parameter dictionary.
183      */

184     public String JavaDoc getO()
185     {
186         return action.getString( "O" );
187     }
188
189     /**
190      * This will set the string specifying the operation to perform:
191      * open to open a document
192      * print to print a document
193      * If the F entry designates an application instead of a document, this entry
194      * is ignored and the application is launched. Default value: open.
195      *
196      * @param o The operation to perform.
197      */

198     public void setO( String JavaDoc o )
199     {
200         action.setString( "O", o );
201     }
202
203     /**
204      * This will get a parameter string to be passed to the application designated by the F entry.
205      * This entry should be omitted if F designates a document.
206      *
207      * @return The P entry of the specific Windows launch parameter dictionary.
208      */

209     public String JavaDoc getP()
210     {
211         return action.getString( "P" );
212     }
213
214     /**
215      * This will set a parameter string to be passed to the application designated by the F entry.
216      * This entry should be omitted if F designates a document.
217      *
218      * @param p The parameter string.
219      */

220     public void setP( String JavaDoc p )
221     {
222         action.setString( "P", p );
223     }
224
225     /**
226      * This will specify whether to open the destination document in a new window.
227      * If this flag is false, the destination document will replace the current
228      * document in the same window. If this entry is absent, the viewer application
229      * should behave in accordance with the current user preference. This entry is
230      * ignored if the file designated by the F entry is not a PDF document.
231      *
232      * @return A flag specifying whether to open the destination document in a new window.
233      */

234     public boolean shouldOpenInNewWindow()
235     {
236         return action.getBoolean( "NewWindow", true );
237     }
238
239     /**
240      * This will specify the destination document to open in a new window.
241      *
242      * @param value The flag value.
243      */

244     public void setOpenInNewWindow( boolean value )
245     {
246         action.setBoolean( "NewWindow", value );
247     }
248 }
Popular Tags