KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > inline > UnresolvedPageNumber


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: UnresolvedPageNumber.java 453920 2006-10-07 14:29:54Z spepping $ */
19  
20 package org.apache.fop.area.inline;
21
22 import org.apache.fop.area.PageViewport;
23 import org.apache.fop.area.Resolvable;
24 import org.apache.fop.fonts.Font;
25
26 import java.util.List JavaDoc;
27
28 /**
29  * Unresolvable page number area.
30  * This is a word area that resolves itself to a page number
31  * from an id reference.
32  */

33 public class UnresolvedPageNumber extends TextArea implements Resolvable {
34
35     private boolean resolved = false;
36     private String JavaDoc pageIDRef;
37     private String JavaDoc text;
38     private boolean pageType;
39
40     /** Indicates that the reference refers to the first area generated by a formatting object. */
41     public static final boolean FIRST = true;
42     /** Indicates that the reference refers to the last area generated by a formatting object. */
43     public static final boolean LAST = false;
44     
45     //Transient fields
46
private transient Font font;
47     
48     /**
49      * Create a new unresolved page number.
50      *
51      * @param id the id reference for resolving this
52      * @param f the font for formatting the page number
53      */

54     public UnresolvedPageNumber(String JavaDoc id, Font f) {
55         this(id, f, FIRST);
56     }
57     
58     /**
59      * Create a new unresolved page number.
60      *
61      * @param id the id reference for resolving this
62      * @param f the font for formatting the page number
63      * @param type indicates whether the reference refers to the first or last area generated by
64      * a formatting object
65      */

66     public UnresolvedPageNumber(String JavaDoc id, Font f, boolean type) {
67         pageIDRef = id;
68         font = f;
69         text = "?";
70         pageType = type;
71     }
72
73     /**
74      * Get the id references for this area.
75      *
76      * @return the id reference for this unresolved page number
77      */

78     public String JavaDoc[] getIDRefs() {
79         return new String JavaDoc[] {pageIDRef};
80     }
81
82     /**
83      * Resolve the page number idref
84      * This resolves the idref for this object by getting the page number
85      * string from the first page in the list of pages that apply
86      * for this ID. The page number text is then set to the String value
87      * of the page number.
88      *
89      * @param id an id whose PageViewports have been determined
90      * @param pages the list of PageViewports associated with this ID
91      */

92     public void resolveIDRef(String JavaDoc id, List JavaDoc pages) {
93         if (!resolved && pageIDRef.equals(id) && pages != null) {
94             if (log.isDebugEnabled()) {
95                 log.debug("Resolving pageNumber: " + id);
96             }
97             resolved = true;
98             PageViewport page;
99             if (pageType == FIRST) {
100                 page = (PageViewport)pages.get(0);
101             } else {
102                 page = (PageViewport)pages.get(pages.size() - 1);
103             }
104             // replace the text
105
removeText();
106             text = page.getPageNumberString();
107             addWord(text, 0);
108             // update ipd
109
if (font != null) {
110                 handleIPDVariation(font.getWordWidth(text) - getIPD());
111                 // set the Font object to null, as we don't need it any more
112
font = null;
113             } else {
114                 log.warn("Cannot update the IPD of an unresolved page number."
115                         + " No font information available.");
116             }
117         }
118     }
119
120     /**
121      * Check if this is resolved.
122      *
123      * @return true when this has been resolved
124      */

125     public boolean isResolved() {
126        return resolved;
127     }
128
129     /**
130      * recursively apply the variation factor to all descendant areas
131      * @param variationFactor the variation factor that must be applied to adjustment ratios
132      * @param lineStretch the total stretch of the line
133      * @param lineShrink the total shrink of the line
134      * @return true if there is an UnresolvedArea descendant
135      */

136     public boolean applyVariationFactor(double variationFactor,
137                                         int lineStretch, int lineShrink) {
138         return true;
139     }
140 }
141
Popular Tags