KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > datatypes > IDNode


1 /*
2  * $Id: IDNode.java,v 1.4.2.5 2003/02/25 10:48:28 jeremias Exp $
3  * ============================================================================
4  * The Apache Software License, Version 1.1
5  * ============================================================================
6  *
7  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  * ============================================================================
45  *
46  * This software consists of voluntary contributions made by many individuals
47  * on behalf of the Apache Software Foundation and was originally created by
48  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
49  * Software Foundation, please see <http://www.apache.org/>.
50  */

51 package org.apache.fop.datatypes;
52
53 import org.apache.fop.pdf.PDFGoTo;
54
55
56 public class IDNode {
57     private String JavaDoc idValue, internalLinkGoToPageReference;
58
59     private PDFGoTo internalLinkGoTo;
60
61     private String JavaDoc pageNumber;
62     private int xPosition = 0; // x position on page
63
private int yPosition = 0; // y position on page
64

65
66     /**
67      * Constructor for IDNode
68      *
69      * @param idValue The value of the id for this node
70      */

71     protected IDNode(String JavaDoc idValue) {
72         this.idValue = idValue;
73     }
74
75
76     /**
77      * Sets the page number for this node
78      *
79      * @param number page number of node
80      */

81     protected void setPageNumber(String JavaDoc pageNumber) {
82         this.pageNumber = pageNumber;
83     }
84
85
86     /**
87      * Returns the page number of this node
88      *
89      * @return page number of this node
90      */

91     public String JavaDoc getPageNumber() {
92         return pageNumber;
93     }
94
95     /**
96      * Returns the page reference.
97      *
98      * @return page reference of this node.
99      */

100     public String JavaDoc getPageReference() {
101        if (null != internalLinkGoTo) {
102          return internalLinkGoTo.getPageReference();
103        } else {
104          return internalLinkGoToPageReference;
105        }
106     }
107
108     public int getXPosition() {
109        return xPosition;
110     }
111     
112     public int getYPosition() {
113        return yPosition;
114     }
115
116     /**
117      * creates a new GoTo object for an internal link
118      *
119      * @param objectNumber
120      * the number to be assigned to the new object
121      */

122     protected void createInternalLinkGoTo(int objectNumber) {
123         if (internalLinkGoToPageReference == null) {
124             internalLinkGoTo = new PDFGoTo(objectNumber, null);
125         } else {
126             internalLinkGoTo = new PDFGoTo(objectNumber,
127                                            internalLinkGoToPageReference);
128         }
129
130         if (xPosition
131                 != 0) // if the position is known (if x is known, then y is known)
132
{
133             internalLinkGoTo.setXPosition(xPosition);
134             internalLinkGoTo.setYPosition(yPosition);
135         }
136
137     }
138
139
140
141     /**
142      * sets the page reference for the internal link's GoTo. The GoTo will jump to this page reference.
143      *
144      * @param pageReference
145      * the page reference to which the internal link GoTo should jump
146      * ex. 23 0 R
147      */

148     protected void setInternalLinkGoToPageReference(String JavaDoc pageReference) {
149         if (internalLinkGoTo != null) {
150             internalLinkGoTo.setPageReference(pageReference);
151         } else {
152             internalLinkGoToPageReference = pageReference;
153         }
154
155     }
156
157
158
159     /**
160      * Returns the reference to the Internal Link's GoTo object
161      *
162      * @return GoTo object reference
163      */

164     protected String JavaDoc getInternalLinkGoToReference() {
165         return internalLinkGoTo.referencePDF();
166     }
167
168
169
170     /**
171      * Returns the id value of this node
172      *
173      * @return this node's id value
174      */

175     protected String JavaDoc getIDValue() {
176         return idValue;
177     }
178
179
180
181     /**
182      * Returns the PDFGoTo object associated with the internal link
183      *
184      * @return PDFGoTo object
185      */

186     protected PDFGoTo getInternalLinkGoTo() {
187         return internalLinkGoTo;
188     }
189
190
191     /**
192      * Determines whether there is an internal link GoTo for this node
193      *
194      * @return true if internal link GoTo for this node is set, false otherwise
195      */

196     protected boolean isThereInternalLinkGoTo() {
197         return internalLinkGoTo != null;
198     }
199
200
201     /**
202      * Sets the position of this node
203      *
204      * @param x the x position
205      * @param y the y position
206      */

207     protected void setPosition(int x, int y) {
208         if (internalLinkGoTo != null) {
209             internalLinkGoTo.setXPosition(x);
210             internalLinkGoTo.setYPosition(y);
211         } else {
212             xPosition = x;
213             yPosition = y;
214         }
215     }
216
217 }
218
Popular Tags