001: /**
002: * Copyright (c) 2004, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.interactive.action.type;
031:
032: import java.io.IOException;
033:
034: import org.pdfbox.cos.COSBase;
035: import org.pdfbox.cos.COSDictionary;
036:
037: import org.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
038:
039: /**
040: * This represents a remote go-to action that can be executed in a PDF document.
041: *
042: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
043: * @author Panagiotis Toumasis (ptoumasis@mail.gr)
044: * @version $Revision: 1.4 $
045: */
046: public class PDActionRemoteGoTo extends PDAction {
047: /**
048: * This type of action this object represents.
049: */
050: public static final String SUB_TYPE = "GoToR";
051:
052: /**
053: * Default constructor.
054: */
055: public PDActionRemoteGoTo() {
056: action = new COSDictionary();
057: setSubType(SUB_TYPE);
058: }
059:
060: /**
061: * Constructor.
062: *
063: * @param a The action dictionary.
064: */
065: public PDActionRemoteGoTo(COSDictionary a) {
066: super (a);
067: }
068:
069: /**
070: * Convert this standard java object to a COS object.
071: *
072: * @return The cos object that matches this Java object.
073: */
074: public COSBase getCOSObject() {
075: return action;
076: }
077:
078: /**
079: * Convert this standard java object to a COS object.
080: *
081: * @return The cos object that matches this Java object.
082: */
083: public COSDictionary getCOSDictionary() {
084: return action;
085: }
086:
087: /**
088: * This will get the type of action that the actions dictionary describes.
089: * It must be GoToR for a remote go-to action.
090: *
091: * @return The S entry of the specific remote go-to action dictionary.
092: */
093: public String getS() {
094: return action.getNameAsString("S");
095: }
096:
097: /**
098: * This will set the type of action that the actions dictionary describes.
099: * It must be GoToR for a remote go-to action.
100: *
101: * @param s The remote go-to action.
102: */
103: public void setS(String s) {
104: action.setName("S", s);
105: }
106:
107: /**
108: * This will get the file in which the destination is located.
109: *
110: * @return The F entry of the specific remote go-to action dictionary.
111: *
112: * @throws IOException If there is an error creating the file spec.
113: */
114: public PDFileSpecification getFile() throws IOException {
115: return PDFileSpecification.createFS(action
116: .getDictionaryObject("F"));
117: }
118:
119: /**
120: * This will set the file in which the destination is located.
121: *
122: * @param fs The file specification.
123: */
124: public void setFile(PDFileSpecification fs) {
125: action.setItem("F", fs);
126: }
127:
128: /**
129: * This will get the destination to jump to.
130: * If the value is an array defining an explicit destination,
131: * its first element must be a page number within the remote
132: * document rather than an indirect reference to a page object
133: * in the current document. The first page is numbered 0.
134: *
135: * @return The D entry of the specific remote go-to action dictionary.
136: */
137:
138: // Array or String.
139: public COSBase getD() {
140: return action.getDictionaryObject("D");
141: }
142:
143: /**
144: * This will set the destination to jump to.
145: * If the value is an array defining an explicit destination,
146: * its first element must be a page number within the remote
147: * document rather than an indirect reference to a page object
148: * in the current document. The first page is numbered 0.
149: *
150: * @param d The destination.
151: */
152:
153: // In case the value is an array.
154: public void setD(COSBase d) {
155: action.setItem("D", d);
156: }
157:
158: /**
159: * This will specify whether to open the destination document in a new window.
160: * If this flag is false, the destination document will replace the current
161: * document in the same window. If this entry is absent, the viewer application
162: * should behave in accordance with the current user preference.
163: *
164: * @return A flag specifying whether to open the destination document in a new window.
165: */
166: public boolean shouldOpenInNewWindow() {
167: return action.getBoolean("NewWindow", true);
168: }
169:
170: /**
171: * This will specify the destination document to open in a new window.
172: *
173: * @param value The flag value.
174: */
175: public void setOpenInNewWindow(boolean value) {
176: action.setBoolean("NewWindow", value);
177: }
178: }
|