KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > layoutmgr > inline > PageNumberCitationLastLayoutManager


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$ */
19
20 package org.apache.fop.layoutmgr.inline;
21
22 import org.apache.fop.fo.flow.PageNumberCitationLast;
23 import org.apache.fop.area.PageViewport;
24 import org.apache.fop.area.Resolvable;
25 import org.apache.fop.area.inline.InlineArea;
26 import org.apache.fop.area.inline.UnresolvedPageNumber;
27 import org.apache.fop.area.inline.TextArea;
28 import org.apache.fop.layoutmgr.LayoutContext;
29 import org.apache.fop.layoutmgr.LayoutManager;
30
31 /**
32  * LayoutManager for the fo:page-number-citation-last formatting object
33  */

34 public class PageNumberCitationLastLayoutManager extends PageNumberCitationLayoutManager {
35
36     private PageNumberCitationLast fobj;
37     
38     /**
39      * Constructor
40      *
41      * @param node the formatting object that creates this area
42      * @todo better retrieval of font info
43      */

44     public PageNumberCitationLastLayoutManager(PageNumberCitationLast node) {
45         super(node);
46         fobj = node;
47     }
48     
49     /** @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#get(LayoutContext) */
50     public InlineArea get(LayoutContext context) {
51         curArea = getPageNumberCitationLastInlineArea(parentLM);
52         return curArea;
53     }
54     
55     /**
56      * if id can be resolved then simply return a word, otherwise
57      * return a resolvable area
58      */

59     private InlineArea getPageNumberCitationLastInlineArea(LayoutManager parentLM) {
60         TextArea text = null;
61         resolved = false;
62         if (!getPSLM().associateLayoutManagerID(fobj.getRefId())) {
63             text = new UnresolvedPageNumber(fobj.getRefId(), font, UnresolvedPageNumber.LAST);
64             getPSLM().addUnresolvedArea(fobj.getRefId(), (Resolvable)text);
65             String JavaDoc str = "MMM"; // reserve three spaces for page number
66
int width = getStringWidth(str);
67             text.setIPD(width);
68         } else {
69             PageViewport page = getPSLM().getLastPVWithID(fobj.getRefId());
70             String JavaDoc str = page.getPageNumberString();
71             // get page string from parent, build area
72
text = new TextArea();
73             int width = getStringWidth(str);
74             text.addWord(str, 0);
75             text.setIPD(width);
76             
77             resolved = true;
78         }
79         
80         updateTextAreaTraits(text);
81         
82         return text;
83     }
84 }
85
Popular Tags